| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.utils; | 5 library analyzer.test.utils; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/resolution_accessors.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| 10 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 11 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
| 12 import 'package:front_end/src/base/source.dart'; |
| 11 import 'package:test/test.dart'; | 13 import 'package:test/test.dart'; |
| 12 | 14 |
| 13 /** | 15 /** |
| 14 * The type of an assertion which asserts properties of [T]s. | 16 * The type of an assertion which asserts properties of [T]s. |
| 15 */ | 17 */ |
| 16 typedef void Asserter<T>(T type); | 18 typedef void Asserter<T>(T type); |
| 17 | 19 |
| 18 /** | 20 /** |
| 19 * The type of a function which given an [S], builds an assertion over [T]s. | 21 * The type of a function which given an [S], builds an assertion over [T]s. |
| 20 */ | 22 */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 38 * Return the declaration of the class with the given [className] in the given | 40 * Return the declaration of the class with the given [className] in the given |
| 39 * compilation [unit]. | 41 * compilation [unit]. |
| 40 */ | 42 */ |
| 41 static ClassDeclaration getClass(CompilationUnit unit, String className) { | 43 static ClassDeclaration getClass(CompilationUnit unit, String className) { |
| 42 NodeList<CompilationUnitMember> unitMembers = unit.declarations; | 44 NodeList<CompilationUnitMember> unitMembers = unit.declarations; |
| 43 for (CompilationUnitMember unitMember in unitMembers) { | 45 for (CompilationUnitMember unitMember in unitMembers) { |
| 44 if (unitMember is ClassDeclaration && unitMember.name.name == className) { | 46 if (unitMember is ClassDeclaration && unitMember.name.name == className) { |
| 45 return unitMember; | 47 return unitMember; |
| 46 } | 48 } |
| 47 } | 49 } |
| 48 fail('No class named $className in ${unit.element.source}'); | 50 Source source = elementForCompilationUnit(unit).source; |
| 51 fail('No class named $className in $source'); |
| 49 return null; | 52 return null; |
| 50 } | 53 } |
| 51 | 54 |
| 52 /** | 55 /** |
| 53 * Return the declaration of the constructor with the given [constructorName]
in | 56 * Return the declaration of the constructor with the given [constructorName]
in |
| 54 * the class with the given [className] in the given compilation [unit]. If | 57 * the class with the given [className] in the given compilation [unit]. If |
| 55 * constructorName is null, return the default constructor; | 58 * constructorName is null, return the default constructor; |
| 56 */ | 59 */ |
| 57 static ConstructorDeclaration getConstructorInClass( | 60 static ConstructorDeclaration getConstructorInClass( |
| 58 CompilationUnit unit, String className, String constructorName) { | 61 CompilationUnit unit, String className, String constructorName) { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 Asserter<DartType> isType(DartType argument) => (DartType t) { | 291 Asserter<DartType> isType(DartType argument) => (DartType t) { |
| 289 expect(t, same(argument)); | 292 expect(t, same(argument)); |
| 290 }; | 293 }; |
| 291 | 294 |
| 292 /** | 295 /** |
| 293 * Given a type, produce an assertion that a type has the same element. | 296 * Given a type, produce an assertion that a type has the same element. |
| 294 */ | 297 */ |
| 295 Asserter<DartType> sameElement(DartType elementType) => | 298 Asserter<DartType> sameElement(DartType elementType) => |
| 296 hasElement(elementType.element); | 299 hasElement(elementType.element); |
| 297 } | 300 } |
| OLD | NEW |