anchor.diff:      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;
  +    addTestFile(code);
  +    await resolveTestFile();
  +
  +    var newUnit = _cloneResolveUnit(result.unit);
  +    var initializer = FindNode(result.content, newUnit).listLiteral('>[]');
       expect(initializer.typeArguments.arguments[0].type, isNotNull);
     }
   
     test_genericFunction_invalid_missingParameterName() async {
  -    String code = r'''
  +    addTestFile(r'''
   typedef F = Function({int});
  -''';
  -    CompilationUnit unit = await resolveSource(code);
  -    _cloneResolveUnit(unit);
  +''');
  +    await resolveTestFile();
  +    // re-resolve
  +    _cloneResolveUnit(result.unit);
       // no other validations than built into DeclarationResolver
     }
   
     test_invalid_functionDeclaration_getter_inFunction() async {
  -    String code = r'''
  +    addTestFile(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 =>');
  +''');
  +    await resolveTestFile();
  +
  +    // re-resolve
  +    var unit2 = _cloneResolveUnit(result.unit);
  +    var getterName = FindNode(result.content, unit2).simple('zzz =>');
  +
       // Local getters are not allowed, so a FunctionElement is created.
  -    expect(getterName.staticElement, new TypeMatcher<FunctionElement>());
  +    expect(getterName.staticElement, isFunctionElement);
     }
   
     test_invalid_functionDeclaration_setter_inFunction() async {
  -    String code = r'''
  +    addTestFile(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)');
  +''');
  +    await resolveTestFile();
  +
  +    // re-resolve
  +    var unit2 = _cloneResolveUnit(result.unit);
  +    var setterName = FindNode(result.content, unit2).simple('zzz(x)');
  +
       // Local getters are not allowed, so a FunctionElement is created.
  -    expect(setterName.staticElement, new TypeMatcher<FunctionElement>());
  +    expect(setterName.staticElement, isFunctionElement);
     }
   
     test_visitExportDirective_notExistingSource() async {
  -    String code = r'''
  +    addTestFile(r'''
   export 'foo.dart';
  -''';
  -    CompilationUnit unit = await resolveSource(code);
  -    // re-resolve
  -    _cloneResolveUnit(unit);
  +''');
  +    await resolveTestFile();
  +    // re-resolve
  +    _cloneResolveUnit(result.unit);
       // no other validations than built into DeclarationResolver
     }
   
     test_visitExportDirective_unresolvedUri() async {
  -    String code = r'''
  +    addTestFile(r'''
   export 'package:foo/bar.dart';
  -''';
  -    CompilationUnit unit = await resolveSource(code);
  -    // re-resolve
  -    _cloneResolveUnit(unit);
  +''');
  +    await resolveTestFile();
  +    // re-resolve
  +    _cloneResolveUnit(result.unit);
       // no other validations than built into DeclarationResolver
     }
   
     test_visitFunctionExpression() async {
  -    String code = r'''
  +    addTestFile(r'''
   main(List<String> items) {
     items.forEach((item) {});
   }
  -''';
  -    CompilationUnit unit = await resolveSource(code);
  -    // re-resolve
  -    _cloneResolveUnit(unit);
  +''');
  +    await resolveTestFile();
  +    // re-resolve
  +    _cloneResolveUnit(result.unit);
       // no other validations than built into DeclarationResolver
     }
   
     test_visitGenericTypeAlias_0() async {
  -    String code = r'''
  +    addTestFile(r'''
   typedef F<T> = Function<S>(List<S> list, Function<A>(A), T);
  -''';
  -    CompilationUnit unit = await resolveSource(code);
  -    // re-resolve
  -    _cloneResolveUnit(unit);
  +''');
  +    await resolveTestFile();
  +    // re-resolve
  +    _cloneResolveUnit(result.unit);
       // no other validations than built into DeclarationResolver
     }
   
     test_visitGenericTypeAlias_1() async {
  -    String code = r'''
  +    addTestFile(r'''
   typedef F = Function({int});
  -''';
  -    CompilationUnit unit = await resolveSource(code);
  -    // re-resolve
  -    _cloneResolveUnit(unit);
  +''');
  +    await resolveTestFile();
  +    // re-resolve
  +    _cloneResolveUnit(result.unit);
       // no other validations than built into DeclarationResolver
     }
   
     test_visitGenericTypeAlias_2() async {
  -    String code = r'''
  +    addTestFile(r'''
   typedef F = int;
  -''';
  -    CompilationUnit unit = await resolveSource(code);
  -    // re-resolve
  -    _cloneResolveUnit(unit);
  +''');
  +    await resolveTestFile();
  +    // re-resolve
  +    _cloneResolveUnit(result.unit);
       // no other validations than built into DeclarationResolver
     }
   
     test_visitImportDirective_notExistingSource() async {
  -    String code = r'''
  +    addTestFile(r'''
   import 'foo.dart';
  -''';
  -    CompilationUnit unit = await resolveSource(code);
  -    // re-resolve
  -    _cloneResolveUnit(unit);
  +''');
  +    await resolveTestFile();
  +    // re-resolve
  +    _cloneResolveUnit(result.unit);
       // no other validations than built into DeclarationResolver
     }
   
     test_visitImportDirective_unresolvedUri() async {
  -    String code = r'''
  +    addTestFile(r'''
   import 'package:foo/bar.dart';
  -''';
  -    CompilationUnit unit = await resolveSource(code);
  -    // re-resolve
  -    _cloneResolveUnit(unit);
  +''');
  +    await resolveTestFile();
  +    // re-resolve
  +    _cloneResolveUnit(result.unit);
       // no other validations than built into DeclarationResolver
     }
   
     test_visitMethodDeclaration_getter_duplicate() async {
  -    String code = r'''
  +    addTestFile(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');
  +''');
  +    await resolveTestFile();
  +
  +    var firstElement = findNode.simple('zzz => 1').staticElement;
  +    var secondElement = findNode.simple('zzz => null').staticElement;
  +    expect(firstElement, isNot(same(secondElement)));
  +
  +    // re-resolve
  +    var unit2 = _cloneResolveUnit(result.unit);
  +    var findNode2 = FindNode(result.content, unit2);
  +    var firstName = findNode2.simple('zzz => 1');
  +    var secondName = findNode2.simple('zzz => null');
       expect(firstName.staticElement, same(firstElement));
       expect(secondName.staticElement, same(secondElement));
     }
   
     test_visitMethodDeclaration_getterSetter() async {
  -    String code = r'''
  +    addTestFile(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(');
  +''');
  +    await resolveTestFile();
  +
  +    var getterElement = findElement.getter('field');
  +    var setterElement = findElement.setter('field');
  +
  +    // re-resolve
  +    var unit2 = _cloneResolveUnit(result.unit);
  +    var findNode2 = FindNode(result.content, unit2);
  +    var getterName = findNode2.simple('field =>');
  +    var setterName = findNode2.simple('field(value)');
       expect(getterName.staticElement, same(getterElement));
       expect(setterName.staticElement, same(setterElement));
     }
   
     test_visitMethodDeclaration_method_duplicate() async {
  -    String code = r'''
  +    addTestFile(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)');
  +''');
  +    await resolveTestFile();
  +
  +    MethodElement firstElement = findNode.simple('zzz(x)').staticElement;
  +    MethodElement secondElement = findNode.simple('zzz(y)').staticElement;
  +    expect(firstElement, isNot(same(secondElement)));
  +
  +    // re-resolve
  +    var unit2 = _cloneResolveUnit(result.unit);
  +    var findNode2 = FindNode(result.content, unit2);
  +    var firstName = findNode2.simple('zzz(x)');
  +    var secondName = findNode2.simple('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'''
  +    addTestFile(r'''
   class C {
     set zzz(x) {}
     set zzz(y) {}
   }
  -''';
  -    CompilationUnit unit = await resolveSource(code);
  +''');
  +    await resolveTestFile();
  +
       PropertyAccessorElement firstElement =
  -        _findSimpleIdentifier(unit, code, 'zzz(x)').staticElement;
  +        findNode.simple('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)');
  +        findNode.simple('zzz(y)').staticElement;
  +    expect(firstElement, isNot(same(secondElement)));
  +
  +    // re-resolve
  +    var unit2 = _cloneResolveUnit(result.unit);
  +    var findNode2 = FindNode(result.content, unit2);
  +    var firstName = findNode2.simple('zzz(x)');
  +    var secondName = findNode2.simple('zzz(y)');
       expect(firstName.staticElement, same(firstElement));
       expect(secondName.staticElement, same(secondElement));
     }
   
     test_visitMethodDeclaration_unaryMinus() async {
  -    String code = r'''
  +    addTestFile(r'''
   class C {
     C operator -() => null;
     C operator -(C other) => null;
   }
  -''';
  -    CompilationUnit unit = await resolveSource(code);
  -    // re-resolve
  -    _cloneResolveUnit(unit);
  +''');
  +    await resolveTestFile();
  +    // re-resolve
  +    _cloneResolveUnit(result.unit);
       // no other validations than built into DeclarationResolver
     }
   
     test_visitPartDirective_notExistingSource() async {
  -    String code = r'''
  +    addTestFile(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));
  -  }
  -}
  +''');
  +    await resolveTestFile();
  +    // re-resolve
  +    _cloneResolveUnit(result.unit);
  +    // no other validations than built into DeclarationResolver
  +  }
  +}
  
positive.code: const a = null;
  const b = null;
  ''');
      expect(unit.directives[0].metadata.single.name.name, 'a');
      expect(unit.directives[1].metadata.single.name.name, 'b');
      var unitElement = unit.declaredElement as CompilationUnitElementImpl;
      // Damage the unit element - as if "setAnnotations" were not called.
      // The ImportElement(s) still have the metadata, we should use it.
      unitElement.setAnnotations(unit.directives[0].offset, []);
      unitElement.setAnnotations(unit.directives[1].offset, []);
      expect(unitElement.library.imports[0].metadata, hasLength(1));
      expect(unitElement.library.imports[1].metadata, hasLength(1));
      // DeclarationResolver on the clone should succeed.
      CompilationUnit clonedUnit = AstCloner.clone(unit);
      new DeclarationResolver().resolve(clonedUnit, unit.declaredElement);
  
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
  