コード例 #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.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 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);
                }
            }
        }
コード例 #3
0
 private void DisplayName(CodeFileTokensBuilder builder, ISymbol symbol, ISymbol definedSymbol = null)
 {
     foreach (var symbolDisplayPart in symbol.ToDisplayParts(_defaultDisplayFormat))
     {
         builder.Append(MapToken(definedSymbol, symbolDisplayPart));
     }
 }
コード例 #4
0
        private void BuildDocumentation(CodeFileTokensBuilder builder, ISymbol symbol)
        {
            var lines = symbol.GetDocumentationCommentXml().Trim().Split(_newlineChars);

            if (lines.All(string.IsNullOrWhiteSpace))
            {
                return;
            }
            builder.Append(null, CodeFileTokenKind.DocumentRangeStart);
            foreach (var line in lines)
            {
                builder.WriteIndent();
                builder.Comment("// " + line.Trim());
                builder.NewLine();
            }
            builder.Append(null, CodeFileTokenKind.DocumentRangeEnd);
        }
コード例 #5
0
 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));
     }
 }
コード例 #6
0
 private void NodeFromSymbol(CodeFileTokensBuilder builder, ISymbol symbol)
 {
     builder.Append(new CodeFileToken()
     {
         DefinitionId = symbol.GetId(),
         Kind         = CodeFileTokenKind.LineIdMarker
     });
     DisplayName(builder, symbol, symbol);
 }
コード例 #7
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));
     }
 }
コード例 #8
0
        public static void BuildDependencies(CodeFileTokensBuilder builder, List <DependencyInfo> dependencies)
        {
            if (dependencies != null && dependencies.Any())
            {
                builder.NewLine();
                builder.Append("Dependencies:", CodeFileTokenKind.Text);
                builder.NewLine();
                foreach (DependencyInfo dependency in dependencies)
                {
                    builder.Append(new CodeFileToken(dependency.Name, CodeFileTokenKind.Text)
                    {
                        // allow dependency to be commentable
                        DefinitionId = dependency.Name
                    });
                    // don't include the version in the API sign-off diffs
                    builder.Append(null, CodeFileTokenKind.SkipDiffRangeStart);
                    builder.Append($"-{dependency.Version}", CodeFileTokenKind.Text);
                    builder.Append(null, CodeFileTokenKind.SkipDiffRangeEnd);
                    builder.NewLine();
                }

                builder.NewLine();
            }
        }
コード例 #9
0
        private void BuildAttributes(CodeFileTokensBuilder builder, ImmutableArray <AttributeData> attributes)
        {
            const string attributeSuffix = "Attribute";

            foreach (var attribute in attributes)
            {
                if (!IsAccessible(attribute.AttributeClass) || IsSkippedAttribute(attribute.AttributeClass))
                {
                    continue;
                }
                builder.WriteIndent();
                builder.Punctuation(SyntaxKind.OpenBracketToken);
                var name = attribute.AttributeClass.Name;
                if (name.EndsWith(attributeSuffix))
                {
                    name = name.Substring(0, name.Length - attributeSuffix.Length);
                }
                builder.Append(name, CodeFileTokenKind.TypeName);
                if (attribute.ConstructorArguments.Any())
                {
                    builder.Punctuation(SyntaxKind.OpenParenToken);
                    bool first = true;

                    foreach (var argument in attribute.ConstructorArguments)
                    {
                        if (!first)
                        {
                            builder.Punctuation(SyntaxKind.CommaToken);
                            builder.Space();
                        }
                        else
                        {
                            first = false;
                        }
                        BuildTypedConstant(builder, argument);
                    }

                    foreach (var argument in attribute.NamedArguments)
                    {
                        if (!first)
                        {
                            builder.Punctuation(SyntaxKind.CommaToken);
                            builder.Space();
                        }
                        else
                        {
                            first = false;
                        }
                        builder.Append(argument.Key, CodeFileTokenKind.Text);
                        builder.Space();
                        builder.Punctuation(SyntaxKind.EqualsToken);
                        builder.Space();
                        BuildTypedConstant(builder, argument.Value);
                    }

                    builder.Punctuation(SyntaxKind.CloseParenToken);
                }
                builder.Punctuation(SyntaxKind.CloseBracketToken);
                builder.NewLine();
            }
        }
コード例 #10
0
 protected override void AddLiteralValue(SpecialType type, object value)
 {
     _builder.Append(ObjectDisplay.FormatPrimitive(value, ObjectDisplayOptions.None), CodeFileTokenKind.Literal);
 }