Merge pull request #780 from dart-lang/switch-to-new-ast-structures

Stop using deprecated AST classes/methods.
diff --git a/lib/src/argument_list_visitor.dart b/lib/src/argument_list_visitor.dart
index 06c159e..c71b9f0 100644
--- a/lib/src/argument_list_visitor.dart
+++ b/lib/src/argument_list_visitor.dart
@@ -504,7 +504,7 @@
     // TODO(rnystrom): Should we step into parenthesized expressions?
 
     if (expression is ListLiteral) return expression.leftBracket;
-    if (expression is MapLiteral) return expression.leftBracket;
+    if (expression is SetOrMapLiteral) return expression.leftBracket;
     if (expression is SingleStringLiteral && expression.isMultiline) {
       return expression.beginToken;
     }
diff --git a/lib/src/call_chain_visitor.dart b/lib/src/call_chain_visitor.dart
index 066656b..b7289b0 100644
--- a/lib/src/call_chain_visitor.dart
+++ b/lib/src/call_chain_visitor.dart
@@ -311,7 +311,7 @@
 
     // Don't split right after a collection literal.
     if (expression is ListLiteral) return false;
-    if (expression is MapLiteral) return false;
+    if (expression is SetOrMapLiteral) return false;
 
     // Don't split right after a non-empty curly-bodied function.
     if (expression is FunctionExpression) {
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 29f014d..6aa452a 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -503,7 +503,7 @@
   ///     ]..addAll(numbers);
   bool _isCollectionLike(Expression expression) {
     if (expression is ListLiteral) return false;
-    if (expression is MapLiteral) return false;
+    if (expression is SetOrMapLiteral) return false;
 
     // If the target is a call with a trailing comma in the argument list,
     // treat it like a collection literal.
@@ -1048,58 +1048,6 @@
     });
   }
 
-  visitForEachStatement(ForEachStatement node) {
-    builder.nestExpression();
-    token(node.awaitKeyword, after: space);
-    token(node.forKeyword);
-    space();
-    token(node.leftParenthesis);
-
-    if (node.loopVariable != null) {
-      // TODO(rnystrom): The formatting logic here is slightly different from
-      // how parameter metadata is handled and from how variable metadata is
-      // handled. I think what it does works better in the context of a for-in
-      // loop, but consider trying to unify this with one of the above.
-      //
-      // Metadata on class and variable declarations is *always* split:
-      //
-      //     @foo
-      //     class Bar {}
-      //
-      // Metadata on parameters has some complex logic to handle multiple
-      // parameters with metadata. It also indents the parameters farther than
-      // the metadata when split:
-      //
-      //     function(
-      //         @foo(long arg list...)
-      //             parameter1,
-      //         @foo
-      //             parameter2) {}
-      //
-      // For for-in variables, we allow it to not split, like parameters, but
-      // don't indent the variable when it does split:
-      //
-      //     for (
-      //         @foo
-      //         @bar
-      //         var blah in stuff) {}
-      builder.startRule();
-      visitNodes(node.loopVariable.metadata, between: split, after: split);
-      visit(node.loopVariable);
-      builder.endRule();
-    } else {
-      visit(node.identifier);
-    }
-    soloSplit();
-    token(node.inKeyword);
-    space();
-    visit(node.iterable);
-    token(node.rightParenthesis);
-    builder.unnest();
-
-    _visitLoopBody(node.body);
-  }
-
   visitFormalParameterList(FormalParameterList node,
       {bool nestExpression: true}) {
     // Corner case: empty parameter lists.
@@ -1206,38 +1154,103 @@
     if (nestExpression) builder.unnest();
   }
 
