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

Unified Diff: pkg/analysis_server/test/abstract_single_unit.dart

Issue 2969343002: Stop depending of visiting LocalVariableElement(s) in Executableelement.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/analysis_server/test/abstract_single_unit.dart
diff --git a/pkg/analysis_server/test/abstract_single_unit.dart b/pkg/analysis_server/test/abstract_single_unit.dart
index 30d66dd50cfa3f44667f78c50b2072368d29126e..86601445dfe60a868d888d618395be6fc09613b6 100644
--- a/pkg/analysis_server/test/abstract_single_unit.dart
+++ b/pkg/analysis_server/test/abstract_single_unit.dart
@@ -5,6 +5,7 @@
import 'dart:async';
import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
@@ -46,6 +47,19 @@ class AbstractSingleUnitTest extends AbstractContextTest {
return findNodeAtString(search, (node) => node is SimpleIdentifier);
}
+ /**
+ * Search the [testUnit] for the [LocalVariableElement] with the given [name].
+ * Fail if there is not exactly one such variable.
+ */
+ LocalVariableElement findLocalVariable(String name) {
+ var finder = new _ElementsByNameFinder(name);
+ testUnit.accept(finder);
+ List<Element> localVariables =
+ finder.elements.where((e) => e is LocalVariableElement).toList();
+ expect(localVariables, hasLength(1));
+ return localVariables[0];
+ }
+
AstNode findNodeAtOffset(int offset, [Predicate<AstNode> predicate]) {
AstNode result = new NodeLocator(offset).searchWithin(testUnit);
if (result != null && predicate != null) {
@@ -114,3 +128,17 @@ class AbstractSingleUnitTest extends AbstractContextTest {
testLibraryElement = testUnitElement.library;
}
}
+
+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);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698