Exemplo n.º 1
0
        private void Build(CodeFileTokensBuilder builder, INamespaceSymbol namespaceSymbol, List <NavigationItem> navigationItems)
        {
            builder.Keyword(SyntaxKind.NamespaceKeyword);
            builder.Space();
            BuildNamespaceName(builder, namespaceSymbol);

            builder.Space();
            builder.Punctuation(SyntaxKind.OpenBraceToken);
            builder.IncrementIndent();
            builder.NewLine();

            List <NavigationItem> namespaceItems = new List <NavigationItem>();

            foreach (var namedTypeSymbol in SymbolOrderProvider.OrderTypes(namespaceSymbol.GetTypeMembers()))
            {
                BuildType(builder, namedTypeSymbol, namespaceItems);
            }

            CloseBrace(builder);

            var namespaceItem = new NavigationItem()
            {
                NavigationId = namespaceSymbol.GetId(),
                Text         = namespaceSymbol.ToDisplayString(),
                ChildItems   = namespaceItems.ToArray(),
                Tags         = { { "TypeKind", "namespace" } }
            };

            navigationItems.Add(namespaceItem);
        }
        private void BuildType(CodeFileTokensBuilder builder, INamedTypeSymbol namedType, List <NavigationItem> navigationBuilder)
        {
            if (!IsAccessible(namedType))
            {
                return;
            }

            var navigationItem = new NavigationItem()
            {
                NavigationId = GetId(namedType),
                Text         = namedType.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat),
            };

            navigationBuilder.Add(navigationItem);
            navigationItem.Tags.Add("TypeKind", "type_" + namedType.TypeKind.ToString().ToLowerInvariant());

            builder.WriteIndent();
            NodeFromSymbol(builder, namedType, true);
            if (namedType.TypeKind == TypeKind.Delegate)
            {
                builder.Punctuation(SyntaxKind.SemicolonToken);
                builder.NewLine();
                return;
            }

            builder.Space();
            builder.Punctuation(SyntaxKind.OpenBraceToken);
            builder.IncrementIndent();
            builder.NewLine();

            foreach (var namedTypeSymbol in SortTypes(namedType.GetTypeMembers()))
            {
                BuildType(builder, namedTypeSymbol, navigationBuilder);
            }

            foreach (var member in SortMembers(namedType.GetMembers()))
            {
                if (member.Kind == SymbolKind.NamedType || member.IsImplicitlyDeclared || !IsAccessible(member))
                {
                    continue;
                }
                if (member is IMethodSymbol method)
                {
                    if (method.MethodKind == MethodKind.PropertyGet ||
                        method.MethodKind == MethodKind.PropertySet ||
                        method.MethodKind == MethodKind.EventAdd ||
                        method.MethodKind == MethodKind.EventRemove ||
                        method.MethodKind == MethodKind.EventRaise)
                    {
                        continue;
                    }
                }
                BuildMember(builder, member);
            }

            CloseBrace(builder);
        }
Exemplo n.º 3
0
        private void BuildType(CodeFileTokensBuilder builder, INamedTypeSymbol namedType, List <NavigationItem> navigationBuilder)
        {
            if (!IsAccessible(namedType))
            {
                return;
            }

            var navigationItem = new NavigationItem()
            {
                NavigationId = namedType.GetId(),
                Text         = namedType.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat),
            };

            navigationBuilder.Add(navigationItem);
            navigationItem.Tags.Add("TypeKind", namedType.TypeKind.ToString().ToLowerInvariant());

            BuildDocumentation(builder, namedType);
            BuildAttributes(builder, namedType.GetAttributes());

            builder.WriteIndent();
            BuildVisibility(builder, namedType);

            builder.Space();

            switch (namedType.TypeKind)
            {
            case TypeKind.Class:
                BuildClassModifiers(builder, namedType);
                builder.Keyword(SyntaxKind.ClassKeyword);
                break;

            case TypeKind.Delegate:
                builder.Keyword(SyntaxKind.DelegateKeyword);
                break;

            case TypeKind.Enum:
                builder.Keyword(SyntaxKind.EnumKeyword);
                break;

            case TypeKind.Interface:
                builder.Keyword(SyntaxKind.InterfaceKeyword);
                break;

            case TypeKind.Struct:
                if (namedType.IsReadOnly)
                {
                    builder.Keyword(SyntaxKind.ReadOnlyKeyword);
                    builder.Space();
                }
                builder.Keyword(SyntaxKind.StructKeyword);
                break;
            }

            builder.Space();

            NodeFromSymbol(builder, namedType);
            if (namedType.TypeKind == TypeKind.Delegate)
            {
                builder.Punctuation(SyntaxKind.SemicolonToken);
                builder.NewLine();
                return;
            }

            builder.Space();

            BuildBaseType(builder, namedType);

            builder.Punctuation(SyntaxKind.OpenBraceToken);
            builder.IncrementIndent();
            builder.NewLine();

            foreach (var namedTypeSymbol in SymbolOrderProvider.OrderTypes(namedType.GetTypeMembers()))
            {
                BuildType(builder, namedTypeSymbol, navigationBuilder);
            }

            foreach (var member in SymbolOrderProvider.OrderMembers(namedType.GetMembers()))
            {
                if (member.Kind == SymbolKind.NamedType || member.IsImplicitlyDeclared || !IsAccessible(member))
                {
                    continue;
                }
                if (member is IMethodSymbol method)
                {
                    if (method.MethodKind == MethodKind.PropertyGet ||
                        method.MethodKind == MethodKind.PropertySet ||
                        method.MethodKind == MethodKind.EventAdd ||
                        method.MethodKind == MethodKind.EventRemove ||
                        method.MethodKind == MethodKind.EventRaise)
                    {
                        continue;
                    }
                }
                BuildMember(builder, member);
            }

            CloseBrace(builder);
        }