public static Doc Print(EnumMemberDeclarationSyntax node)
        {
            var docs = new List <Doc>
            {
                AttributeLists.Print(node, node.AttributeLists),
                Modifiers.Print(node.Modifiers),
                Token.Print(node.Identifier)
            };

            if (node.EqualsValue != null)
            {
                docs.Add(EqualsValueClause.Print(node.EqualsValue));
            }
            return(Doc.Concat(docs));
        }
Beispiel #2
0
        public static Doc Print(VariableDeclaratorSyntax node)
        {
            var docs = new List <Doc> {
                Token.Print(node.Identifier)
            };

            if (node.ArgumentList != null)
            {
                docs.Add(BracketedArgumentList.Print(node.ArgumentList));
            }
            if (node.Initializer != null)
            {
                docs.Add(EqualsValueClause.Print(node.Initializer));
            }
            return(Doc.Concat(docs));
        }
Beispiel #3
0
        public static Doc Print(ParameterSyntax node)
        {
            var docs = new List <Doc>
            {
                AttributeLists.Print(node, node.AttributeLists),
                node.AttributeLists.Any() ? Doc.Line : Doc.Null,
                Modifiers.Print(node.Modifiers)
            };

            if (node.Type != null)
            {
                docs.Add(Node.Print(node.Type), " ");
            }

            docs.Add(Token.Print(node.Identifier));
            if (node.Default != null)
            {
                docs.Add(EqualsValueClause.Print(node.Default));
            }

            return(Doc.Concat(docs));
        }
Beispiel #4
0
        public static Doc Print(BasePropertyDeclarationSyntax node)
        {
            EqualsValueClauseSyntax?         initializer = null;
            ExplicitInterfaceSpecifierSyntax?explicitInterfaceSpecifierSyntax = null;
            Doc identifier   = Doc.Null;
            Doc eventKeyword = Doc.Null;
            ArrowExpressionClauseSyntax?expressionBody = null;
            SyntaxToken?semicolonToken = null;

            if (node is PropertyDeclarationSyntax propertyDeclarationSyntax)
            {
                expressionBody = propertyDeclarationSyntax.ExpressionBody;
                initializer    = propertyDeclarationSyntax.Initializer;
                explicitInterfaceSpecifierSyntax = propertyDeclarationSyntax.ExplicitInterfaceSpecifier;
                identifier     = Token.Print(propertyDeclarationSyntax.Identifier);
                semicolonToken = propertyDeclarationSyntax.SemicolonToken;
            }
            else if (node is IndexerDeclarationSyntax indexerDeclarationSyntax)
            {
                expressionBody = indexerDeclarationSyntax.ExpressionBody;
                explicitInterfaceSpecifierSyntax = indexerDeclarationSyntax.ExplicitInterfaceSpecifier;
                identifier = Doc.Concat(
                    Token.Print(indexerDeclarationSyntax.ThisKeyword),
                    Node.Print(indexerDeclarationSyntax.ParameterList)
                    );
                semicolonToken = indexerDeclarationSyntax.SemicolonToken;
            }
            else if (node is EventDeclarationSyntax eventDeclarationSyntax)
            {
                eventKeyword = Token.Print(eventDeclarationSyntax.EventKeyword, " ");
                explicitInterfaceSpecifierSyntax = eventDeclarationSyntax.ExplicitInterfaceSpecifier;
                identifier     = Token.Print(eventDeclarationSyntax.Identifier);
                semicolonToken = eventDeclarationSyntax.SemicolonToken;
            }

            Doc contents = string.Empty;

            if (node.AccessorList != null)
            {
                Doc separator = " ";
                if (
                    node.AccessorList.Accessors.Any(
                        o =>
                        o.Body != null ||
                        o.ExpressionBody != null ||
                        o.Modifiers.Any() ||
                        o.AttributeLists.Any()
                        )
                    )
                {
                    separator = Doc.Line;
                }

                contents = Doc.Group(
                    Doc.Concat(
                        separator,
                        Token.Print(node.AccessorList.OpenBraceToken),
                        Doc.Indent(
                            node.AccessorList.Accessors.Select(
                                o => PrintAccessorDeclarationSyntax(o, separator)
                                )
                            .ToArray()
                            ),
                        separator,
                        Token.Print(node.AccessorList.CloseBraceToken)
                        )
                    );
            }
            else if (expressionBody != null)
            {
                contents = Doc.Concat(ArrowExpressionClause.Print(expressionBody));
            }

            var docs = new List <Doc>();

            docs.Add(ExtraNewLines.Print(node));
            docs.Add(AttributeLists.Print(node, node.AttributeLists));

            return(Doc.Group(
                       Doc.Concat(
                           Doc.Concat(docs),
                           Modifiers.Print(node.Modifiers),
                           eventKeyword,
                           Node.Print(node.Type),
                           " ",
                           explicitInterfaceSpecifierSyntax != null
                        ? Doc.Concat(
                               Node.Print(explicitInterfaceSpecifierSyntax.Name),
                               Token.Print(explicitInterfaceSpecifierSyntax.DotToken)
                               )
                        : Doc.Null,
                           identifier,
                           contents,
                           initializer != null ? EqualsValueClause.Print(initializer) : Doc.Null,
                           semicolonToken.HasValue ? Token.Print(semicolonToken.Value) : Doc.Null
                           )
                       ));
        }