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

Side by Side Diff: pkg/analyzer/test/utils.dart

Issue 2963313002: Stop using ExecutableElement.localVariables in inference tests. (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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.utils; 5 library analyzer.test.utils;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
9 import 'package:analyzer/dart/ast/visitor.dart';
9 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 11 import 'package:analyzer/dart/element/type.dart';
11 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; 12 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider;
12 import 'package:front_end/src/base/source.dart'; 13 import 'package:front_end/src/base/source.dart';
13 import 'package:test/test.dart'; 14 import 'package:test/test.dart';
14 15
15 /** 16 /**
17 * Search the [unit] for the [LocalVariableElement] with the given [name].
18 * Fail if there is not exactly one such variable.
19 */
20 LocalVariableElement findLocalVariable(CompilationUnit unit, String name) {
21 var finder = new _ElementsByNameFinder(name);
22 unit.accept(finder);
23 List<Element> localVariables =
24 finder.elements.where((e) => e is LocalVariableElement).toList();
25 expect(localVariables, hasLength(1));
26 return localVariables[0];
27 }
28
29 /**
16 * The type of an assertion which asserts properties of [T]s. 30 * The type of an assertion which asserts properties of [T]s.
17 */ 31 */
18 typedef void Asserter<T>(T type); 32 typedef void Asserter<T>(T type);
19 33
20 /** 34 /**
21 * The type of a function which given an [S], builds an assertion over [T]s. 35 * The type of a function which given an [S], builds an assertion over [T]s.
22 */ 36 */
23 typedef Asserter<T> AsserterBuilder<S, T>(S arg); 37 typedef Asserter<T> AsserterBuilder<S, T>(S arg);
24 38
25 /** 39 /**
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 Asserter<DartType> argAssert0, Asserter<DartType> argAssert1) => 317 Asserter<DartType> argAssert0, Asserter<DartType> argAssert1) =>
304 isInstantiationOf(isMap)([argAssert0, argAssert1]); 318 isInstantiationOf(isMap)([argAssert0, argAssert1]);
305 319
306 /** 320 /**
307 * Assert that a type is equal to the [expected]. 321 * Assert that a type is equal to the [expected].
308 */ 322 */
309 Asserter<DartType> isType(DartType expected) => (DartType t) { 323 Asserter<DartType> isType(DartType expected) => (DartType t) {
310 expect(t, expected); 324 expect(t, expected);
311 }; 325 };
312 } 326 }
327
328 class _ElementsByNameFinder extends RecursiveAstVisitor<Null> {
329 final String name;
330 final List<Element> elements = [];
331
332 _ElementsByNameFinder(this.name);
333
334 @override
335 visitSimpleIdentifier(SimpleIdentifier node) {
336 if (node.name == name && node.inDeclarationContext()) {
337 elements.add(node.staticElement);
338 }
339 }
340 }
OLDNEW
« 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