anchor.diff:      expect(unit.directives[2].metadata.single.name.name, 'b');
     }
   
  -  test_metadata_simpleFormalParameter() async {
  +  test_simpleFormalParameter() async {
       await setupCode('f(@a x) {}) {}');
       checkMetadata('x');
     }
   
  -  test_metadata_simpleFormalParameter_withDefault() async {
  +  test_simpleFormalParameter_withDefault() async {
       await setupCode('f([@a x = null]) {}');
       checkMetadata('x');
     }
   
  -  test_metadata_topLevelVariableDeclaration() async {
  +  test_topLevelVariableDeclaration() async {
       await setupCode('@a int x;');
       checkMetadata('x');
     }
   
  -  test_metadata_typeParameter_ofClass() async {
  +  test_typeParameter_ofClass() async {
       await setupCode('class C<@a T> {}');
       checkMetadata('T');
     }
   
  -  test_metadata_typeParameter_ofClassTypeAlias() async {
  +  test_typeParameter_ofClassTypeAlias() async {
       await setupCode('class C<@a T> = D with E; class D {} class E {}');
       checkMetadata('T');
     }
   
  -  test_metadata_typeParameter_ofFunction() async {
  +  test_typeParameter_ofFunction() async {
       await setupCode('f<@a T>() {}');
       checkMetadata('T');
     }
   
  -  test_metadata_typeParameter_ofTypedef() async {
  +  test_typeParameter_ofTypedef() async {
       await setupCode('typedef F<@a T>();');
       checkMetadata('T');
     }
  
positive.code:     String code = r'''
  var v = <Function(int)>[];
  ''';
      CompilationUnit unit = await resolveSource(code);
      CompilationUnit newUnit = _cloneResolveUnit(unit);
      var v = newUnit.declarations[0] as TopLevelVariableDeclaration;
      var initializer = v.variables.variables[0].initializer as ListLiteral;
      expect(initializer.typeArguments.arguments[0].type, isNotNull);
    }
  
    test_genericFunction_invalid_missingParameterName() async {
      String code = r'''
  typedef F = Function({int});
  ''';
      CompilationUnit unit = await resolveSource(code);
      _cloneResolveUnit(unit);
      // no other validations than built into DeclarationResolver
    }
  
    test_invalid_functionDeclaration_getter_inFunction() async {
      String code = r'''
  var v = (() {
    main() {
      int get zzz => 42;
    }
  });
  ''';
      CompilationUnit unit = await resolveSource(code);
      // re-resolve
      CompilationUnit unit2 = _cloneResolveUnit(unit);
      SimpleIdentifier getterName = _findSimpleIdentifier(unit2, code, 'zzz =>');
      // Local getters are not allowed, so a FunctionElement is created.
      expect(getterName.staticElement, new TypeMatcher<FunctionElement>());
    }
  
    test_invalid_functionDeclaration_setter_inFunction() async {
      String code = r'''
  var v = (() {
    main() {
      set zzz(x) {}
    }
  });
  ''';
      CompilationUnit unit = await resolveSource(code);
      // re-resolve
      CompilationUnit unit2 = _cloneResolveUnit(unit);
      SimpleIdentifier setterName = _findSimpleIdentifier(unit2, code, 'zzz(x)');
      // Local getters are not allowed, so a FunctionElement is created.
      expect(setterName.staticElement, new TypeMatcher<FunctionElement>());
    }
  
    test_visitExportDirective_notExistingSource() async {
      String code = r'''
  export 'foo.dart';
  ''';
      CompilationUnit unit = await resolveSource(code);
      // re-resolve
      _cloneResolveUnit(unit);
      // no other validations than built into DeclarationResolver
    }
  
    test_visitExportDirective_unresolvedUri() async {
      String code = r'''
  export 'package:foo/bar.dart';
  ''';
      CompilationUnit unit = await resolveSource(code);
      // re-resolve
      _cloneResolveUnit(unit);
      // no other validations than built into DeclarationResolver
    }
  
    test_visitFunctionExpression() async {
      String code = r'''
  main(List<String> items) {
    items.forEach((item) {});
  }
  ''';
      CompilationUnit unit = await resolveSource(code);
      // re-resolve
      _cloneResolveUnit(unit);
      // no other validations than built into DeclarationResolver
    }
  
    test_visitGenericTypeAlias_0() async {
      String code = r'''
  typedef F<T> = Function<S>(List<S> list, Function<A>(A), T);
  ''';
      CompilationUnit unit = await resolveSource(code);
      // re-resolve
      _cloneResolveUnit(unit);
      // no other validations than built into DeclarationResolver
    }
  
    test_visitGenericTypeAlias_1() async {
      String code = r'''
  typedef F = Function({int});
  ''';
      CompilationUnit unit = await resolveSource(code);
      // re-resolve
      _cloneResolveUnit(unit);
      // no other validations than built into DeclarationResolver
    }
  
    test_visitGenericTypeAlias_2() async {
      String code = r'''
  typedef F = int;
  ''';
      CompilationUnit unit = await resolveSource(code);
      // re-resolve
      _cloneResolveUnit(unit);
      // no other validations than built into DeclarationResolver
    }
  
    test_visitImportDirective_notExistingSource() async {
      String code = r'''
  import 'foo.dart';
  ''';
      CompilationUnit unit = await resolveSource(code);
      // re-resolve
      _cloneResolveUnit(unit);
      // no other validations than built into DeclarationResolver
    }
  
    test_visitImportDirective_unresolvedUri() async {
      String code = r'''
  import 'package:foo/bar.dart';
  ''';
      CompilationUnit unit = await resolveSource(code);
      // re-resolve
      _cloneResolveUnit(unit);
      // no other validations than built into DeclarationResolver
    }
  
    test_visitMethodDeclaration_getter_duplicate() async {
      String code = r'''
  class C {
    int get zzz => 1;
    String get zzz => null;
  }
  ''';
      CompilationUnit unit = await resolveSource(code);
      PropertyAccessorElement firstElement =
          _findSimpleIdentifier(unit, code, 'zzz => 1').staticElement;
      PropertyAccessorElement secondElement =
          _findSimpleIdentifier(unit, code, 'zzz => null').staticElement;
      // re-resolve
      CompilationUnit unit2 = _cloneResolveUnit(unit);
      SimpleIdentifier firstName = _findSimpleIdentifier(unit2, code, 'zzz => 1');
      SimpleIdentifier secondName =
          _findSimpleIdentifier(unit2, code, 'zzz => null');
      expect(firstName.staticElement, same(firstElement));
      expect(secondName.staticElement, same(secondElement));
    }
  
    test_visitMethodDeclaration_getterSetter() async {
      String code = r'''
  class C {
    int _field = 0;
    int get field => _field;
    void set field(value) {_field = value;}
  }
  ''';
      CompilationUnit unit = await resolveSource(code);
      FieldElement getterElement =
          _findSimpleIdentifier(unit, code, 'field =').staticElement;
      PropertyAccessorElement setterElement =
          _findSimpleIdentifier(unit, code, 'field(').staticElement;
      // re-resolve
      CompilationUnit unit2 = _cloneResolveUnit(unit);
      SimpleIdentifier getterName = _findSimpleIdentifier(unit2, code, 'field =');
      SimpleIdentifier setterName = _findSimpleIdentifier(unit2, code, 'field(');
      expect(getterName.staticElement, same(getterElement));
      expect(setterName.staticElement, same(setterElement));
    }
  
    test_visitMethodDeclaration_method_duplicate() async {
      String code = r'''
  class C {
    void zzz(x) {}
    void zzz(y) {}
  }
  ''';
      CompilationUnit unit = await resolveSource(code);
      MethodElement firstElement =
          _findSimpleIdentifier(unit, code, 'zzz(x)').staticElement;
      MethodElement secondElement =
          _findSimpleIdentifier(unit, code, 'zzz(y)').staticElement;
      // re-resolve
      CompilationUnit unit2 = _cloneResolveUnit(unit);
      SimpleIdentifier firstName = _findSimpleIdentifier(unit2, code, 'zzz(x)');
      SimpleIdentifier secondName = _findSimpleIdentifier(unit2, code, 'zzz(y)');
      expect(firstName.staticElement, same(firstElement));
      expect(secondName.staticElement, same(secondElement));
    }
  
    test_visitMethodDeclaration_setter_duplicate() async {
      // https://github.com/dart-lang/sdk/issues/25601
      String code = r'''
  class C {
    set zzz(x) {}
    set zzz(y) {}
  }
  ''';
      CompilationUnit unit = await resolveSource(code);
      PropertyAccessorElement firstElement =
          _findSimpleIdentifier(unit, code, 'zzz(x)').staticElement;
      PropertyAccessorElement secondElement =
          _findSimpleIdentifier(unit, code, 'zzz(y)').staticElement;
      // re-resolve
      CompilationUnit unit2 = _cloneResolveUnit(unit);
      SimpleIdentifier firstName = _findSimpleIdentifier(unit2, code, 'zzz(x)');
      SimpleIdentifier secondName = _findSimpleIdentifier(unit2, code, 'zzz(y)');
      expect(firstName.staticElement, same(firstElement));
      expect(secondName.staticElement, same(secondElement));
    }
  
    test_visitMethodDeclaration_unaryMinus() async {
      String code = r'''
  class C {
    C operator -() => null;
    C operator -(C other) => null;
  }
  ''';
      CompilationUnit unit = await resolveSource(code);
      // re-resolve
      _cloneResolveUnit(unit);
      // no other validations than built into DeclarationResolver
    }
  
    test_visitPartDirective_notExistingSource() async {
      String code = r'''
  part 'foo.bar';
  ''';
      CompilationUnit unit = await resolveSource(code);
      // re-resolve
      _cloneResolveUnit(unit);
      // no other validations than built into DeclarationResolver
    }
  }
  
  /**
   * Strong mode DeclarationResolver tests
   * TODO(paulberry): migrate this test away from the task model.
   * See dartbug.com/35734.
   */
  @reflectiveTest
  class StrongModeDeclarationResolverTest extends ResolverTestCase {
    @override
    void setUp() {
      reset();
    }
  
    test_genericFunction_typeParameter() async {
      // Fasta ignores generic type comments
      if (usingFastaParser) return;
      String code = r'''
  /*=T*/ max/*<T>*/(/*=T*/ x, /*=T*/ y) => null;
  ''';
      CompilationUnit unit = await resolveSource(code);
      FunctionDeclaration node = _findSimpleIdentifier(unit, code, 'max').parent;
      TypeParameter t = node.functionExpression.typeParameters.typeParameters[0];
  
      FunctionElement element = node.name.staticElement;
      TypeParameterElement tElement = element.typeParameters[0];
      expect(tElement, isNotNull);
      expect(element.typeParameters.toString(), "[T]");
      expect(element.type.toString(), "<T>(T, T) → T");
      expect(t.declaredElement, same(tElement));
  
      // re-resolve
      CompilationUnit unit2 = _cloneResolveUnit(unit);
      node = _findSimpleIdentifier(unit2, code, 'max').parent;
      t = node.functionExpression.typeParameters.typeParameters[0];
      expect(t.declaredElement, same(tElement));
    }
  
    test_genericMethod_typeParameter() async {
      // Fasta ignores generic type comments
      if (usingFastaParser) return;
      String code = r'''
  class C {
    /*=T*/ max/*<T>*/(/*=T*/ x, /*=T*/ y) => null;
  }
  ''';
      CompilationUnit unit = await resolveSource(code);
      MethodDeclaration node = _findSimpleIdentifier(unit, code, 'max').parent;
      TypeParameter t = node.typeParameters.typeParameters[0];
  
      MethodElement element = node.name.staticElement;
      TypeParameterElement tElement = element.typeParameters[0];
      expect(tElement, isNotNull);
      expect(element.typeParameters.toString(), "[T]");
      expect(element.type.toString(), "<T>(T, T) → T");
      expect(t.declaredElement, same(tElement));
  
      // re-resolve
      CompilationUnit unit2 = _cloneResolveUnit(unit);
      node = _findSimpleIdentifier(unit2, code, 'max').parent;
      t = node.typeParameters.typeParameters[0];
      expect(t.declaredElement, same(tElement));
    }
  }
  
negative.code:     expect(unit.directives[1].metadata.single.name.name, 'b');
    }
  
    test_libraryDirective() async {
      await setupCode('@a library L;');
      checkMetadata('L');
    }
  
    test_libraryDirective_resynthesized() async {
      addTestFile('@a library L; const a = null;');
      await resolveTestFile();
      unit = result.unit;
  
      expect(unit.directives.single.metadata.single.name.name, 'a');
      var unitElement = unit.declaredElement as CompilationUnitElementImpl;
  
      // Damage the unit element - as if "setAnnotations" were not called.
      // The LibraryElement still has the metadata, we should use it.
      unitElement.setAnnotations(unit.directives.single.offset, []);
      expect(unitElement.library.metadata, hasLength(1));
  
      // DeclarationResolver on the clone should succeed.
      CompilationUnit clonedUnit = AstCloner.clone(unit);
      new DeclarationResolver().resolve(clonedUnit, unit.declaredElement);
      expect(clonedUnit.directives.single.metadata.single.name.name, 'a');
    }
  
    test_localFunctionDeclaration() async {
      await setupCode('f() { @a g() {} }');
      // Note: metadata on local function declarations is ignored by the
      // analyzer.  TODO(paulberry): is this a bug?
      FunctionDeclaration node = EngineTestCase.findNode(
          unit, code, 'g', (AstNode n) => n is FunctionDeclaration);
      NodeList<Annotation> metadata = (node as FunctionDeclarationImpl).metadata;
      if (Parser.useFasta) {
        expect(metadata, hasLength(1));
      } else {
        expect(metadata, isEmpty);
      }
    }
  
    test_localVariableDeclaration() async {
      await setupCode('f() { @a int x; }');
      checkMetadata('x', expectDifferent: true);
    }
  
    test_methodDeclaration_getter() async {
      await setupCode('class C { @a get m => null; }');
      checkMetadata('m');
    }
  
    test_methodDeclaration_method() async {
      await setupCode('class C { @a m() {} }');
      checkMetadata('m');
    }
  
    test_methodDeclaration_setter() async {
      await setupCode('class C { @a set m(value) {} }');
      checkMetadata('m');
    }
  
    test_partDirective() async {
      newFile('/test/lib/foo.dart', content: 'part of L;');
      await setupCode('library L; @a part "foo.dart";');
      checkMetadata('part');
    }
  
    test_partDirective_resynthesized() async {
      newFile('/test/lib/part_a.dart', content: 'part of L;');
      newFile('/test/lib/part_b.dart', content: 'part of L;');
  
      addTestFile(r'''
  library L;
  
  @a
  