Пример #1
0
        private void BuildTypedConstant(CodeFileTokensBuilder builder, TypedConstant typedConstant)
        {
            if (typedConstant.IsNull)
            {
                builder.Keyword(SyntaxKind.NullKeyword);
            }
            else if (typedConstant.Kind == TypedConstantKind.Enum)
            {
                new CodeFileBuilderEnumFormatter(builder).Format(typedConstant.Type, typedConstant.Value);
            }
            else if (typedConstant.Kind == TypedConstantKind.Type)
            {
                builder.Keyword(SyntaxKind.TypeOfKeyword);
                builder.Punctuation("(");
                DisplayName(builder, (ITypeSymbol)typedConstant.Value);
                builder.Punctuation(")");
            }
            else if (typedConstant.Kind == TypedConstantKind.Array)
            {
                builder.Keyword(SyntaxKind.NewKeyword);
                builder.Punctuation("[] {");

                bool first = true;

                foreach (var value in typedConstant.Values)
                {
                    if (!first)
                    {
                        builder.Punctuation(SyntaxKind.CommaToken);
                        builder.Space();
                    }
                    else
                    {
                        first = false;
                    }

                    BuildTypedConstant(builder, value);
                }
                builder.Punctuation("}");
            }
            else
            {
                if (typedConstant.Value is string s)
                {
                    builder.Append(
                        ObjectDisplay.FormatLiteral(s, ObjectDisplayOptions.UseQuotes | ObjectDisplayOptions.EscapeNonPrintableCharacters),
                        CodeFileTokenKind.StringLiteral);
                }
                else
                {
                    builder.Append(
                        ObjectDisplay.FormatPrimitive(typedConstant.Value, ObjectDisplayOptions.None),
                        CodeFileTokenKind.Literal);
                }
            }
        }
Пример #2
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);
        }
Пример #3
0
 private void BuildTypedConstant(CodeFileTokensBuilder builder, TypedConstant typedConstant)
 {
     if (typedConstant.IsNull)
     {
         builder.Keyword(SyntaxKind.NullKeyword);
     }
     else if (typedConstant.Kind == TypedConstantKind.Enum)
     {
         new CodeFileBuilderEnumFormatter(builder).Format(typedConstant.Type, typedConstant.Value);
     }
     else
     {
         if (typedConstant.Value is string s)
         {
             builder.Append(
                 ObjectDisplay.FormatLiteral(s, ObjectDisplayOptions.UseQuotes | ObjectDisplayOptions.EscapeNonPrintableCharacters),
                 CodeFileTokenKind.StringLiteral);
         }
         else
         {
             builder.Append(
                 ObjectDisplay.FormatPrimitive(typedConstant.Value, ObjectDisplayOptions.None),
                 CodeFileTokenKind.Literal);
         }
     }
 }
Пример #4
0
        private static void BuildClassModifiers(CodeFileTokensBuilder builder, INamedTypeSymbol namedType)
        {
            if (namedType.IsAbstract)
            {
                builder.Keyword(SyntaxKind.AbstractKeyword);
                builder.Space();
            }

            if (namedType.IsStatic)
            {
                builder.Keyword(SyntaxKind.StaticKeyword);
                builder.Space();
            }

            if (namedType.IsSealed)
            {
                builder.Keyword(SyntaxKind.SealedKeyword);
                builder.Space();
            }
        }
Пример #5
0
 private void DisplayName(CodeFileTokensBuilder builder, ISymbol symbol, ISymbol definedSymbol = null)
 {
     if (NeedsAccessibility(symbol))
     {
         builder.Keyword(SyntaxFacts.GetText(ToEffectiveAccessibility(symbol.DeclaredAccessibility)));
         builder.Space();
     }
     foreach (var symbolDisplayPart in symbol.ToDisplayParts(_defaultDisplayFormat))
     {
         builder.Append(MapToken(definedSymbol, symbolDisplayPart));
     }
 }
 private void NodeFromSymbol(CodeFileTokensBuilder builder, ISymbol symbol, bool prependVisibility = false)
 {
     builder.Append(new CodeFileToken()
     {
         DefinitionId = GetId(symbol),
         Kind         = CodeFileTokenKind.LineIdMarker
     });
     if (prependVisibility)
     {
         builder.Keyword(SyntaxFacts.GetText(ToEffectiveAccessibility(symbol.DeclaredAccessibility)));
         builder.Space();
     }
     foreach (var symbolDisplayPart in symbol.ToDisplayParts(_defaultDisplayFormat))
     {
         builder.Append(MapToken(symbol, symbolDisplayPart));
     }
 }
Пример #7
0
 private void BuildVisibility(CodeFileTokensBuilder builder, ISymbol symbol)
 {
     builder.Keyword(SyntaxFacts.GetText(ToEffectiveAccessibility(symbol.DeclaredAccessibility)));
 }
Пример #8
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);
        }