-  visitForStatement(ForStatement node) {
+  visitForStatement2(ForStatement2 node) {
     builder.nestExpression();
+    token(node.awaitKeyword, after: space);
     token(node.forKeyword);
     space();
     token(node.leftParenthesis);
 
     builder.startRule();
 
-    // The initialization clause.
-    if (node.initialization != null) {
-      visit(node.initialization);
-    } else if (node.variables != null) {
-      // Nest split variables more so they aren't at the same level
-      // as the rest of the loop clauses.
-      builder.nestExpression();
+    visit(node.forLoopParts);
 
-      // Allow the variables to stay unsplit even if the clauses split.
-      builder.startRule();
+    token(node.rightParenthesis);
+    builder.endRule();
+    builder.unnest();
 
-      var declaration = node.variables;
-      visitMetadata(declaration.metadata);
-      modifier(declaration.keyword);
-      visit(declaration.type, after: space);
+    _visitLoopBody(node.body);
+  }
 
-      visitCommaSeparatedNodes(declaration.variables, between: () {
-        split();
-      });
+  visitForEachPartsWithDeclaration(ForEachPartsWithDeclaration node) {
+    // TODO(rnystrom): The formatting logic here is slightly different from
+    // how parameter metadata is handled and from how variable metadata is
+    // handled. I think what it does works better in the context of a for-in
+    // loop, but consider trying to unify this with one of the above.
+    //
+    // Metadata on class and variable declarations is *always* split:
+    //
+    //     @foo
+    //     class Bar {}
+    //
+    // Metadata on parameters has some complex logic to handle multiple
+    // parameters with metadata. It also indents the parameters farther than
+    // the metadata when split:
+    //
+    //     function(
+    //         @foo(long arg list...)
+    //             parameter1,
+    //         @foo
+    //             parameter2) {}
+    //
+    // For for-in variables, we allow it to not split, like parameters, but
+    // don't indent the variable when it does split:
+    //
+    //     for (
+    //         @foo
+    //         @bar
+    //         var blah in stuff) {}
+    // TODO(rnystrom): we used to call builder.startRule() here, but now we call
+    // it from visitForStatement2 prior to the `(`.  Is that ok?
+    visitNodes(node.loopVariable.metadata, between: split, after: split);
+    visit(node.loopVariable);
+    // TODO(rnystrom): we used to call builder.endRule() here, but now we call
+    // it from visitForStatement2 after the `)`.  Is that ok?
 
-      builder.endRule();
-      builder.unnest();
-    }
+    _visitForEachPartsFromIn(node);
+  }
 
+  void _visitForEachPartsFromIn(ForEachParts node) {
+    soloSplit();
+    token(node.inKeyword);
+    space();
+    visit(node.iterable);
+  }
+
+  visitForEachPartsWithIdentifier(ForEachPartsWithIdentifier node) {
+    visit(node.identifier);
+    _visitForEachPartsFromIn(node);
+  }
+
+  visitForPartsWithDeclarations(ForPartsWithDeclarations node) {
+    // Nest split variables more so they aren't at the same level
+    // as the rest of the loop clauses.
+    builder.nestExpression();
+
+    // Allow the variables to stay unsplit even if the clauses split.
+    builder.startRule();
+
+    var declaration = node.variables;
+    visitMetadata(declaration.metadata);
+    modifier(declaration.keyword);
+    visit(declaration.type, after: space);
+
+    visitCommaSeparatedNodes(declaration.variables, between: () {
+      split();
+    });
+
+    builder.endRule();
+    builder.unnest();
+
+    _visitForPartsFromLeftSeparator(node);
+  }
+
+  visitForPartsWithExpression(ForPartsWithExpression node) {
+    visit(node.initialization);
+    _visitForPartsFromLeftSeparator(node);
+  }
+
+  void _visitForPartsFromLeftSeparator(ForParts node) {
     token(node.leftSeparator);
 
     // The condition clause.
@@ -1256,12 +1269,6 @@
 
       builder.endRule();
     }
-
-    token(node.rightParenthesis);
-    builder.endRule();
-    builder.unnest();
-
-    _visitLoopBody(node.body);
   }
 
   visitFunctionDeclaration(FunctionDeclaration node) {
@@ -1597,14 +1604,10 @@
   visitListLiteral(ListLiteral node) {
     // Corner case: Splitting inside a list looks bad if there's only one
     // element, so make those more costly.
-    var cost = node.elements.length <= 1 ? Cost.singleElementList : Cost.normal;
+    var cost =
+        node.elements2.length <= 1 ? Cost.singleElementList : Cost.normal;
     _visitCollectionLiteral(
-        node, node.leftBracket, node.elements, node.rightBracket, cost);
-  }
-
-  visitMapLiteral(MapLiteral node) {
-    _visitCollectionLiteral(
-        node, node.leftBracket, node.entries, node.rightBracket);
+        node, node.leftBracket, node.elements2, node.rightBracket, cost);
   }
 
   visitMapLiteralEntry(MapLiteralEntry node) {
@@ -1834,9 +1837,9 @@
     newline();
   }
 
