Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: pkg/analyzer/lib/src/generated/testing/element_search.dart

Issue 2965133003: Move findElementsByName() into shared analyzer/element_search.dart file. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
+ }
+ }
+}
« no previous file with comments | « pkg/analysis_server/test/plugin/protocol_dart_test.dart ('k') | pkg/analyzer/test/src/dart/analysis/search_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698