private static StringBuilder AppendType(this StringBuilder identifier,
                                         ITypeElement type,
                                         ISubstitution substitution,
                                         IDictionary <DeclaredElementInstance, IName> seenElements)
 {
     return(identifier.Append('[').Append(type.GetName(substitution, seenElements).Identifier).Append(']'));
 }
Beispiel #2
0
        private static TypeHierarchy CreateTypeHierarchy(ITypeElement type,
                                                         ISubstitution substitution,
                                                         IKaVEList <ITypeName> seenTypes,
                                                         bool shouldIgnoreRootTypes)
        {
            if (shouldIgnoreRootTypes && (type == null || IsRootType(type)))
            {
                // ignore implicite extensions in type hierarchy
                return(null);
            }
            var typeName = type.GetName <ITypeName>(substitution);

            seenTypes.Add(typeName);
            var enclosingClassHierarchy = new TypeHierarchy(typeName.Identifier);

            foreach (var superType in type.GetSuperTypes())
            {
                var resolveResult     = superType.Resolve();
                var declElem          = resolveResult.DeclaredElement;
                var isUnresolvedAlias = declElem is IUsingAliasDirective;
                // TODO NameUpdate: "isUnknownOrUnResolvedUntested" required by one analyzed solution, still untested
                var isUnknownOrUnResolvedUntested = superType.IsUnknown || !superType.IsResolved;
                if (!resolveResult.IsValid() || declElem == null || isUnresolvedAlias || isUnknownOrUnResolvedUntested)
                {
                    enclosingClassHierarchy.Implements.Add(new TypeHierarchy());
                    continue;
                }

                var superName = declElem.GetName <ITypeName>(substitution);
                if (seenTypes.Contains(superName))
                {
                    continue;
                }

                var superTypeElement      = superType.GetTypeElement();
                var superTypeSubstitution = superType.GetSubstitution();
                var superHierarchy        = CreateTypeHierarchy(superTypeElement, superTypeSubstitution, seenTypes, true);

                if (declElem is IClass || declElem is IStruct)
                {
                    enclosingClassHierarchy.Extends = superHierarchy;
                }
                else if (declElem is IInterface)
                {
                    enclosingClassHierarchy.Implements.Add(superHierarchy);
                }
            }
            return(enclosingClassHierarchy);
        }