Revert "Eliminate uses of old AST node types from pkg/analyzer/lib/src/summary"

This reverts commit 0b40a46ab5d8286bc608e60062d2e449b79f628e.

Reason for revert: Broke flutter

Original change's description:
> Eliminate uses of old AST node types from pkg/analyzer/lib/src/summary
> 
> Change-Id: Ida907040d0461d9ae723421eeac71f4e19a8d4b2
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/95284
> Commit-Queue: Paul Berry <paulberry@google.com>
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>

TBR=paulberry@google.com,scheglov@google.com,brianwilkerson@google.com,mfairhurst@google.com

Change-Id: Ie13d23c84ea59c60acf56fd0d73f73c91107f6ed
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96202
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 6bd9085..a22da7a 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -8910,20 +8910,15 @@
   /// Return `true` if the given collection [element] does not contain any
   /// synthetic tokens.
   bool _isComplete(CollectionElement element) {
-    // TODO(paulberry,brianwilkerson): the code below doesn't work because it
-    // assumes access to token offsets, which aren't available when working with
-    // expressions resynthesized from summaries.  For now we just assume the
-    // collection element is complete.
+    Token token = element.beginToken;
+    int endOffset = element.endToken.offset;
+    while (token != null && token.offset <= endOffset) {
+      if (token.isSynthetic) {
+        return false;
+      }
+      token = token.next;
+    }
     return true;
-//    Token token = element.beginToken;
-//    int endOffset = element.endToken.offset;
-//    while (token != null && token.offset <= endOffset) {
-//      if (token.isSynthetic) {
-//        return false;
-//      }
-//      token = token.next;
-//    }
-//    return true;
   }
 }
 
diff --git a/pkg/analyzer/lib/src/summary/expr_builder.dart b/pkg/analyzer/lib/src/summary/expr_builder.dart
index 3733565..3301d95 100644
--- a/pkg/analyzer/lib/src/summary/expr_builder.dart
+++ b/pkg/analyzer/lib/src/summary/expr_builder.dart
@@ -865,7 +865,7 @@
     int count = _uc.ints[intPtr++];
     List<CollectionElement> elements = <CollectionElement>[];
     for (int i = 0; i < count; i++) {
-      elements.insert(0, _popCollectionElement());
+      elements.add(_popCollectionElement());
     }
     DartType staticType;
     if (typeArguments != null && typeArguments.arguments.length == 2) {
diff --git a/pkg/analyzer/lib/src/summary/summarize_const_expr.dart b/pkg/analyzer/lib/src/summary/summarize_const_expr.dart
index 056a4bf..5e93786 100644
--- a/pkg/analyzer/lib/src/summary/summarize_const_expr.dart
+++ b/pkg/analyzer/lib/src/summary/summarize_const_expr.dart
@@ -344,6 +344,14 @@
           typeName.typeArguments != null);
     } else if (expr is ListLiteral) {
       _serializeListLiteral(expr);
+      // ignore: deprecated_member_use_from_same_package
+    } else if (expr is MapLiteral) {
+      // ignore: deprecated_member_use_from_same_package
+      _serializeMapLiteral(expr);
+      // ignore: deprecated_member_use_from_same_package
+    } else if (expr is SetLiteral) {
+      // ignore: deprecated_member_use_from_same_package
+      _serializeSetLiteral(expr);
     } else if (expr is SetOrMapLiteral) {
       _serializeSetOrMapLiteral(expr);
     } else if (expr is MethodInvocation) {
@@ -565,6 +573,27 @@
     }
   }
 
+  @deprecated
+  void _serializeMapLiteral(MapLiteral expr) {
+    if (forConst || expr.typeArguments == null) {
+      for (MapLiteralEntry entry in expr.entries) {
+        _serialize(entry.key);
+        _serialize(entry.value);
+      }
+      ints.add(expr.entries.length);
+    } else {
+      ints.add(0);
+    }
+    if (expr.typeArguments != null &&
+        expr.typeArguments.arguments.length == 2) {
+      references.add(serializeType(expr.typeArguments.arguments[0]));
+      references.add(serializeType(expr.typeArguments.arguments[1]));
+      operations.add(UnlinkedExprOperation.makeTypedMap);
+    } else {
+      operations.add(UnlinkedExprOperation.makeUntypedMap);
+    }
+  }
+
   void _serializeMethodInvocation(MethodInvocation invocation) {
     Expression target = invocation.target;
     SimpleIdentifier methodName = invocation.methodName;
@@ -644,6 +673,24 @@
     }
   }
 
