Пример #1
0
 public override bool Walk(ArrayLiteral node)
 {
     if (node != null)
     {
         if (node.Elements != null)
         {
             foreach (var element in node.Elements)
             {
                 element.Walk(this);
             }
         }
     }
     return(false);
 }
Пример #2
0
 public override bool Walk(ArrayLiteral node) { AddNode(node); return true; }
 public override bool Walk(ArrayLiteral node)
 {
     if (node != null)
     {
         if (node.Elements != null)
         {
             foreach (var element in node.Elements) {
                 element.Walk(this);
             }
         }
     }
     return false;
 }
Пример #4
0
        public override bool Walk(ArrayLiteral node) {
            if (node.Elements.Length == 0) {
                // If we have no body, format the closing bracket.
                bool isMultiLine = ContainsLineFeed(node.GetStartIndex(_tree.LocationResolver), node.GetEndIndex(_tree.LocationResolver));
                if (isMultiLine) {
                    ReplacePreceedingIncludingNewLines(node.GetEndIndex(_tree.LocationResolver) - 1, ReplaceWith.InsertNewLineAndIndentation, replaceOnNewLine: true);
                } else {
                    ReplacePreceedingWhiteSpace(node.GetEndIndex(_tree.LocationResolver) - 1, "");
                }
            } else {
                Indent();

                for (int i = 0; i < node.Elements.Length; i++) {
                    var curExpr = node.Elements[i];

                    // Fix spacing of commas and '['
                    if (i == 0) {
                        // There should be no spacing between the [ and the first element
                        ReplacePreceedingWhiteSpace(curExpr.GetStartIndex(_tree.LocationResolver), "", _openBracket);
                    } else {
                        ReplacePreceedingWhiteSpace(
                            curExpr.GetStartIndex(_tree.LocationResolver),
                            _options.SpaceAfterComma ? " " : string.Empty,
                            _comma);
                    }

                    ReplacePreceedingWhiteSpace(curExpr.GetStartIndex(_tree.LocationResolver));
                    curExpr.Walk(this);
                }
                Dedent();

                // Format Ending Brace
                if (ContainsLineFeed(node.Elements[node.Elements.Length - 1].GetEndIndex(_tree.LocationResolver), node.GetEndIndex(_tree.LocationResolver))) {
                    ReplacePreceedingIncludingNewLines(node.GetEndIndex(_tree.LocationResolver) - 1, ReplaceWith.InsertNewLineAndIndentation);
                } else {
                    ReplacePreceedingWhiteSpace(node.GetEndIndex(_tree.LocationResolver) - 1, "");
                }
            }
            return false;
        }