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

Unified Diff: pkg/analyzer/test/utils.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/test/utils.dart
diff --git a/pkg/analyzer/test/utils.dart b/pkg/analyzer/test/utils.dart
index 3a2e229692c6f1d8e716c7a894b9b4a5db6c5a8e..ed733b81e5c6fc9e707cdae9701ebf78c5bec4d0 100644
--- a/pkg/analyzer/test/utils.dart
+++ b/pkg/analyzer/test/utils.dart
@@ -6,31 +6,21 @@ library analyzer.test.utils;
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/standard_resolution_map.dart';
-import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/generated/resolver.dart' show TypeProvider;
+import 'package:analyzer/src/generated/testing/element_search.dart';
import 'package:front_end/src/base/source.dart';
import 'package:test/test.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;
-}
-
-/**
* Search the [unit] for the [LocalVariableElement] with the given [name].
* Fail if there is not exactly one such variable.
*/
LocalVariableElement findLocalVariable(CompilationUnit unit, String name) {
- var finder = new _ElementsByNameFinder(name);
- unit.accept(finder);
+ List<Element> elements = findElementsByName(unit, name);
List<Element> localVariables =
- finder.elements.where((e) => e is LocalVariableElement).toList();
+ elements.where((e) => e is LocalVariableElement).toList();
expect(localVariables, hasLength(1));
return localVariables[0];
}
@@ -333,17 +323,3 @@ class TypeAssertions {
expect(t, expected);
};
}
-
-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