+  @deprecated
+  void _serializeSetLiteral(SetLiteral expr) {
+    if (forConst || expr.typeArguments == null) {
+      List<Expression> elements = expr.elements;
+      elements.forEach(_serialize);
+      ints.add(elements.length);
+    } else {
+      ints.add(0);
+    }
+    if (expr.typeArguments != null &&
+        expr.typeArguments.arguments.length == 1) {
+      references.add(serializeType(expr.typeArguments.arguments[0]));
+      operations.add(UnlinkedExprOperation.makeTypedSet);
+    } else {
+      operations.add(UnlinkedExprOperation.makeUntypedSet);
+    }
+  }
+
   void _serializeSetOrMapLiteral(SetOrMapLiteral expr) {
     if (forConst || expr.typeArguments == null) {
       for (CollectionElement element in expr.elements2) {
diff --git a/pkg/analyzer/test/src/summary/summary_common.dart b/pkg/analyzer/test/src/summary/summary_common.dart
index b45006a..9d73270 100644
--- a/pkg/analyzer/test/src/summary/summary_common.dart
+++ b/pkg/analyzer/test/src/summary/summary_common.dart
@@ -2884,14 +2884,11 @@
         operators: [
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushString,
-          UnlinkedExprOperation.makeMapLiteralEntry,
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushString,
-          UnlinkedExprOperation.makeMapLiteralEntry,
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushString,
-          UnlinkedExprOperation.makeMapLiteralEntry,
-          UnlinkedExprOperation.makeTypedMap2
+          UnlinkedExprOperation.makeTypedMap
         ],
         ints: [
           11,
@@ -2920,14 +2917,11 @@
         operators: [
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushString,
-          UnlinkedExprOperation.makeMapLiteralEntry,
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushString,
-          UnlinkedExprOperation.makeMapLiteralEntry,
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushString,
-          UnlinkedExprOperation.makeMapLiteralEntry,
-          UnlinkedExprOperation.makeTypedMap2
+          UnlinkedExprOperation.makeTypedMap
         ],
         ints: [
           11,
@@ -3084,14 +3078,11 @@
         operators: [
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushString,
-          UnlinkedExprOperation.makeMapLiteralEntry,
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushString,
-          UnlinkedExprOperation.makeMapLiteralEntry,
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushString,
-          UnlinkedExprOperation.makeMapLiteralEntry,
-          UnlinkedExprOperation.makeUntypedSetOrMap
+          UnlinkedExprOperation.makeUntypedMap
         ],
         ints: [
           11,
@@ -3117,7 +3108,7 @@
         UnlinkedExprOperation.pushInt,
         UnlinkedExprOperation.pushInt,
         UnlinkedExprOperation.pushInt,
-        UnlinkedExprOperation.makeUntypedSetOrMap
+        UnlinkedExprOperation.makeUntypedSet
       ],
       ints: [11, 22, 33, 3],
     );
@@ -7392,7 +7383,7 @@
         'var v = <int, String>{11: "aaa", 22: "bbb", 33: "ccc"};');
     assertUnlinkedConst(variable.initializer.bodyExpr,
         '<int, String>{11: "aaa", 22: "bbb", 33: "ccc"}',
-        operators: [UnlinkedExprOperation.makeTypedMap2],
+        operators: [UnlinkedExprOperation.makeTypedMap],
         ints: [0],
         referenceValidators: [
           (EntityRef r) => checkTypeRef(r, 'dart:core', 'int',
@@ -7438,14 +7429,11 @@
         operators: [
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushString,
-          UnlinkedExprOperation.makeMapLiteralEntry,
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushString,
-          UnlinkedExprOperation.makeMapLiteralEntry,
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushString,
-          UnlinkedExprOperation.makeMapLiteralEntry,
-          UnlinkedExprOperation.makeUntypedSetOrMap
+          UnlinkedExprOperation.makeUntypedMap
         ],
         ints: [11, 22, 33, 3],
         strings: ['aaa', 'bbb', 'ccc'],
@@ -7460,7 +7448,7 @@
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushInt,
           UnlinkedExprOperation.pushInt,
-          UnlinkedExprOperation.makeUntypedSetOrMap
+          UnlinkedExprOperation.makeUntypedSet
         ],
         ints: [11, 22, 33, 3],
         forTypeInferenceOnly: true);