Exemplo n.º 1
0
        private static List <Edit> GetEdits(string code, FormattingOptions options, JsAst ast, bool onEnter = false)
        {
            var visitor = new FormattingVisitor(code, ast, options, onEnter);

            visitor.Format(ast);
            return(visitor.Edits);
        }
Exemplo n.º 2
0
        public static IList<Edit> GetEdits(SyntaxTree syntaxTree, TextSpan textSpan, FormattingOptions options)
        {
            // Format.
            var formattingVisitor = new FormattingVisitor(syntaxTree, textSpan, options);
            formattingVisitor.Visit(syntaxTree.Root);

            return formattingVisitor.Edits.Values;
        }
Exemplo n.º 3
0
        private static void AssertParse(string input, string expected)
        {
            var ast       = new Parser(Tokenizer.Create()).Parse(input);
            var formatter = new FormattingVisitor();

            ast.Accept(formatter);
            formatter.GetString().Should().Be(expected);
        }
Exemplo n.º 4
0
        public static IList <TextChange> GetEdits(SyntaxTree syntaxTree, SyntaxNode syntaxNode, TextSpan textSpan, FormattingOptions options)
        {
            // Format.
            var formattingVisitor = new FormattingVisitor(syntaxTree, textSpan, options);

            formattingVisitor.Visit(syntaxNode);

            return(formattingVisitor.Edits.Values);
        }
Exemplo n.º 5
0
        public static IReadOnlyList <FormattingSpan> GetFormattingSpans(this RazorSyntaxTree syntaxTree)
        {
            if (syntaxTree == null)
            {
                throw new ArgumentNullException(nameof(syntaxTree));
            }

            var visitor = new FormattingVisitor(syntaxTree.Source);

            visitor.Visit(syntaxTree.Root);

            return(visitor.FormattingSpans);
        }
Exemplo n.º 6
0
        public string Format(object obj)
        {
            var    _visitor = new FormattingVisitor(this);
            string ret;

            if (obj == null)
            {
                return("null");
            }
            var reference = obj as IReference;

            if (reference != null)
            {
                reference.Dispatch(_visitor);
                ret = _visitor.FormattedValue;
                return(Return(ret, obj));
            }
            var expression = obj as IExpression;

            if (expression != null)
            {
                expression.Dispatch(_visitor);
                ret = _visitor.FormattedValue;
                return(Return(ret, obj));
            }
            var statement = obj as IStatement;

            if (statement != null)
            {
                statement.Dispatch(_visitor);
                ret = _visitor.FormattedValue;
                return(Return(ret, obj));
            }

            string value = _visitor.FormattedValue;

            ret = value;
            if (value.NullOrEmpty())
            {
                ret = "[" + obj.GetType().Name + "]";
            }
            return(Return(ret, obj));
        }
Exemplo n.º 7
0
 public AstFormatter()
 {
     _visitor = new FormattingVisitor(this);
 }