| Index: pkg/analyzer/test/src/context/abstract_context.dart
|
| diff --git a/pkg/analyzer/test/src/context/abstract_context.dart b/pkg/analyzer/test/src/context/abstract_context.dart
|
| index 18bde46f2915d10b12ac33d9e2d504d8b7744657..b0b7a01e321746b13216495c227d9e64de1f7559 100644
|
| --- a/pkg/analyzer/test/src/context/abstract_context.dart
|
| +++ b/pkg/analyzer/test/src/context/abstract_context.dart
|
| @@ -4,7 +4,9 @@
|
|
|
| library analyzer.test.src.context.abstract_context;
|
|
|
| +import 'package:analyzer/dart/ast/ast.dart';
|
| import 'package:analyzer/dart/element/element.dart';
|
| +import 'package:analyzer/dart/element/visitor.dart';
|
| import 'package:analyzer/file_system/file_system.dart';
|
| import 'package:analyzer/file_system/memory_file_system.dart';
|
| import 'package:analyzer/src/context/cache.dart';
|
| @@ -20,6 +22,28 @@ import 'package:unittest/unittest.dart';
|
|
|
| import 'mock_sdk.dart';
|
|
|
| +/**
|
| + * Finds an [Element] with the given [name].
|
| + */
|
| +Element findChildElement(Element root, String name, [ElementKind kind]) {
|
| + Element result = null;
|
| + root.accept(new _ElementVisitorFunctionWrapper((Element element) {
|
| + if (element.name != name) {
|
| + return;
|
| + }
|
| + if (kind != null && element.kind != kind) {
|
| + return;
|
| + }
|
| + result = element;
|
| + }));
|
| + return result;
|
| +}
|
| +
|
| +/**
|
| + * A function to be called for every [Element].
|
| + */
|
| +typedef void _ElementVisitorFunction(Element element);
|
| +
|
| class AbstractContextTest {
|
| MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
|
|
|
| @@ -124,6 +148,10 @@ class AbstractContextTest {
|
| analysisDriver = context.driver;
|
| }
|
|
|
| + CompilationUnit resolveLibraryUnit(Source source) {
|
| + return context.resolveCompilationUnit2(source, source);
|
| + }
|
| +
|
| void setUp() {
|
| List<Plugin> plugins = <Plugin>[];
|
| plugins.addAll(AnalysisEngine.instance.requiredPlugins);
|
| @@ -138,3 +166,18 @@ class AbstractContextTest {
|
|
|
| void tearDown() {}
|
| }
|
| +
|
| +/**
|
| + * Wraps the given [_ElementVisitorFunction] into an instance of
|
| + * [GeneralizingElementVisitor].
|
| + */
|
| +class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor {
|
| + final _ElementVisitorFunction function;
|
| +
|
| + _ElementVisitorFunctionWrapper(this.function);
|
| +
|
| + visitElement(Element element) {
|
| + function(element);
|
| + super.visitElement(element);
|
| + }
|
| +}
|
|
|