public static Doc Print(VariableDeclarationSyntax node)
        {
            if (node.Variables.Count > 1)
            {
                var docs = Doc.Concat(
                    SeparatedSyntaxList.Print(
                        node.Variables,
                        VariableDeclarator.Print,
                        node.Parent is ForStatementSyntax ? Doc.Line : Doc.HardLine
                        )
                    );

                return(Doc.Concat(Node.Print(node.Type), " ", Doc.Indent(docs)));
            }

            var variable    = node.Variables[0];
            var initializer = variable.Initializer;

            return(Doc.Concat(
                       Doc.Group(
                           Node.Print(node.Type),
                           " ",
                           Token.Print(variable.Identifier),
                           variable.ArgumentList != null
                        ? BracketedArgumentList.Print(variable.ArgumentList)
                        : Doc.Null,
                           initializer != null
                        ? Doc.Concat(" ", Token.Print(initializer.EqualsToken))
                        : Doc.Null
                           ),
                       initializer != null ? RightHandSide.Print(initializer.Value) : Doc.Null
                       ));
        }
Exemple #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));
        }