public static IReadOnlyCollection <ITypeElement> GetLinkedTypes(ITypeElement source) { var sources = new[] { source } .Concat(source.GetAllSuperTypes() .Select(x => x.GetTypeElement()) .WhereNotNull() .Where(x => !x.IsObjectClass())); var linkedTypes = sources.SelectMany(GetLinkedTypesInternal).ToList(); // TODO move to Internal method var services = source.GetPsiServices(); linkedTypes.ForEach(x => services.Finder.FindInheritors(x, new FindResultConsumer(y => { if ((y as FindResultDeclaredElement)?.DeclaredElement is ITypeElement typeElement) { linkedTypes.Add(typeElement); } return(FindExecution.Continue); }), NullProgressIndicator.Create())); return(linkedTypes); }
private static IReadOnlyCollection <ITypeElement> GetLinkedTypesInternal(ITypeElement source) { var settings = GetSettings(source.GetSolution()); var derivedNames = GetDerivedNames(source, settings.NamingSuffixes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); var attributeName = settings.TypeofAttributeName.TrimFromEnd("Attribute"); var typeofs = GetAttributeLinkedTypes(source, attributeName); if (typeofs != null) { return(typeofs.ToList()); } var psiServices = source.GetPsiServices(); var symbolCache = psiServices.Symbols.GetSymbolScope(LibrarySymbolScope.NONE, caseSensitive: true); var linkedTypes = derivedNames.SelectMany(x => symbolCache.GetElementsByShortName(x)).ToList(); var wordIndex = psiServices.WordIndex; var sourceFiles = wordIndex.GetFilesContainingAllWords(new[] { source.ShortName }); var typesInFiles = sourceFiles .SelectMany(x => psiServices.Symbols.GetTypesAndNamespacesInFile(x)) .OfType <ClassLikeTypeElement>() .Where(x => GetAttributeLinkedTypes(x, attributeName)?.Contains(source) ?? false); linkedTypes.AddRange(typesInFiles); return(linkedTypes.Where(x => !x.Equals(source)).Cast <ITypeElement>().ToList()); }
public IEnumerable <ITypeElement> GetLinkedTypes(ITypeElement sourceType) { var services = sourceType.GetPsiServices(); var symbolScope = services.Symbols.GetSymbolScope(LibrarySymbolScope.FULL, caseSensitive: false); var linkedNames = _linkedNamesCache.LinkedNamesMap[sourceType.ShortName]; var possibleLinkedTypes = linkedNames.SelectMany(x => symbolScope.GetElementsByShortName(x.Second).OfType <ITypeElement>()); foreach (var possibleLinkedType in possibleLinkedTypes) { if (_linkedTypesProviders.Any(x => x.IsLinkedType(sourceType, possibleLinkedType)) || _linkedTypesProviders.Any(x => x.IsLinkedType(possibleLinkedType, sourceType))) { yield return(possibleLinkedType); } } }
public string GetForTypeElement([CanBeNull] ITypeElement typeElement) { if (typeElement == null) { return(null); } if (_highlighterIdSource == HighlighterIdSource.ReSharper) { var language = CSharpLanguage.Instance; if (language != null) { return(typeElement .GetPsiServices() .LanguageManager .TryGetService <IHighlightingAttributeIdProvider>(language) ?.GetHighlightingAttributeId(typeElement, false)); } return(null); } switch (typeElement) { case IDelegate _: return(Delegate); case IEnum _: return(Enum); case IInterface _: return(Interface); case IStruct _: return(Struct); case ITypeParameter _: return(TypeParameter); case IClass @class: return(@class.IsAbstract && @class.IsSealed ? StaticClass : Class); default: return(VsIdentifier); } }