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

Unified Diff: pkg/analyzer_plugin/test/support/abstract_context.dart

Issue 2973093002: Stop depending on LabelElement(s) to be reported in visitChildren(). (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_plugin/test/support/abstract_context.dart
diff --git a/pkg/analyzer_plugin/test/support/abstract_context.dart b/pkg/analyzer_plugin/test/support/abstract_context.dart
index e124c3309bbf00144b464482ce6be7ba00dc515a..0dd6652b24282a1ffad220f5e280f4280c0d86d8 100644
--- a/pkg/analyzer_plugin/test/support/abstract_context.dart
+++ b/pkg/analyzer_plugin/test/support/abstract_context.dart
@@ -6,6 +6,7 @@ import 'dart:async';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/visitor.dart';
import 'package:analyzer/exception/exception.dart';
@@ -41,6 +42,15 @@ Element findChildElement(Element root, String name, [ElementKind kind]) {
}
/**
+ * Search the [unit] for the [Element]s with the given [name].
+ */
+List<Element> findElementsByName(CompilationUnit unit, String name) {
Brian Wilkerson 2017/07/06 18:19:18 Can we use the copy in pkg/analyzer/test/utils.dar
+ var finder = new _ElementsByNameFinder(name);
+ unit.accept(finder);
+ return finder.elements;
+}
+
+/**
* A function to be called for every [Element].
*/
typedef void _ElementVisitorFunction(Element element);
@@ -99,7 +109,9 @@ class Required {
Element findElementInUnit(CompilationUnit unit, String name,
[ElementKind kind]) {
- return findChildElement(unit.element, name, kind);
+ return findElementsByName(unit, name)
+ .where((e) => kind == null || e.kind == kind)
+ .single;
}
File newFile(String path, [String content]) =>
@@ -177,6 +189,20 @@ class PrintLogger implements Logger {
}
}
+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);
+ }
+ }
+}
+
/**
* Wraps the given [_ElementVisitorFunction] into an instance of
* [engine.GeneralizingElementVisitor].

Powered by Google App Engine
This is Rietveld 408576698