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/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
11 import 'package:analyzer/dart/element/type.dart'; | 11 import 'package:analyzer/dart/element/type.dart'; |
12 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 12 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
13 import 'package:front_end/src/base/source.dart'; | 13 import 'package:front_end/src/base/source.dart'; |
14 import 'package:test/test.dart'; | 14 import 'package:test/test.dart'; |
15 | 15 |
16 /** | 16 /** |
| 17 * Search the [unit] for the [Element]s with the given [name]. |
| 18 */ |
| 19 List<Element> findElementsByName(CompilationUnit unit, String name) { |
| 20 var finder = new _ElementsByNameFinder(name); |
| 21 unit.accept(finder); |
| 22 return finder.elements; |
| 23 } |
| 24 |
| 25 /** |
17 * Search the [unit] for the [LocalVariableElement] with the given [name]. | 26 * Search the [unit] for the [LocalVariableElement] with the given [name]. |
18 * Fail if there is not exactly one such variable. | 27 * Fail if there is not exactly one such variable. |
19 */ | 28 */ |
20 LocalVariableElement findLocalVariable(CompilationUnit unit, String name) { | 29 LocalVariableElement findLocalVariable(CompilationUnit unit, String name) { |
21 var finder = new _ElementsByNameFinder(name); | 30 var finder = new _ElementsByNameFinder(name); |
22 unit.accept(finder); | 31 unit.accept(finder); |
23 List<Element> localVariables = | 32 List<Element> localVariables = |
24 finder.elements.where((e) => e is LocalVariableElement).toList(); | 33 finder.elements.where((e) => e is LocalVariableElement).toList(); |
25 expect(localVariables, hasLength(1)); | 34 expect(localVariables, hasLength(1)); |
26 return localVariables[0]; | 35 return localVariables[0]; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 340 |
332 _ElementsByNameFinder(this.name); | 341 _ElementsByNameFinder(this.name); |
333 | 342 |
334 @override | 343 @override |
335 visitSimpleIdentifier(SimpleIdentifier node) { | 344 visitSimpleIdentifier(SimpleIdentifier node) { |
336 if (node.name == name && node.inDeclarationContext()) { | 345 if (node.name == name && node.inDeclarationContext()) { |
337 elements.add(node.staticElement); | 346 elements.add(node.staticElement); |
338 } | 347 } |
339 } | 348 } |
340 } | 349 } |
OLD | NEW |