Example #1
0
        private static void GetSuperTypes(
            [NotNull] ITypeElement typeElement,
            BaseTypeDisplayKind baseTypeDisplayKind,
            ImplementedInterfacesDisplayKind implementedInterfacesDisplayKind,
            [CanBeNull] out DeclaredElementInstance baseType,
            [NotNull] out IList <DeclaredElementInstance> implementedInterfaces)
        {
            baseType = null;
            implementedInterfaces = EmptyList <DeclaredElementInstance> .InstanceList;

            var  searchForBaseType = baseTypeDisplayKind != BaseTypeDisplayKind.Never && typeElement is IClass;
            bool searchForImplementedInterfaces = implementedInterfacesDisplayKind != ImplementedInterfacesDisplayKind.Never;

            if (!searchForBaseType && !searchForImplementedInterfaces)
            {
                return;
            }

            var foundInterfaces = new LocalList <DeclaredElementInstance>();

            foreach (var superType in typeElement.GetAllSuperTypes())
            {
                ITypeElement superTypeElement = superType.GetTypeElement();

                if (superTypeElement is IClass || superTypeElement is IDelegate)
                {
                    if (searchForBaseType)
                    {
                        searchForBaseType = false;
                        if (MatchesBaseTypeDisplayKind(superTypeElement, baseTypeDisplayKind))
                        {
                            baseType = new DeclaredElementInstance(superTypeElement, superType.GetSubstitution());
                        }
                        if (!searchForImplementedInterfaces)
                        {
                            return;
                        }
                    }
                    continue;
                }

                if (searchForImplementedInterfaces &&
                    superTypeElement is IInterface @interface &&
                    MatchesImplementedInterfacesDisplayKind(@interface, implementedInterfacesDisplayKind))
                {
                    foundInterfaces.Add(new DeclaredElementInstance(superTypeElement, superType.GetSubstitution()));
                }
            }

            implementedInterfaces = foundInterfaces.ResultingList();
        }
Example #2
0
        private void AddSuperTypes(
            [NotNull] IdentifierTooltipContent identifierContent,
            [NotNull] ITypeElement typeElement,
            BaseTypeDisplayKind baseTypeDisplayKind,
            ImplementedInterfacesDisplayKind implementedInterfacesDisplayKind,
            [NotNull] PsiLanguageType languageType,
            [NotNull] ITreeNode contextualNode,
            [NotNull] HighlighterIdProvider highlighterIdProvider,
            [NotNull] IContextBoundSettingsStore settings)
        {
            GetSuperTypes(
                typeElement,
                baseTypeDisplayKind,
                implementedInterfacesDisplayKind,
                out DeclaredElementInstance baseType,
                out IList <DeclaredElementInstance> implementedInterfaces);

            if (baseType == null && implementedInterfaces.Count == 0)
            {
                return;
            }

            PresenterOptions presenterOptions = PresenterOptions.ForBaseTypeOrImplementedInterfaceTooltip(settings);

            if (baseType != null)
            {
                identifierContent.BaseType = _colorizerPresenter.TryPresent(baseType, presenterOptions, languageType, highlighterIdProvider, contextualNode, out _);
            }

            if (implementedInterfaces.Count > 0)
            {
                var sortedPresentedInterfaces = new SortedDictionary <string, RichText>(StringComparer.Ordinal);
                foreach (DeclaredElementInstance implementedInterface in implementedInterfaces)
                {
                    RichText richText = _colorizerPresenter.TryPresent(implementedInterface, presenterOptions, languageType, highlighterIdProvider, contextualNode, out _);
                    if (richText != null)
                    {
                        sortedPresentedInterfaces[richText.ToString(false)] = richText;
                    }
                }
                foreach (RichText richText in sortedPresentedInterfaces.Values)
                {
                    identifierContent.ImplementedInterfaces.Add(richText);
                }
            }
        }
Example #3
0
        private static bool MatchesBaseTypeDisplayKind([NotNull] ITypeElement typeElement, BaseTypeDisplayKind displayKind)
        {
            switch (displayKind)
            {
            case BaseTypeDisplayKind.Never:
                return(false);

            case BaseTypeDisplayKind.SolutionCode:
                return(!(typeElement is ICompiledElement));

            case BaseTypeDisplayKind.SolutionCodeAndNonSystemExternalCode:
                return(!(typeElement is ICompiledElement && typeElement.IsInSystemLikeNamespace()));

            case BaseTypeDisplayKind.OnlyIfNotSystemObject:
                return(!typeElement.IsObjectClass());

            case BaseTypeDisplayKind.Always:
                return(true);

            default:
                return(false);
            }
        }