public AnnotationsLoader(SimpleExtensionManager extensionManager) { this.extensionManager = extensionManager; var location = FileSystemPath.CreateByCanonicalPath(Assembly.GetExecutingAssembly().Location) .Directory.Combine("ExternalAnnotations"); myAnnotations = new OneToSetMap <string, FileSystemPath>(StringComparer.OrdinalIgnoreCase); // Cache the annotation filenames to save scanning the directory multiple times. // Safe to cache as the user shouldn't be changing files in the install dir. If // they want to add extra annotations, use an extension. // The rules are simple: either the file is named after the assembly, or the folder // is (or both, but that doesn't matter) foreach (var file in location.GetChildFiles("*.xml")) { myAnnotations.Add(file.NameWithoutExtension, file); } foreach (var directory in location.GetChildDirectories()) { foreach (var file in directory.GetChildFiles("*.xml", PathSearchFlags.RecurseIntoSubdirectories)) { myAnnotations.Add(file.NameWithoutExtension, file); myAnnotations.Add(file.Directory.Name, file); } } }
public TypeResolver() { myFullNames.Add("string", typeof(string).FullName); myFullNames.Add("int", typeof(int).FullName); myFullNames.Add("void", typeof(void).FullName); myFullNames.Add("bool", typeof(bool).FullName); myFullNames.Add("object", typeof(object).FullName); myFullNames.Add("float", typeof(float).FullName); myFullNames.Add("double", typeof(double).FullName); myFullNames.Add("IEnumerator", typeof(IEnumerator).FullName); }
private static void FillTargetAndMethod(IBuffer buffer, OneToSetMap <string, FileID> eventHandlerToScriptTarget) { var lexer = new YamlLexer(buffer, false, false); lexer.Start(); TokenNodeType currentToken; FileID currentTarget = null; string currentMethod = null; while ((currentToken = lexer.TokenType) != null) { if (currentToken == YamlTokenType.NS_PLAIN_ONE_LINE_IN) { var text = buffer.GetText(new TextRange(lexer.TokenStart, lexer.TokenEnd)); lexer.Advance(); SkipWhitespace(lexer); currentToken = lexer.TokenType; if (currentToken == YamlTokenType.COLON) { if (text.Equals("m_Target")) { if (currentMethod != null && currentTarget != null) { eventHandlerToScriptTarget.Add(currentMethod, currentTarget); } lexer.Advance(); currentTarget = GetFileId(buffer, lexer); } else if (text.Equals("m_MethodName")) { Assertion.Assert(currentTarget != null, "currentTarget != null"); lexer.Advance(); currentMethod = GetPrimitiveValue(buffer, lexer); } } } lexer.Advance(); } if (currentMethod != null && currentTarget != null) { eventHandlerToScriptTarget.Add(currentMethod, currentTarget); } }
private IList<MethodArgumentStatus> CalculateArgumentStatuses() { var argumentStatuses = new List<MethodArgumentStatus>(); var allInvokedExpressions = new OneToSetMap<IVariableDeclaration, InvokedExpressionData>(); var allStatuses = new OneToSetMap<IVariableDeclaration, VariableDisposeStatus>(); DoForEachExit(data => { data.InvokedExpressions.ForEach(kvp => allInvokedExpressions.AddRange(kvp.Key, kvp.Value)); data.Status.ForEach(kvp => allStatuses.Add(kvp.Key, kvp.Value)); }); var generalStatuses = new Dictionary<IVariableDeclaration, VariableDisposeStatus>(); allStatuses.ForEach(kvp => generalStatuses[kvp.Key] = GetGeneralStatus(kvp.Value)); if (_disposableArguments == null) return null; _disposableArguments.ForEach( kvp => argumentStatuses.Add(new MethodArgumentStatus(kvp.Value, generalStatuses[kvp.Key], allInvokedExpressions[kvp.Key].OrderBy(im => im.Offset).ToList(), _psiSourceFile))); if (_processThis) { var allThisInvokedExpressions = new HashSet<InvokedExpressionData>(); var allThisStatuses = new HashSet<VariableDisposeStatus>(); DoForEachExit(data => { allThisInvokedExpressions.UnionWith(data.ThisInvokedExpressions); if (data.ThisStatus.HasValue) allThisStatuses.Add(data.ThisStatus.Value); }); argumentStatuses.Add(new MethodArgumentStatus(0, GetGeneralStatus(allThisStatuses), allThisInvokedExpressions.OrderBy(im => im.Offset).ToList(), _psiSourceFile)); } return argumentStatuses.OrderBy(mas => mas.Number).ToList(); }
public ExternalAnnotationsProvider() { var location = TestDataPath2; annotations = new OneToSetMap<string, FileSystemPath>(StringComparer.OrdinalIgnoreCase); foreach (var file in location.GetChildFiles("*.xml")) annotations.Add(file.NameWithoutExtension, file); foreach (var directory in location.GetChildDirectories()) { foreach (var file in directory.GetChildFiles("*.xml", PathSearchFlags.RecurseIntoSubdirectories)) { annotations.Add(file.NameWithoutExtension, file); annotations.Add(file.Directory.Name, file); } } }
/// <summary> /// Collects the handlers that implement installation against the assembly attributes, see <see cref="InstallAttributesAttribute"/>. /// Do not call, use <see cref="MapAttributeToInstallers"/>. /// </summary> protected void CollectAttributeInstallers() { // Init only once if (myMapAttributeToInstallers != null) { return; } myMapAttributeToInstallers = new OneToSetMap <Type, IInstallAttributes>(); // Cache the installer objects to singleton them in case they handle multiple attrs myMapInstallerTypeToInstance = new Dictionary <Type, IInstallAttributes>(); foreach (Assembly assembly in Assemblies) // All the assemblies { try { foreach (Type typeInstaller in assembly.GetTypes()) // All the types { // Does the current type declare it installs any attrs? object[] attributes = typeInstaller.GetCustomAttributes(typeof(InstallAttributesAttribute), false); if (attributes.Length == 0) { continue; } // Create the installer instance, if not created yet IInstallAttributes installer; if (!myMapInstallerTypeToInstance.TryGetValue(typeInstaller, out installer)) { object objectInstaller = Activator.CreateInstance(typeInstaller); installer = objectInstaller as IInstallAttributes; if (installer == null) { throw new InvalidOperationException(string.Format("The attribute-installer object of type “{0}” does not implement the required “{1}” interface.", typeInstaller.FullName, typeof(IInstallAttributes).FullName)); } myMapInstallerTypeToInstance.Add(typeInstaller, installer); } // Add attributes foreach (InstallAttributesAttribute attribute in attributes) { if (attribute.AttributeToInstall != null) // A single-time installer { // Duplicate? if ((myMapAttributeToInstallers.ContainsKey(attribute.AttributeToInstall)) && (myMapAttributeToInstallers[attribute.AttributeToInstall].Contains(installer))) { throw new InvalidOperationException(string.Format("The installer class “{0}” registers for the “{1}” attribute twice.", typeInstaller.FullName, attribute.AttributeToInstall.FullName)); } myMapAttributeToInstallers.Add(attribute.AttributeToInstall, installer); } } } } catch (Exception ex) { throw new InvalidOperationException(string.Format("Failed to collect attribute-installers from the “{0}” assembly. {1}", assembly.FullName, ex.Message), ex); } } }
private static void FillScriptMapping(Dictionary <string, string> simpleValues, Dictionary <string, FileID> referenceValues, OneToSetMap <string, string> scriptMapping) { var anchor = simpleValues.GetValueSafe("&anchor"); if (referenceValues.TryGetValue(UnityYamlConstants.ScriptProperty, out var fileID)) { scriptMapping.Add(anchor, fileID.guid); } }
public ExternalAnnotationsProvider() { var location = TestDataPath2; annotations = new OneToSetMap <string, FileSystemPath>(StringComparer.OrdinalIgnoreCase); foreach (var file in location.GetChildFiles("*.xml")) { annotations.Add(file.NameWithoutExtension, file); } foreach (var directory in location.GetChildDirectories()) { foreach (var file in directory.GetChildFiles("*.xml", PathSearchFlags.RecurseIntoSubdirectories)) { annotations.Add(file.NameWithoutExtension, file); annotations.Add(file.Directory.Name, file); } } }
protected override NTriplesFileCache ComputeCache(IPsiSourceFile sourceFile, IList <INTriplesSymbol> data) { var uriIdentifierData = new List <NTriplesUriIdentifierSymbol>(); var prefixDeclarationData = new List <NTriplesPrefixDeclarationSymbol>(); foreach (INTriplesSymbol symbol in data) { var uriIdentifierSymbol = symbol as NTriplesUriIdentifierSymbol; if (uriIdentifierSymbol != null) { uriIdentifierData.Add(uriIdentifierSymbol); continue; } var prefixDeclarationSymbol = symbol as NTriplesPrefixDeclarationSymbol; if (prefixDeclarationSymbol != null) { prefixDeclarationData.Add(prefixDeclarationSymbol); } } this.myProjectFileToSymbolsUriIdentifierMap.AddValueRange(sourceFile, uriIdentifierData); foreach (NTriplesUriIdentifierSymbol declaration in uriIdentifierData) { var uri = declaration.Namespace + declaration.LocalName; this.myUriToUriIdentifierSymbolsMap.Add(uri, declaration); if (declaration.Info.Kind == IdentifierKind.Subject) { myUriToSubjectSymbolsMap.Add(uri, declaration); } if (declaration.Info.IsTypePropertyDeclaration) { this.myUriToTypePropertyDeclarationSymbolsMap.Add(uri, declaration); } if (declaration.Info.IsClassDeclaration) { this.myUriToTypeDeclarationSymbolsMap.Add(uri, declaration); } else if (declaration.Info.DeclaredTypeNames.Any()) { this.myUriToTypeInstantiationSymbolsMap.Add(uri, declaration); } } this.myProjectFileToSymbolsPrefixDeclarationMap.AddValueRange(sourceFile, prefixDeclarationData); foreach (NTriplesPrefixDeclarationSymbol declaration in prefixDeclarationData) { this.myNameToPrefixDeclarationSymbolsMap.Add(declaration.Name, declaration); } return(new NTriplesFileCache(uriIdentifierData, prefixDeclarationData)); }
private void UpdateIndex(AttributedTypesTrieNode node, OneToSetMap <IPsiSourceFile, AttributedTypesTrieNode> sourceFileToNodes) { foreach (var annotationData in node.Annotations) { sourceFileToNodes.Add(annotationData.SourceFile, node); } foreach (var childNode in node.Children.Values) { UpdateIndex(childNode, sourceFileToNodes); } }
public TempAnnotationsLoader() { myAnnotations = new OneToSetMap <string, FileSystemPath>(StringComparer.OrdinalIgnoreCase); var annotationsPath = GetType().Assembly.GetPath().Directory / "Extensions" / "JetBrains.Unity" / "annotations"; var annotationFiles = annotationsPath.GetChildFiles(); foreach (var annotationFile in annotationFiles) { myAnnotations.Add(annotationFile.NameWithoutExtension, annotationFile); } }
private void UpdateIndexAfterLoad(AttributedTypesTrieNode trieNode) { foreach (var annotationData in trieNode.Annotations) { mySourceFileToNodes.Add(annotationData.SourceFile, trieNode); } foreach (var childNode in trieNode.Children.Values) { UpdateIndexAfterLoad(childNode); } }
private static OneToSetMap<string, string> GetTraitsFromAttributes(IEnumerable<IAttributeInfo> attributes) { var traits = new OneToSetMap<string, string>(); foreach (var attributeInfo in attributes) { var name = attributeInfo.GetPropertyValue<string>("Name"); var value = attributeInfo.GetPropertyValue<string>("Value"); if (name != null && value != null) traits.Add(name, value); } return traits; }
public AnnotationsLoader() { myAnnotations = new OneToSetMap <string, FileSystemPath>(StringComparer.OrdinalIgnoreCase); var testDataPathBase = TestUtil.GetTestDataPathBase(GetType().Assembly); var annotationsPath = testDataPathBase.Parent.Parent / "src" / "resharper-unity" / "annotations"; Assertion.Assert(annotationsPath.ExistsDirectory, $"Cannot find annotations: {annotationsPath}"); var annotationFiles = annotationsPath.GetChildFiles(); foreach (var annotationFile in annotationFiles) { myAnnotations.Add(annotationFile.NameWithoutExtension, annotationFile); } }
public AnnotationsLoader(SimpleExtensionManager extensionManager) { this.extensionManager = extensionManager; var location = FileSystemPath.CreateByCanonicalPath(Assembly.GetExecutingAssembly().Location) .Directory.Combine("ExternalAnnotations"); myAnnotations = new OneToSetMap<string, FileSystemPath>(StringComparer.OrdinalIgnoreCase); // Cache the annotation filenames to save scanning the directory multiple times. // Safe to cache as the user shouldn't be changing files in the install dir. If // they want to add extra annotations, use an extension. // The rules are simple: either the file is named after the assembly, or the folder // is (or both, but that doesn't matter) foreach (var file in location.GetChildFiles("*.xml")) myAnnotations.Add(file.NameWithoutExtension, file); foreach (var directory in location.GetChildDirectories()) { foreach (var file in directory.GetChildFiles("*.xml", PathSearchFlags.RecurseIntoSubdirectories)) { myAnnotations.Add(file.NameWithoutExtension, file); myAnnotations.Add(file.Directory.Name, file); } } }
private void AddUniqueValue(MonoBehaviourField field, InspectorVariableUsage variableUsage) { var uniqueValuePtr = variableUsage.Value.GetHashCode(); var previousCount = myUniqueValuesCount.GetOrEmpty(field).Count; myUniqueValuesCount.Add(field, uniqueValuePtr); var newCount = myUniqueValuesCount.GetOrEmpty(field).Count; if (previousCount < 2 && newCount != previousCount) { var isAdded = myUniqueValuesInstances.Add(field, variableUsage.Value); Assertion.Assert(isAdded, "value should not be presented"); } }
private static OneToSetMap <string, string> GetTraitsFromAttributes(IEnumerable <IAttributeInfo> attributes) { var traits = new OneToSetMap <string, string>(); foreach (var attributeInfo in attributes) { var name = attributeInfo.GetPropertyValue <string>("Name"); var value = attributeInfo.GetPropertyValue <string>("Value"); if (name != null && value != null) { traits.Add(name, value); } } return(traits); }
private static void AddWords(OneToSetMap <string, string> wordsPerAssembly, JetHashSet <string> abbreviations, IAssemblyPsiModule assemblyPsiModule, string name) { var textParts = TextSplitter.Split(name); foreach (var textPart in textParts.Where(tp => tp.Type == TextPartType.Word)) { if (textPart.Text == textPart.Text.ToUpperInvariant()) { abbreviations.Add(textPart.Text); } else { wordsPerAssembly.Add(assemblyPsiModule.Assembly.AssemblyName.Name, textPart.Text); } } }
public void UpdateIncludes([NotNull] FileSystemPath includer, [NotNull] ICollection <FileSystemPath> includees) { lock (_locker) { foreach (FileSystemPath includee in _includerToIncludees[includer]) { _includeeToIncluders.Remove(includee, includer); } _includerToIncludees.RemoveKey(includer); if (includees.Count > 0) { _includerToIncludees.AddRange(includer, includees); foreach (FileSystemPath includee in includees) { _includeeToIncluders.Add(includee, includer); } } } }
/// <summary> /// return true when some data was added /// </summary> public bool Merge(AttributedTypesTrieNode builtPart, OneToSetMap <IPsiSourceFile, AttributedTypesTrieNode> sourceFileToNodes) { var ret = false; if (builtPart.myAnnotations != null && builtPart.myAnnotations.Count > 0) { ret = true; foreach (var data in builtPart.myAnnotations) { sourceFileToNodes.Add(data.SourceFile, this); } } if (myAnnotations == null && builtPart.myAnnotations != null) { myAnnotations = builtPart.myAnnotations; } else if (myAnnotations != null && builtPart.myAnnotations != null) { myAnnotations = myAnnotations.Concat(builtPart.myAnnotations).ToList(); } if (builtPart.myChildren != null) { foreach (var child in builtPart.myChildren) { AttributedTypesTrieNode ownChild; var childTrie = child.Value; if (Children.TryGetValue(child.Key, out ownChild)) { ret = ownChild.Merge(childTrie, sourceFileToNodes) || ret; } else { Children[child.Key] = childTrie; ret = true; UpdateIndex(childTrie, sourceFileToNodes); } } } return(ret); }
public void Execute(ISolution solution, ITextControl textControl) { var jetPopupMenus = solution.GetPsiServices().GetComponent <JetPopupMenus>(); var cache = solution.GetComponent <SpecflowStepsDefinitionsCache>(); jetPopupMenus.ShowModal(JetPopupMenu.ShowWhen.AutoExecuteIfSingleEnabledItem, (lifetime, menu) => { menu.Caption.Value = WindowlessControlAutomation.Create("Where to create the step ?"); var availableSteps = cache.GetBindingTypes(_reference.GetElement().GetPsiModule()); var filesPerClasses = new OneToSetMap <string, SpecflowStepsDefinitionsCache.AvailableBindingClass>(); foreach (var availableBindingClass in availableSteps) { filesPerClasses.Add(availableBindingClass.ClassClrName, availableBindingClass); } menu.ItemKeys.AddRange(filesPerClasses); menu.DescribeItem.Advise(lifetime, e => { var(classClrFullName, _) = (KeyValuePair <string, ISet <SpecflowStepsDefinitionsCache.AvailableBindingClass> >)e.Key; e.Descriptor.Icon = PsiSymbolsThemedIcons.Class.Id; e.Descriptor.Style = MenuItemStyle.Enabled; var clrTypeName = new ClrTypeName(classClrFullName); e.Descriptor.Text = new RichText(clrTypeName.ShortName, DeclaredElementPresenterTextStyles.ParameterInfo.GetStyle(DeclaredElementPresentationPartKind.Type)); e.Descriptor.ShortcutText = clrTypeName.GetNamespaceName(); }); menu.ItemClicked.Advise(lifetime, key => { var(_, availableBindingClasses) = (KeyValuePair <string, ISet <SpecflowStepsDefinitionsCache.AvailableBindingClass> >)key; OpenFileSelectionModal(jetPopupMenus, textControl, availableBindingClasses, _reference.GetStepKind(), _reference.GetStepText()); }); menu.PopupWindowContextSource = textControl.PopupWindowContextFactory.ForCaret(); }); }
public TypeResolver() { myFullNames.Add("string", typeof(string).FullName); myFullNames.Add("int", typeof(int).FullName); myFullNames.Add("void", typeof(void).FullName); myFullNames.Add("bool", typeof(bool).FullName); myFullNames.Add("object", typeof(object).FullName); myFullNames.Add("float", typeof(float).FullName); myFullNames.Add("double", typeof(double).FullName); myFullNames.Add("IEnumerator", typeof(IEnumerator).FullName); // TODO: Provide a better way of handling generics? // We only have one use so far, in AssetModificationProcessor.CanOpenForEdit in 2020.2. ApiParser will fail // if we get any others, as the list above are the only non-Unity types we recognise. Note that using // typeof(List<string>).FullName will give an assembly qualified name for the type parameter, including // culture, version and public key token. We need a simple type name. myFullNames.Add("List<string>", "System.Collections.Generic.List`1[[System.String]]"); }
private IDictionary <long, IHierarchyElement> DoImport(Guid ownerGuid, AssetDocumentHierarchyElement assetDocumentHierarchyElement, HashSet <Guid> visitedGuid) { var result = new Dictionary <long, IHierarchyElement>(); foreach (var prefabInstanceHierarchy in assetDocumentHierarchyElement.GetPrefabInstanceHierarchies()) { var guid = prefabInstanceHierarchy.SourcePrefabGuid; var sourceFilePath = myMetaFileGuidCache.GetAssetFilePathsFromGuid(guid).FirstOrDefault(); if (sourceFilePath == null) { continue; } if (!myUnityExternalFilesPsiModule.TryGetFileByPath(sourceFilePath, out var sourceFile)) { continue; } var prefabHierarchy = assetDocumentHierarchyElement.AssetDocumentHierarchyElementContainer.GetAssetHierarchyFor(sourceFile); if (prefabHierarchy == null) { continue; } if (!myCache.TryGetFromCache(guid, out var importedElements)) { if (!visitedGuid.Contains(guid)) // invalid assets with cycles in prefab imports { myDependencies.Add(guid, ownerGuid); visitedGuid.Add(guid); importedElements = DoImport(guid, prefabHierarchy, visitedGuid); StoreResult(guid, importedElements); } else { importedElements = EmptyDictionary <long, IHierarchyElement> .Instance; } } foreach (var element in prefabHierarchy.Elements()) { if (element is IStrippedHierarchyElement) { continue; } if (element is IPrefabInstanceHierarchy) { continue; } var imported = element.Import(prefabInstanceHierarchy); if (imported == null) { continue; } result[imported.Location.LocalDocumentAnchor] = imported; } foreach (var element in importedElements.Values) { Assertion.Assert(!(element is IStrippedHierarchyElement), "element should be imported"); Assertion.Assert(!(element is IPrefabInstanceHierarchy), "prefab should be imported"); var imported = element.Import(prefabInstanceHierarchy); if (imported == null) { continue; } result[imported.Location.LocalDocumentAnchor] = imported; } } foreach (var value in result.Values) { var transform = value as ImportedTransformHierarchy; var reference = transform?.OwningGameObject; if (reference == null) { continue; } var importedGameObject = result.GetValueSafe(reference.Value.LocalDocumentAnchor) as ImportedGameObjectHierarchy; if (importedGameObject == null) { continue; } importedGameObject.TransformHierarchy = transform; } return(result); }
public void Execute(IDataContext context, DelegateExecute nextExecute) { var solution = context.GetData(ProjectModelDataConstants.SOLUTION); if (solution == null) { return; } var symbolCache = solution.GetComponent <ISymbolCache>(); var types = new OneToSetMap <string, string>(); var symbolScope = symbolCache.GetSymbolScope(LibrarySymbolScope.FULL, true); foreach (var typeElement in symbolScope.GetAllTypeElementsGroupedByName().OfType <ITypeMember>()) { // Non-nested, public or protected types. Essentially what would appear in completion if (typeElement.GetContainingType() == null && IsVisible(typeElement)) { var typeParametersOwner = (ITypeParametersOwner)typeElement; var shortName = typeElement.ShortName + (typeParametersOwner.TypeParameters.Count > 0 ? $"`{typeParametersOwner.TypeParameters.Count}" : string.Empty); types.Add(shortName, ((ITypeElement)typeElement).GetClrName().FullName); } } Dumper.DumpToNotepad(writer => { var toDump = (from pair in types where pair.Value.Count > 1 && pair.Value.Any(x => !x.StartsWith("System")) let skipped = IsSkipped(pair) select new { pair, skipped }).OrderBy(x => x.pair.Key).ToList(); writer.WriteLine($"Found {toDump.Count} items. Skipping {toDump.Count(x => x.skipped)}"); writer.WriteLine(); foreach (var(key, value) in toDump.Where(x => !x.skipped).Select(x => x.pair)) { writer.WriteLine("Short name: " + key); foreach (var fullName in value) { writer.WriteLine($" {fullName}"); } writer.WriteLine(); } writer.WriteLine(); writer.WriteLine(); writer.WriteLine(); writer.WriteLine("Skipping:"); writer.WriteLine(); foreach (var(key, value) in toDump.Where(x => x.skipped).Select(x => x.pair)) { writer.WriteLine("Short name: " + key); foreach (var fullName in value) { writer.WriteLine($" {fullName}"); } writer.WriteLine(); } }); }