| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.src.context.abstract_context; | 5 library analyzer.test.src.context.abstract_context; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 7 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/dart/element/visitor.dart'; |
| 8 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| 9 import 'package:analyzer/file_system/memory_file_system.dart'; | 11 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 10 import 'package:analyzer/src/context/cache.dart'; | 12 import 'package:analyzer/src/context/cache.dart'; |
| 11 import 'package:analyzer/src/context/context.dart'; | 13 import 'package:analyzer/src/context/context.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/sdk.dart'; | 15 import 'package:analyzer/src/generated/sdk.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
| 15 import 'package:analyzer/src/task/driver.dart'; | 17 import 'package:analyzer/src/task/driver.dart'; |
| 16 import 'package:analyzer/task/model.dart'; | 18 import 'package:analyzer/task/model.dart'; |
| 17 import 'package:plugin/manager.dart'; | 19 import 'package:plugin/manager.dart'; |
| 18 import 'package:plugin/plugin.dart'; | 20 import 'package:plugin/plugin.dart'; |
| 19 import 'package:unittest/unittest.dart'; | 21 import 'package:unittest/unittest.dart'; |
| 20 | 22 |
| 21 import 'mock_sdk.dart'; | 23 import 'mock_sdk.dart'; |
| 22 | 24 |
| 25 /** |
| 26 * Finds an [Element] with the given [name]. |
| 27 */ |
| 28 Element findChildElement(Element root, String name, [ElementKind kind]) { |
| 29 Element result = null; |
| 30 root.accept(new _ElementVisitorFunctionWrapper((Element element) { |
| 31 if (element.name != name) { |
| 32 return; |
| 33 } |
| 34 if (kind != null && element.kind != kind) { |
| 35 return; |
| 36 } |
| 37 result = element; |
| 38 })); |
| 39 return result; |
| 40 } |
| 41 |
| 42 /** |
| 43 * A function to be called for every [Element]. |
| 44 */ |
| 45 typedef void _ElementVisitorFunction(Element element); |
| 46 |
| 23 class AbstractContextTest { | 47 class AbstractContextTest { |
| 24 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); | 48 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 25 | 49 |
| 26 DartSdk sdk = new MockSdk(); | 50 DartSdk sdk = new MockSdk(); |
| 27 SourceFactory sourceFactory; | 51 SourceFactory sourceFactory; |
| 28 AnalysisContextImpl context; | 52 AnalysisContextImpl context; |
| 29 AnalysisCache analysisCache; | 53 AnalysisCache analysisCache; |
| 30 AnalysisDriver analysisDriver; | 54 AnalysisDriver analysisDriver; |
| 31 | 55 |
| 32 UriResolver sdkResolver; | 56 UriResolver sdkResolver; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 new SourceFactory(<UriResolver>[sdkResolver, resourceResolver]); | 141 new SourceFactory(<UriResolver>[sdkResolver, resourceResolver]); |
| 118 context = createAnalysisContext(); | 142 context = createAnalysisContext(); |
| 119 if (options != null) { | 143 if (options != null) { |
| 120 context.analysisOptions = options; | 144 context.analysisOptions = options; |
| 121 } | 145 } |
| 122 context.sourceFactory = sourceFactory; | 146 context.sourceFactory = sourceFactory; |
| 123 analysisCache = context.analysisCache; | 147 analysisCache = context.analysisCache; |
| 124 analysisDriver = context.driver; | 148 analysisDriver = context.driver; |
| 125 } | 149 } |
| 126 | 150 |
| 151 CompilationUnit resolveLibraryUnit(Source source) { |
| 152 return context.resolveCompilationUnit2(source, source); |
| 153 } |
| 154 |
| 127 void setUp() { | 155 void setUp() { |
| 128 List<Plugin> plugins = <Plugin>[]; | 156 List<Plugin> plugins = <Plugin>[]; |
| 129 plugins.addAll(AnalysisEngine.instance.requiredPlugins); | 157 plugins.addAll(AnalysisEngine.instance.requiredPlugins); |
| 130 plugins.add(AnalysisEngine.instance.commandLinePlugin); | 158 plugins.add(AnalysisEngine.instance.commandLinePlugin); |
| 131 plugins.add(AnalysisEngine.instance.optionsPlugin); | 159 plugins.add(AnalysisEngine.instance.optionsPlugin); |
| 132 | 160 |
| 133 ExtensionManager manager = new ExtensionManager(); | 161 ExtensionManager manager = new ExtensionManager(); |
| 134 manager.processPlugins(plugins); | 162 manager.processPlugins(plugins); |
| 135 | 163 |
| 136 prepareAnalysisContext(); | 164 prepareAnalysisContext(); |
| 137 } | 165 } |
| 138 | 166 |
| 139 void tearDown() {} | 167 void tearDown() {} |
| 140 } | 168 } |
| 169 |
| 170 /** |
| 171 * Wraps the given [_ElementVisitorFunction] into an instance of |
| 172 * [GeneralizingElementVisitor]. |
| 173 */ |
| 174 class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor { |
| 175 final _ElementVisitorFunction function; |
| 176 |
| 177 _ElementVisitorFunctionWrapper(this.function); |
| 178 |
| 179 visitElement(Element element) { |
| 180 function(element); |
| 181 super.visitElement(element); |
| 182 } |
| 183 } |
| OLD | NEW |