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

Unified Diff: pkg/analyzer/test/utils.dart

Issue 2963313002: Stop using ExecutableElement.localVariables in inference tests. (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « pkg/analyzer/test/src/task/strong/inferred_type_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/utils.dart
diff --git a/pkg/analyzer/test/utils.dart b/pkg/analyzer/test/utils.dart
index 154a266ba20c7a9dbb2e3755ad1a6596af9be815..61697c59d9e4bd0fb3b7024e956be9775ef1a316 100644
--- a/pkg/analyzer/test/utils.dart
+++ b/pkg/analyzer/test/utils.dart
@@ -6,6 +6,7 @@ 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;
@@ -13,6 +14,19 @@ import 'package:front_end/src/base/source.dart';
import 'package:test/test.dart';
/**
+ * 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> localVariables =
+ finder.elements.where((e) => e is LocalVariableElement).toList();
+ expect(localVariables, hasLength(1));
+ return localVariables[0];
+}
+
+/**
* The type of an assertion which asserts properties of [T]s.
*/
typedef void Asserter<T>(T type);
@@ -310,3 +324,17 @@ 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);
+ }
+ }
+}
« no previous file with comments | « pkg/analyzer/test/src/task/strong/inferred_type_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698