コード例 #1
0
ファイル: EnumGenerator.cs プロジェクト: seawatts/jsii
        SeparatedSyntaxList <EnumMemberDeclarationSyntax> CreateValues()
        {
            return(SF.SeparatedList(Type.Members.Select(GetMemberDeclaration)));

            EnumMemberDeclarationSyntax GetMemberDeclaration(EnumMember member)
            {
                EnumMemberDeclarationSyntax declaration = SF.EnumMemberDeclaration
                                                          (
                    SF.List(new[] {
                    SF.AttributeList(SF.SeparatedList(new[] {
                        SF.Attribute(
                            SF.ParseName("JsiiEnumMember"),
                            SF.ParseAttributeArgumentList($"(\"{member.Name}\")")
                            )
                    }))
                }),
                    Symbols.GetNameSyntaxToken(Type, member),
                    null
                                                          );

                if (member.Docs != null)
                {
                    DocCommentGeneratorBase <EnumMember> generator = new EnumMemberDocCommentGenerator(member);
                    SyntaxTriviaList trivia = SF.TriviaList(generator.CreateDocComment());

                    declaration = declaration.WithLeadingTrivia(trivia);
                }

                return(declaration);
            }
        }
コード例 #2
0
        string Render(Docs docs)
        {
            EnumMember member = new EnumMember("member", docs);
            EnumMemberDocCommentGenerator generator = new EnumMemberDocCommentGenerator(member);

            SyntaxTrivia docComment = generator.CreateDocComment();
            SyntaxTree   tree       = SF.SyntaxTree(
                SF.EnumMemberDeclaration("Member")
                .WithLeadingTrivia(generator.CreateDocComment())
                .NormalizeWhitespace(elasticTrivia: true)
                );

            return(tree.ToString());
        }
コード例 #3
0
ファイル: EnumGenerator.cs プロジェクト: nicholasgriffen/jsii
        SeparatedSyntaxList <EnumMemberDeclarationSyntax> CreateValues()
        {
            return(SF.SeparatedList(Type.Members.Select(GetMemberDeclaration)));

            EnumMemberDeclarationSyntax GetMemberDeclaration(EnumMember member)
            {
                EnumMemberDeclarationSyntax declaration = SF.EnumMemberDeclaration
                                                          (
                    SF.List(GetAttributeLists()),
                    Symbols.GetNameSyntaxToken(Type, member),
                    null
                                                          );

                if (member.Docs != null)
                {
                    DocCommentGeneratorBase <EnumMember> generator = new EnumMemberDocCommentGenerator(member);
                    SyntaxTriviaList trivia = SF.TriviaList(generator.CreateDocComment());

                    declaration = declaration.WithLeadingTrivia(trivia);
                }

                return(declaration);

                IEnumerable <AttributeListSyntax> GetAttributeLists()
                {
                    yield return(SF.AttributeList(SF.SingletonSeparatedList(
                                                      SF.Attribute(
                                                          SF.ParseName("JsiiEnumMember"),
                                                          SF.ParseAttributeArgumentList($"(name: \"{member.Name}\")")
                                                          )
                                                      )));

                    if (member.Docs?.Stability == Stability.Deprecated)
                    {
                        var argument = member.Docs?.Deprecated != null?SF.Literal(member.Docs?.Deprecated).ToString() : "";

                        yield return(SF.AttributeList(SF.SingletonSeparatedList(
                                                          SF.Attribute(
                                                              SF.ParseName("System.Obsolete"),
                                                              SF.ParseAttributeArgumentList($"({argument})")
                                                              )
                                                          )));
                    }
                }
            }
        }