-  visitSetLiteral(SetLiteral node) {
+  visitSetOrMapLiteral(SetOrMapLiteral node) {
     _visitCollectionLiteral(
-        node, node.leftBracket, node.elements, node.rightBracket);
+        node, node.leftBracket, node.elements2, node.rightBracket);
   }
 
   visitShowCombinator(ShowCombinator node) {
@@ -2173,7 +2176,7 @@
 
     // Don't allow a split between a name and a collection. Instead, we want
     // the collection itself to split, or to split before the argument.
-    if (node.expression is ListLiteral || node.expression is MapLiteral) {
+    if (node.expression is ListLiteral || node.expression is SetOrMapLiteral) {
       space();
     } else {
       var split = soloSplit();
@@ -2700,7 +2703,7 @@
   ///         new SomeBuilderClass()..method()..method();
   int _assignmentCost(Expression rightHandSide) {
     if (rightHandSide is ListLiteral) return Cost.assignBlock;
-    if (rightHandSide is MapLiteral) return Cost.assignBlock;
+    if (rightHandSide is SetOrMapLiteral) return Cost.assignBlock;
     if (rightHandSide is CascadeExpression) return Cost.assignBlock;
 
     return Cost.assign;
diff --git a/pubspec.lock b/pubspec.lock
index 5c0437e..6172ed6 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -7,7 +7,7 @@
       name: analyzer
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.35.1"
+    version: "0.35.3"
   args:
     dependency: "direct main"
     description:
@@ -77,7 +77,7 @@
       name: front_end
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.1.11"
+    version: "0.1.13"
   glob:
     dependency: transitive
     description:
@@ -98,7 +98,7 @@
       name: html
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.13.3+3"
+    version: "0.13.4+1"
   http:
     dependency: transitive
     description:
@@ -147,7 +147,7 @@
       name: kernel
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.3.11"
+    version: "0.3.13"
   logging:
     dependency: transitive
     description:
@@ -203,7 +203,7 @@
       name: package_resolver
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.0.6"
+    version: "1.0.10"
   path:
     dependency: "direct main"
     description:
@@ -217,7 +217,7 @@
       name: pedantic
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.4.0"
+    version: "1.5.0"
   plugin:
     dependency: transitive
     description:
@@ -287,7 +287,7 @@
       name: source_span
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.5.4"
+    version: "1.5.5"
   stack_trace:
     dependency: transitive
     description:
@@ -394,4 +394,4 @@
     source: hosted
     version: "2.1.15"
 sdks:
-  dart: ">=2.1.0 <3.0.0"
+  dart: ">=2.1.1-dev.0.0 <3.0.0"
diff --git a/pubspec.yaml b/pubspec.yaml
index 2c0c2f6..ccd6217 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -9,7 +9,7 @@
   sdk: '>=2.0.0 <3.0.0'
 
 dependencies:
-  analyzer: '>=0.35.1 <0.36.0'
+  analyzer: '>=0.35.3 <0.36.0'
   args: '>=0.12.1 <2.0.0'
   path: ^1.0.0
   source_span: ^1.4.0
diff --git a/test/comments/sets.stmt b/test/comments/sets.stmt
index 6d310c6..5ec54a7 100644
--- a/test/comments/sets.stmt
+++ b/test/comments/sets.stmt
@@ -50,8 +50,9 @@
 >>> multiple inline block comments
 var set = <int>{  /* 1 */   /* 2 */   /* 3 */  };
 <<<
-var set =
-    <int>{/* 1 */ /* 2 */ /* 3 */};
+var set = <int>{
+  /* 1 */ /* 2 */ /* 3 */
+};
 >>> multiline trailing block comment
 var set = <int>{  /* comment
 */  };
diff --git a/test/splitting/sets.stmt b/test/splitting/sets.stmt
index 743498a..43e7c3f 100644
--- a/test/splitting/sets.stmt
+++ b/test/splitting/sets.stmt
@@ -90,8 +90,12 @@
 >>> const
 var set = const {"foo", "bar", "fuz", null};
 <<<
-var set =
-    const {"foo", "bar", "fuz", null};
+var set = const {
+  "foo",
+  "bar",
+  "fuz",
+  null
+};
 >>> trailing comma forces split
 var set = {"foo", "bar" , };
 <<<