OLD | NEW |
---|---|
(Empty) | |
1 import 'package:analyzer/dart/ast/ast.dart'; | |
Brian Wilkerson
2017/07/06 18:42:28
Missing copyright.
| |
2 import 'package:analyzer/dart/ast/visitor.dart'; | |
3 import 'package:analyzer/dart/element/element.dart'; | |
4 | |
5 /** | |
6 * Search the [unit] for the [Element]s with the given [name]. | |
7 */ | |
8 List<Element> findElementsByName(CompilationUnit unit, String name) { | |
9 var finder = new _ElementsByNameFinder(name); | |
10 unit.accept(finder); | |
11 return finder.elements; | |
12 } | |
13 | |
14 class _ElementsByNameFinder extends RecursiveAstVisitor<Null> { | |
15 final String name; | |
16 final List<Element> elements = []; | |
17 | |
18 _ElementsByNameFinder(this.name); | |
19 | |
20 @override | |
21 visitSimpleIdentifier(SimpleIdentifier node) { | |
22 if (node.name == name && node.inDeclarationContext()) { | |
23 elements.add(node.staticElement); | |
24 } | |
25 } | |
26 } | |
OLD | NEW |