Index: pkg/analyzer/lib/src/generated/testing/element_search.dart |
diff --git a/pkg/analyzer/lib/src/generated/testing/element_search.dart b/pkg/analyzer/lib/src/generated/testing/element_search.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d9a5cb2ae574e7590853c09bc6764b9fb9ee519d |
--- /dev/null |
+++ b/pkg/analyzer/lib/src/generated/testing/element_search.dart |
@@ -0,0 +1,26 @@ |
+import 'package:analyzer/dart/ast/ast.dart'; |
Brian Wilkerson
2017/07/06 18:42:28
Missing copyright.
|
+import 'package:analyzer/dart/ast/visitor.dart'; |
+import 'package:analyzer/dart/element/element.dart'; |
+ |
+/** |
+ * Search the [unit] for the [Element]s with the given [name]. |
+ */ |
+List<Element> findElementsByName(CompilationUnit unit, String name) { |
+ var finder = new _ElementsByNameFinder(name); |
+ unit.accept(finder); |
+ return finder.elements; |
+} |
+ |
+class _ElementsByNameFinder extends RecursiveAstVisitor<Null> { |
+ final String name; |
+ final List<Element> elements = []; |
+ |
+ _ElementsByNameFinder(this.name); |
+ |
+ @override |
+ visitSimpleIdentifier(SimpleIdentifier node) { |
+ if (node.name == name && node.inDeclarationContext()) { |
+ elements.add(node.staticElement); |
+ } |
+ } |
+} |