| 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 test.src.task.dart_test; | 5 library test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| 11 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart' | 12 import 'package:analyzer/src/generated/engine.dart' |
| 13 hide AnalysisTask, ParseDartTask, ScanDartTask; | 13 hide AnalysisTask, GetContentTask, ParseDartTask, ScanDartTask; |
| 14 import 'package:analyzer/src/generated/error.dart'; | 14 import 'package:analyzer/src/generated/error.dart'; |
| 15 import 'package:analyzer/src/generated/resolver.dart'; | 15 import 'package:analyzer/src/generated/resolver.dart'; |
| 16 import 'package:analyzer/src/generated/sdk.dart'; | 16 import 'package:analyzer/src/generated/sdk.dart'; |
| 17 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 18 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 19 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 19 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 20 import 'package:analyzer/src/task/dart.dart'; | 20 import 'package:analyzer/src/task/dart.dart'; |
| 21 import 'package:analyzer/src/task/driver.dart'; | 21 import 'package:analyzer/src/task/driver.dart'; |
| 22 import 'package:analyzer/src/task/general.dart'; |
| 23 import 'package:analyzer/src/task/manager.dart'; |
| 22 import 'package:analyzer/task/dart.dart'; | 24 import 'package:analyzer/task/dart.dart'; |
| 23 import 'package:analyzer/task/general.dart'; | 25 import 'package:analyzer/task/general.dart'; |
| 24 import 'package:analyzer/task/model.dart'; | 26 import 'package:analyzer/task/model.dart'; |
| 25 import 'package:typed_mock/typed_mock.dart'; | 27 import 'package:typed_mock/typed_mock.dart'; |
| 26 import 'package:unittest/unittest.dart'; | 28 import 'package:unittest/unittest.dart'; |
| 27 | 29 |
| 28 import '../../generated/resolver_test.dart'; | |
| 29 import '../../generated/test_support.dart'; | 30 import '../../generated/test_support.dart'; |
| 30 import '../../reflective_tests.dart'; | 31 import '../../reflective_tests.dart'; |
| 32 import '../mock_sdk.dart'; |
| 31 | 33 |
| 32 main() { | 34 main() { |
| 33 groupSep = ' | '; | 35 groupSep = ' | '; |
| 34 runReflectiveTests(BuildCompilationUnitElementTaskTest); | 36 runReflectiveTests(BuildCompilationUnitElementTaskTest); |
| 35 runReflectiveTests(BuildDirectiveElementsTaskTest); | 37 runReflectiveTests(BuildDirectiveElementsTaskTest); |
| 36 runReflectiveTests(BuildLibraryElementTaskTest); | 38 runReflectiveTests(BuildLibraryElementTaskTest); |
| 37 runReflectiveTests(BuildPublicNamespaceTaskTest); | 39 runReflectiveTests(BuildPublicNamespaceTaskTest); |
| 38 runReflectiveTests(ParseDartTaskTest); | 40 runReflectiveTests(ParseDartTaskTest); |
| 39 runReflectiveTests(ScanDartTaskTest); | 41 runReflectiveTests(ScanDartTaskTest); |
| 40 } | 42 } |
| 41 | 43 |
| 42 @reflectiveTest | 44 @reflectiveTest |
| 43 class BuildCompilationUnitElementTaskTest extends EngineTestCase { | 45 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { |
| 44 test_buildInputs() { | 46 test_buildInputs() { |
| 45 AnalysisTarget target = new TestSource(); | |
| 46 Map<String, TaskInput> inputs = | 47 Map<String, TaskInput> inputs = |
| 47 BuildCompilationUnitElementTask.buildInputs(target); | 48 BuildCompilationUnitElementTask.buildInputs(emptySource); |
| 48 expect(inputs, isNotNull); | 49 expect(inputs, isNotNull); |
| 49 expect(inputs.keys, unorderedEquals( | 50 expect(inputs.keys, unorderedEquals( |
| 50 [BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME])); | 51 [BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME])); |
| 51 } | 52 } |
| 52 | 53 |
| 53 test_constructor() { | 54 test_constructor() { |
| 54 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 55 AnalysisTarget target = new TestSource(); | |
| 56 BuildCompilationUnitElementTask task = | 55 BuildCompilationUnitElementTask task = |
| 57 new BuildCompilationUnitElementTask(context, target); | 56 new BuildCompilationUnitElementTask(context, emptySource); |
| 58 expect(task, isNotNull); | 57 expect(task, isNotNull); |
| 59 expect(task.context, context); | 58 expect(task.context, context); |
| 60 expect(task.target, target); | 59 expect(task.target, emptySource); |
| 61 } | 60 } |
| 62 | 61 |
| 63 test_createTask() { | 62 test_createTask() { |
| 64 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 65 AnalysisTarget target = new TestSource(); | |
| 66 BuildCompilationUnitElementTask task = | 63 BuildCompilationUnitElementTask task = |
| 67 BuildCompilationUnitElementTask.createTask(context, target); | 64 BuildCompilationUnitElementTask.createTask(context, emptySource); |
| 68 expect(task, isNotNull); | 65 expect(task, isNotNull); |
| 69 expect(task.context, context); | 66 expect(task.context, context); |
| 70 expect(task.target, target); | 67 expect(task.target, emptySource); |
| 71 } | 68 } |
| 72 | 69 |
| 73 test_description() { | 70 test_description() { |
| 74 AnalysisTarget target = new TestSource(); | |
| 75 BuildCompilationUnitElementTask task = | 71 BuildCompilationUnitElementTask task = |
| 76 new BuildCompilationUnitElementTask(null, target); | 72 new BuildCompilationUnitElementTask(null, emptySource); |
| 77 expect(task.description, isNotNull); | 73 expect(task.description, isNotNull); |
| 78 } | 74 } |
| 79 | 75 |
| 80 test_descriptor() { | 76 test_descriptor() { |
| 81 TaskDescriptor descriptor = BuildCompilationUnitElementTask.DESCRIPTOR; | 77 TaskDescriptor descriptor = BuildCompilationUnitElementTask.DESCRIPTOR; |
| 82 expect(descriptor, isNotNull); | 78 expect(descriptor, isNotNull); |
| 83 } | 79 } |
| 84 | 80 |
| 85 test_perform_library() { | 81 test_perform_library() { |
| 86 BuildCompilationUnitElementTask task = _performBuildTask(r''' | 82 _performBuildTask(r''' |
| 87 library lib; | 83 library lib; |
| 88 import 'lib2.dart'; | 84 import 'lib2.dart'; |
| 89 export 'lib3.dart'; | 85 export 'lib3.dart'; |
| 90 part 'part.dart'; | 86 part 'part.dart'; |
| 91 class A {'''); | 87 class A {'''); |
| 92 | |
| 93 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; | |
| 94 expect(outputs, hasLength(2)); | 88 expect(outputs, hasLength(2)); |
| 95 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); | 89 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); |
| 96 expect(outputs[RESOLVED_UNIT1], isNotNull); | 90 expect(outputs[RESOLVED_UNIT1], isNotNull); |
| 97 } | 91 } |
| 98 | 92 |
| 99 BuildCompilationUnitElementTask _performBuildTask(String content) { | 93 void _performBuildTask(String content) { |
| 100 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 94 AnalysisTarget target = _newSource('/test.dart', content); |
| 101 AnalysisTarget target = new TestSource(); | 95 _computeResult(target, RESOLVED_UNIT1); |
| 102 | 96 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>()); |
| 103 ScanDartTask scanTask = new ScanDartTask(context, target); | |
| 104 scanTask.inputs = {ScanDartTask.CONTENT_INPUT_NAME: content}; | |
| 105 scanTask.perform(); | |
| 106 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; | |
| 107 | |
| 108 ParseDartTask parseTask = new ParseDartTask(context, target); | |
| 109 parseTask.inputs = { | |
| 110 ParseDartTask.LINE_INFO_INPUT_NAME: scanOutputs[LINE_INFO], | |
| 111 ParseDartTask.TOKEN_STREAM_INPUT_NAME: scanOutputs[TOKEN_STREAM] | |
| 112 }; | |
| 113 parseTask.perform(); | |
| 114 Map<ResultDescriptor, dynamic> parseOutputs = parseTask.outputs; | |
| 115 | |
| 116 BuildCompilationUnitElementTask buildTask = | |
| 117 new BuildCompilationUnitElementTask(context, target); | |
| 118 buildTask.inputs = { | |
| 119 BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME: | |
| 120 parseOutputs[PARSED_UNIT] | |
| 121 }; | |
| 122 buildTask.perform(); | |
| 123 | |
| 124 return buildTask; | |
| 125 } | 97 } |
| 126 } | 98 } |
| 127 | 99 |
| 128 @reflectiveTest | 100 @reflectiveTest |
| 129 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { | 101 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { |
| 130 test_buildInputs() { | 102 test_buildInputs() { |
| 131 ExtendedAnalysisContext context = new _MockContext(); | 103 ExtendedAnalysisContext context = new _MockContext(); |
| 132 // prepare sources | 104 // prepare sources |
| 133 File fileA = resourceProvider.newFile('/libA.dart', ''); | 105 File fileA = resourceProvider.newFile('/libA.dart', ''); |
| 134 File fileB = resourceProvider.newFile('/libB.dart', ''); | 106 File fileB = resourceProvider.newFile('/libB.dart', ''); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 164 expect( | 136 expect( |
| 165 inputs[BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME], | 137 inputs[BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME], |
| 166 containsPair(sourceC, libraryElementC)); | 138 containsPair(sourceC, libraryElementC)); |
| 167 expect(inputs[BuildDirectiveElementsTask.IMPORTS_SOURCE_KIND_INPUT_NAME], | 139 expect(inputs[BuildDirectiveElementsTask.IMPORTS_SOURCE_KIND_INPUT_NAME], |
| 168 containsPair(sourceB, SourceKind.LIBRARY)); | 140 containsPair(sourceB, SourceKind.LIBRARY)); |
| 169 expect(inputs[BuildDirectiveElementsTask.EXPORTS_SOURCE_KIND_INPUT_NAME], | 141 expect(inputs[BuildDirectiveElementsTask.EXPORTS_SOURCE_KIND_INPUT_NAME], |
| 170 containsPair(sourceC, SourceKind.LIBRARY)); | 142 containsPair(sourceC, SourceKind.LIBRARY)); |
| 171 } | 143 } |
| 172 | 144 |
| 173 test_constructor() { | 145 test_constructor() { |
| 174 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 175 AnalysisTarget target = new TestSource(); | |
| 176 BuildDirectiveElementsTask task = | 146 BuildDirectiveElementsTask task = |
| 177 new BuildDirectiveElementsTask(context, target); | 147 new BuildDirectiveElementsTask(context, emptySource); |
| 178 expect(task, isNotNull); | 148 expect(task, isNotNull); |
| 179 expect(task.context, context); | 149 expect(task.context, context); |
| 180 expect(task.target, target); | 150 expect(task.target, emptySource); |
| 181 } | 151 } |
| 182 | 152 |
| 183 test_createTask() { | 153 test_createTask() { |
| 184 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 185 AnalysisTarget target = new TestSource(); | |
| 186 BuildDirectiveElementsTask task = | 154 BuildDirectiveElementsTask task = |
| 187 BuildDirectiveElementsTask.createTask(context, target); | 155 BuildDirectiveElementsTask.createTask(context, emptySource); |
| 188 expect(task, isNotNull); | 156 expect(task, isNotNull); |
| 189 expect(task.context, context); | 157 expect(task.context, context); |
| 190 expect(task.target, target); | 158 expect(task.target, emptySource); |
| 191 } | 159 } |
| 192 | 160 |
| 193 test_description() { | 161 test_description() { |
| 194 AnalysisTarget target = new TestSource(); | |
| 195 BuildDirectiveElementsTask task = | 162 BuildDirectiveElementsTask task = |
| 196 new BuildDirectiveElementsTask(null, target); | 163 new BuildDirectiveElementsTask(null, emptySource); |
| 197 expect(task.description, isNotNull); | 164 expect(task.description, isNotNull); |
| 198 } | 165 } |
| 199 | 166 |
| 200 test_descriptor() { | 167 test_descriptor() { |
| 201 TaskDescriptor descriptor = BuildDirectiveElementsTask.DESCRIPTOR; | 168 TaskDescriptor descriptor = BuildDirectiveElementsTask.DESCRIPTOR; |
| 202 expect(descriptor, isNotNull); | 169 expect(descriptor, isNotNull); |
| 203 } | 170 } |
| 204 | 171 |
| 205 test_perform() { | 172 test_perform() { |
| 206 // TODO | 173 List<Source> sources = _newSources({ |
| 207 var libraryResultA = _buildLibraryElement({ | |
| 208 '/libA.dart': ''' | 174 '/libA.dart': ''' |
| 209 library libA; | 175 library libA; |
| 210 import 'libB.dart'; | 176 import 'libB.dart'; |
| 211 export 'libC.dart'; | 177 export 'libC.dart'; |
| 212 ''' | 178 ''', |
| 213 }); | |
| 214 var libraryResultB = _buildLibraryElement({ | |
| 215 '/libB.dart': ''' | 179 '/libB.dart': ''' |
| 216 library libB; | 180 library libB; |
| 217 ''' | 181 ''', |
| 218 }); | |
| 219 var libraryResultC = _buildLibraryElement({ | |
| 220 '/libC.dart': ''' | 182 '/libC.dart': ''' |
| 221 library libC; | 183 library libC; |
| 222 ''' | 184 ''' |
| 223 }); | 185 }); |
| 186 Source sourceA = sources[0]; |
| 187 Source sourceB = sources[1]; |
| 188 Source sourceC = sources[2]; |
| 224 // perform task | 189 // perform task |
| 225 BuildDirectiveElementsTask task = | 190 _computeResult(sourceA, RESOLVED_UNIT3); |
| 226 new BuildDirectiveElementsTask(context, libraryResultA.librarySource); | 191 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 227 task.inputs = { | |
| 228 BuildDirectiveElementsTask.RESOLVED_UNIT2_INPUT_NAME: | |
| 229 libraryResultA.libraryUnit, | |
| 230 BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME: { | |
| 231 libraryResultB.librarySource: libraryResultB.libraryElement | |
| 232 }, | |
| 233 BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME: { | |
| 234 libraryResultC.librarySource: libraryResultC.libraryElement | |
| 235 }, | |
| 236 BuildDirectiveElementsTask.IMPORTS_SOURCE_KIND_INPUT_NAME: { | |
| 237 libraryResultB.librarySource: SourceKind.LIBRARY | |
| 238 }, | |
| 239 BuildDirectiveElementsTask.EXPORTS_SOURCE_KIND_INPUT_NAME: { | |
| 240 libraryResultC.librarySource: SourceKind.LIBRARY | |
| 241 } | |
| 242 }; | |
| 243 Map<ResultDescriptor, dynamic> outputs = _performTask(task); | |
| 244 // prepare outputs | 192 // prepare outputs |
| 245 CompilationUnit libraryUnitA = outputs[RESOLVED_UNIT3]; | 193 CompilationUnit libraryUnitA = outputs[RESOLVED_UNIT3]; |
| 246 LibraryElement libraryElementA = libraryUnitA.element.library; | 194 LibraryElement libraryElementA = libraryUnitA.element.library; |
| 195 LibraryElement libraryElementB = _getImportLibraryInput(sourceB); |
| 196 LibraryElement libraryElementC = _getExportLibraryInput(sourceC); |
| 247 // no errors | 197 // no errors |
| 248 _assertErrorsWithCodes([]); | 198 _assertErrorsWithCodes([]); |
| 249 // validate directives | 199 // validate directives |
| 250 { | 200 { |
| 251 ImportDirective importNode = libraryUnitA.directives[1]; | 201 ImportDirective importNode = libraryUnitA.directives[1]; |
| 252 ImportElement importElement = importNode.element; | 202 ImportElement importElement = importNode.element; |
| 253 expect(importElement, isNotNull); | 203 expect(importElement, isNotNull); |
| 254 expect(importElement.importedLibrary, libraryResultB.libraryElement); | 204 expect(importElement.importedLibrary, libraryElementB); |
| 255 expect(importElement.prefix, isNull); | 205 expect(importElement.prefix, isNull); |
| 256 expect(importElement.nameOffset, 14); | 206 expect(importElement.nameOffset, 14); |
| 257 expect(importElement.uriOffset, 21); | 207 expect(importElement.uriOffset, 21); |
| 258 expect(importElement.uriEnd, 32); | 208 expect(importElement.uriEnd, 32); |
| 259 } | 209 } |
| 260 { | 210 { |
| 261 ExportDirective exportNode = libraryUnitA.directives[2]; | 211 ExportDirective exportNode = libraryUnitA.directives[2]; |
| 262 ExportElement exportElement = exportNode.element; | 212 ExportElement exportElement = exportNode.element; |
| 263 expect(exportElement, isNotNull); | 213 expect(exportElement, isNotNull); |
| 264 expect(exportElement.exportedLibrary, libraryResultC.libraryElement); | 214 expect(exportElement.exportedLibrary, libraryElementC); |
| 265 expect(exportElement.nameOffset, 34); | 215 expect(exportElement.nameOffset, 34); |
| 266 expect(exportElement.uriOffset, 41); | 216 expect(exportElement.uriOffset, 41); |
| 267 expect(exportElement.uriEnd, 52); | 217 expect(exportElement.uriEnd, 52); |
| 268 } | 218 } |
| 269 // validate LibraryElement | 219 // validate LibraryElement |
| 270 expect(libraryElementA.hasExtUri, isFalse); | 220 expect(libraryElementA.hasExtUri, isFalse); |
| 271 // has an artificial "dart:core" import | 221 // has an artificial "dart:core" import |
| 272 { | 222 { |
| 273 List<ImportElement> imports = libraryElementA.imports; | 223 List<ImportElement> imports = libraryElementA.imports; |
| 274 expect(imports, hasLength(2)); | 224 expect(imports, hasLength(2)); |
| 275 // TODO(scheglov) use FS-based MockDartSdk | 225 expect(imports[1].importedLibrary.isDartCore, isTrue); |
| 276 // expect(imports[1].importedLibrary.isDartCore, isTrue); | |
| 277 } | 226 } |
| 278 } | 227 } |
| 279 | 228 |
| 280 test_perform_combinators() { | 229 test_perform_combinators() { |
| 281 var libraryResultA = _buildLibraryElement({ | 230 List<Source> sources = _newSources({ |
| 282 '/libA.dart': ''' | 231 '/libA.dart': ''' |
| 283 library libA; | 232 library libA; |
| 284 import 'libB.dart' show A, B hide C, D; | 233 import 'libB.dart' show A, B hide C, D; |
| 234 ''', |
| 235 '/libB.dart': ''' |
| 236 library libB; |
| 285 ''' | 237 ''' |
| 286 }); | 238 }); |
| 287 Source sourceB = _newSource('/libB.dart'); | 239 Source sourceA = sources[0]; |
| 288 // perform task | 240 // perform task |
| 289 BuildDirectiveElementsTask task = | 241 _computeResult(sourceA, RESOLVED_UNIT3); |
| 290 new BuildDirectiveElementsTask(context, libraryResultA.librarySource); | 242 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 291 task.inputs = { | |
| 292 BuildDirectiveElementsTask.RESOLVED_UNIT2_INPUT_NAME: | |
| 293 libraryResultA.libraryUnit, | |
| 294 BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME: { | |
| 295 sourceB: ElementFactory.library(context, 'libB') | |
| 296 }, | |
| 297 BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME: {}, | |
| 298 BuildDirectiveElementsTask.IMPORTS_SOURCE_KIND_INPUT_NAME: { | |
| 299 sourceB: SourceKind.LIBRARY | |
| 300 }, | |
| 301 BuildDirectiveElementsTask.EXPORTS_SOURCE_KIND_INPUT_NAME: {} | |
| 302 }; | |
| 303 Map<ResultDescriptor, dynamic> outputs = _performTask(task); | |
| 304 // prepare outputs | 243 // prepare outputs |
| 305 CompilationUnit libraryUnitA = outputs[RESOLVED_UNIT3]; | 244 CompilationUnit libraryUnitA = outputs[RESOLVED_UNIT3]; |
| 306 // no errors | 245 // no errors |
| 307 _assertErrorsWithCodes([]); | 246 _assertErrorsWithCodes([]); |
| 308 // validate directives | 247 // validate directives |
| 309 ImportDirective importNode = libraryUnitA.directives[1]; | 248 ImportDirective importNode = libraryUnitA.directives[1]; |
| 310 ImportElement importElement = importNode.element; | 249 ImportElement importElement = importNode.element; |
| 311 List<NamespaceCombinator> combinators = importElement.combinators; | 250 List<NamespaceCombinator> combinators = importElement.combinators; |
| 312 expect(combinators, hasLength(2)); | 251 expect(combinators, hasLength(2)); |
| 313 { | 252 { |
| 314 ShowElementCombinator combinator = combinators[0]; | 253 ShowElementCombinator combinator = combinators[0]; |
| 315 expect(combinator.offset, 33); | 254 expect(combinator.offset, 33); |
| 316 expect(combinator.end, 42); | 255 expect(combinator.end, 42); |
| 317 expect(combinator.shownNames, ['A', 'B']); | 256 expect(combinator.shownNames, ['A', 'B']); |
| 318 } | 257 } |
| 319 { | 258 { |
| 320 HideElementCombinator combinator = combinators[1]; | 259 HideElementCombinator combinator = combinators[1]; |
| 321 expect(combinator.hiddenNames, ['C', 'D']); | 260 expect(combinator.hiddenNames, ['C', 'D']); |
| 322 } | 261 } |
| 323 } | 262 } |
| 324 | 263 |
| 325 test_perform_error_exportOfNonLibrary() { | 264 test_perform_error_exportOfNonLibrary() { |
| 326 var libraryResultA = _buildLibraryElement({ | 265 List<Source> sources = _newSources({ |
| 327 '/libA.dart': ''' | 266 '/libA.dart': ''' |
| 328 library libA; | 267 library libA; |
| 329 export 'part.dart'; | 268 export 'part.dart'; |
| 269 ''', |
| 270 '/part.dart': ''' |
| 271 part of notLib; |
| 330 ''' | 272 ''' |
| 331 }); | 273 }); |
| 332 Source sourceB = _newSource('/part.dart'); | 274 Source sourceA = sources[0]; |
| 333 // perform task | 275 // perform task |
| 334 BuildDirectiveElementsTask task = | 276 _computeResult(sourceA, RESOLVED_UNIT3); |
| 335 new BuildDirectiveElementsTask(context, libraryResultA.librarySource); | 277 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 336 task.inputs = { | |
| 337 BuildDirectiveElementsTask.RESOLVED_UNIT2_INPUT_NAME: | |
| 338 libraryResultA.libraryUnit, | |
| 339 BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME: {}, | |
| 340 BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME: { | |
| 341 sourceB: ElementFactory.library(context, 'notLib') | |
| 342 }, | |
| 343 BuildDirectiveElementsTask.IMPORTS_SOURCE_KIND_INPUT_NAME: {}, | |
| 344 BuildDirectiveElementsTask.EXPORTS_SOURCE_KIND_INPUT_NAME: { | |
| 345 sourceB: SourceKind.PART | |
| 346 } | |
| 347 }; | |
| 348 _performTask(task); | |
| 349 // validate errors | 278 // validate errors |
| 350 _assertErrorsWithCodes([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); | 279 _assertErrorsWithCodes([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); |
| 351 } | 280 } |
| 352 | 281 |
| 353 test_perform_error_importOfNonLibrary() { | 282 test_perform_error_importOfNonLibrary() { |
| 354 var libraryResultA = _buildLibraryElement({ | 283 List<Source> sources = _newSources({ |
| 355 '/libA.dart': ''' | 284 '/libA.dart': ''' |
| 356 library libA; | 285 library libA; |
| 357 import 'part.dart'; | 286 import 'part.dart'; |
| 287 ''', |
| 288 '/part.dart': ''' |
| 289 part of notLib; |
| 358 ''' | 290 ''' |
| 359 }); | 291 }); |
| 360 Source sourceB = _newSource('/part.dart'); | 292 Source sourceA = sources[0]; |
| 361 // perform task | 293 // perform task |
| 362 BuildDirectiveElementsTask task = | 294 _computeResult(sourceA, RESOLVED_UNIT3); |
| 363 new BuildDirectiveElementsTask(context, libraryResultA.librarySource); | 295 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 364 task.inputs = { | |
| 365 BuildDirectiveElementsTask.RESOLVED_UNIT2_INPUT_NAME: | |
| 366 libraryResultA.libraryUnit, | |
| 367 BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME: { | |
| 368 sourceB: ElementFactory.library(context, 'notLib') | |
| 369 }, | |
| 370 BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME: {}, | |
| 371 BuildDirectiveElementsTask.IMPORTS_SOURCE_KIND_INPUT_NAME: { | |
| 372 sourceB: SourceKind.PART | |
| 373 }, | |
| 374 BuildDirectiveElementsTask.EXPORTS_SOURCE_KIND_INPUT_NAME: {} | |
| 375 }; | |
| 376 _performTask(task); | |
| 377 // validate errors | 296 // validate errors |
| 378 _assertErrorsWithCodes([CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); | 297 _assertErrorsWithCodes([CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); |
| 379 } | 298 } |
| 380 | 299 |
| 381 test_perform_hasExtUri() { | 300 test_perform_hasExtUri() { |
| 382 var libraryResult = _buildLibraryElement({ | 301 List<Source> sources = _newSources({ |
| 383 '/lib.dart': ''' | 302 '/lib.dart': ''' |
| 384 library lib; | |
| 385 import 'dart-ext:doesNotExist.dart'; | 303 import 'dart-ext:doesNotExist.dart'; |
| 386 ''' | 304 ''' |
| 387 }); | 305 }); |
| 306 Source source = sources[0]; |
| 388 // perform task | 307 // perform task |
| 389 BuildDirectiveElementsTask task = | 308 _computeResult(source, RESOLVED_UNIT3); |
| 390 new BuildDirectiveElementsTask(context, libraryResult.librarySource); | 309 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 391 task.inputs = { | |
| 392 BuildDirectiveElementsTask.RESOLVED_UNIT2_INPUT_NAME: | |
| 393 libraryResult.libraryUnit, | |
| 394 BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME: {}, | |
| 395 BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME: {}, | |
| 396 BuildDirectiveElementsTask.IMPORTS_SOURCE_KIND_INPUT_NAME: {}, | |
| 397 BuildDirectiveElementsTask.EXPORTS_SOURCE_KIND_INPUT_NAME: {} | |
| 398 }; | |
| 399 Map<ResultDescriptor, dynamic> outputs = _performTask(task); | |
| 400 // prepare outputs | 310 // prepare outputs |
| 401 CompilationUnit libraryUnit = outputs[RESOLVED_UNIT3]; | 311 CompilationUnit libraryUnit = outputs[RESOLVED_UNIT3]; |
| 402 LibraryElement libraryElement = libraryUnit.element.library; | 312 LibraryElement libraryElement = libraryUnit.element.library; |
| 403 expect(libraryElement.hasExtUri, isTrue); | 313 expect(libraryElement.hasExtUri, isTrue); |
| 404 } | 314 } |
| 405 | 315 |
| 406 test_perform_importPrefix() { | 316 test_perform_importPrefix() { |
| 407 var libraryResultA = _buildLibraryElement({ | 317 List<Source> sources = _newSources({ |
| 408 '/libA.dart': ''' | 318 '/libA.dart': ''' |
| 409 library libA; | 319 library libA; |
| 410 import 'libB.dart' as pref; | 320 import 'libB.dart' as pref; |
| 411 import 'libC.dart' as pref; | 321 import 'libC.dart' as pref; |
| 412 ''' | 322 ''', |
| 413 }); | |
| 414 var libraryResultB = _buildLibraryElement({ | |
| 415 '/libB.dart': ''' | 323 '/libB.dart': ''' |
| 416 library libB; | 324 library libB; |
| 417 ''' | 325 ''', |
| 418 }); | |
| 419 var libraryResultC = _buildLibraryElement({ | |
| 420 '/libC.dart': ''' | 326 '/libC.dart': ''' |
| 421 library libC; | 327 library libC; |
| 422 ''' | 328 ''' |
| 423 }); | 329 }); |
| 330 Source sourceA = sources[0]; |
| 331 Source sourceB = sources[1]; |
| 424 // perform task | 332 // perform task |
| 425 BuildDirectiveElementsTask task = | 333 _computeResult(sourceA, RESOLVED_UNIT3); |
| 426 new BuildDirectiveElementsTask(context, libraryResultA.librarySource); | 334 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); |
| 427 task.inputs = { | |
| 428 BuildDirectiveElementsTask.RESOLVED_UNIT2_INPUT_NAME: | |
| 429 libraryResultA.libraryUnit, | |
| 430 BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME: { | |
| 431 libraryResultB.librarySource: libraryResultB.libraryElement, | |
| 432 libraryResultC.librarySource: libraryResultC.libraryElement | |
| 433 }, | |
| 434 BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME: {}, | |
| 435 BuildDirectiveElementsTask.IMPORTS_SOURCE_KIND_INPUT_NAME: { | |
| 436 libraryResultB.librarySource: SourceKind.LIBRARY, | |
| 437 libraryResultC.librarySource: SourceKind.LIBRARY | |
| 438 }, | |
| 439 BuildDirectiveElementsTask.EXPORTS_SOURCE_KIND_INPUT_NAME: {} | |
| 440 }; | |
| 441 Map<ResultDescriptor, dynamic> outputs = _performTask(task); | |
| 442 // prepare outputs | 335 // prepare outputs |
| 443 CompilationUnit libraryUnitA = outputs[RESOLVED_UNIT3]; | 336 CompilationUnit libraryUnitA = outputs[RESOLVED_UNIT3]; |
| 444 // validate directives | 337 // validate directives |
| 445 { | 338 { |
| 446 ImportDirective importNodeB = libraryUnitA.directives[1]; | 339 ImportDirective importNodeB = libraryUnitA.directives[1]; |
| 447 SimpleIdentifier prefixNodeB = importNodeB.prefix; | 340 SimpleIdentifier prefixNodeB = importNodeB.prefix; |
| 448 ImportElement importElementB = importNodeB.element; | 341 ImportElement importElementB = importNodeB.element; |
| 449 PrefixElement prefixElement = importElementB.prefix; | 342 PrefixElement prefixElement = importElementB.prefix; |
| 450 expect(importElementB, isNotNull); | 343 expect(importElementB, isNotNull); |
| 451 expect(importElementB.importedLibrary, libraryResultB.libraryElement); | 344 expect(importElementB.importedLibrary, _getImportLibraryInput(sourceB)); |
| 452 expect(prefixElement, isNotNull); | 345 expect(prefixElement, isNotNull); |
| 453 // TODO(scheglov) remove "prefixOffset" | |
| 454 expect(importElementB.prefixOffset, prefixElement.nameOffset); | 346 expect(importElementB.prefixOffset, prefixElement.nameOffset); |
| 455 expect(prefixNodeB.staticElement, prefixElement); | 347 expect(prefixNodeB.staticElement, prefixElement); |
| 456 // PrefixElement "pref" is shared | 348 // PrefixElement "pref" is shared |
| 457 ImportDirective importNodeC = libraryUnitA.directives[2]; | 349 ImportDirective importNodeC = libraryUnitA.directives[2]; |
| 458 SimpleIdentifier prefixNodeC = importNodeC.prefix; | 350 SimpleIdentifier prefixNodeC = importNodeC.prefix; |
| 459 ImportElement importElementC = importNodeC.element; | 351 ImportElement importElementC = importNodeC.element; |
| 460 expect(prefixNodeC.staticElement, prefixElement); | 352 expect(prefixNodeC.staticElement, prefixElement); |
| 461 expect(importElementC.prefix, prefixElement); | 353 expect(importElementC.prefix, prefixElement); |
| 462 } | 354 } |
| 463 } | 355 } |
| 464 | 356 |
| 465 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { | 357 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| 466 _fillErrorListener(BUILD_DIRECTIVES_ERRORS); | 358 _fillErrorListener(BUILD_DIRECTIVES_ERRORS); |
| 467 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 359 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 468 } | 360 } |
| 469 | 361 |
| 470 Source _newSource(String path, [String content = '']) { | 362 _getExportLibraryInput(Source source) { |
| 471 File file = resourceProvider.newFile(path, content); | 363 var key = BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME; |
| 472 return file.createSource(); | 364 return task.inputs[key][source]; |
| 365 } |
| 366 |
| 367 _getImportLibraryInput(Source source) { |
| 368 var key = BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME; |
| 369 return task.inputs[key][source]; |
| 473 } | 370 } |
| 474 } | 371 } |
| 475 | 372 |
| 476 @reflectiveTest | 373 @reflectiveTest |
| 477 class BuildLibraryElementTaskTest extends _AbstractDartTaskTest { | 374 class BuildLibraryElementTaskTest extends _AbstractDartTaskTest { |
| 478 Source librarySource; | 375 Source librarySource; |
| 479 CompilationUnit libraryUnit; | 376 CompilationUnit libraryUnit; |
| 480 CompilationUnitElement libraryUnitElement; | 377 CompilationUnitElement libraryUnitElement; |
| 481 List<CompilationUnit> partUnits; | 378 List<CompilationUnit> partUnits; |
| 482 | 379 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 507 workItem.gatherInputs(null); | 404 workItem.gatherInputs(null); |
| 508 Map<String, dynamic> inputs = workItem.inputs; | 405 Map<String, dynamic> inputs = workItem.inputs; |
| 509 expect(inputs, hasLength(2)); | 406 expect(inputs, hasLength(2)); |
| 510 expect(inputs[BuildLibraryElementTask.DEFINING_RESOLVER_UNIT1_INPUT_NAME], | 407 expect(inputs[BuildLibraryElementTask.DEFINING_RESOLVER_UNIT1_INPUT_NAME], |
| 511 libraryUnit); | 408 libraryUnit); |
| 512 expect(inputs[BuildLibraryElementTask.PARTS_RESOLVED_UNIT1_INPUT_NAME], | 409 expect(inputs[BuildLibraryElementTask.PARTS_RESOLVED_UNIT1_INPUT_NAME], |
| 513 unorderedEquals([partUnit1, partUnit2])); | 410 unorderedEquals([partUnit1, partUnit2])); |
| 514 } | 411 } |
| 515 | 412 |
| 516 test_constructor() { | 413 test_constructor() { |
| 517 AnalysisTarget target = new TestSource(); | 414 BuildLibraryElementTask task = |
| 518 BuildLibraryElementTask task = new BuildLibraryElementTask(context, target); | 415 new BuildLibraryElementTask(context, emptySource); |
| 519 expect(task, isNotNull); | 416 expect(task, isNotNull); |
| 520 expect(task.context, context); | 417 expect(task.context, context); |
| 521 expect(task.target, target); | 418 expect(task.target, emptySource); |
| 522 } | 419 } |
| 523 | 420 |
| 524 test_createTask() { | 421 test_createTask() { |
| 525 AnalysisTarget target = new TestSource(); | |
| 526 BuildLibraryElementTask task = | 422 BuildLibraryElementTask task = |
| 527 BuildLibraryElementTask.createTask(context, target); | 423 BuildLibraryElementTask.createTask(context, emptySource); |
| 528 expect(task, isNotNull); | 424 expect(task, isNotNull); |
| 529 expect(task.context, context); | 425 expect(task.context, context); |
| 530 expect(task.target, target); | 426 expect(task.target, emptySource); |
| 531 } | 427 } |
| 532 | 428 |
| 533 test_description() { | 429 test_description() { |
| 534 AnalysisTarget target = new TestSource(); | 430 BuildLibraryElementTask task = |
| 535 BuildLibraryElementTask task = new BuildLibraryElementTask(null, target); | 431 new BuildLibraryElementTask(null, emptySource); |
| 536 expect(task.description, isNotNull); | 432 expect(task.description, isNotNull); |
| 537 } | 433 } |
| 538 | 434 |
| 539 test_descriptor() { | 435 test_descriptor() { |
| 540 TaskDescriptor descriptor = BuildLibraryElementTask.DESCRIPTOR; | 436 TaskDescriptor descriptor = BuildLibraryElementTask.DESCRIPTOR; |
| 541 expect(descriptor, isNotNull); | 437 expect(descriptor, isNotNull); |
| 542 } | 438 } |
| 543 | 439 |
| 544 test_perform() { | 440 test_perform() { |
| 545 _performBuildTask({ | 441 _performBuildTask({ |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 expect(unitElement1.topLevelVariables, [variable]); | 594 expect(unitElement1.topLevelVariables, [variable]); |
| 699 expect(unitElement2.topLevelVariables, [variable]); | 595 expect(unitElement2.topLevelVariables, [variable]); |
| 700 } | 596 } |
| 701 | 597 |
| 702 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { | 598 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| 703 _fillErrorListener(BUILD_LIBRARY_ERRORS); | 599 _fillErrorListener(BUILD_LIBRARY_ERRORS); |
| 704 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 600 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 705 } | 601 } |
| 706 | 602 |
| 707 void _performBuildTask(Map<String, String> sourceMap) { | 603 void _performBuildTask(Map<String, String> sourceMap) { |
| 708 _BuildLibraryElementTaskResult result = _buildLibraryElement(sourceMap); | 604 List<Source> sources = _newSources(sourceMap); |
| 709 Map<String, CompilationUnit> unitMap = <String, CompilationUnit>{}; | 605 _computeResult(sources.first, RESOLVED_UNIT2); |
| 710 sourceMap.forEach((String path, String content) { | 606 expect(task, new isInstanceOf<BuildLibraryElementTask>()); |
| 711 CompilationUnit unit = _buildCompilationUnit(path, content); | 607 libraryUnit = outputs[RESOLVED_UNIT2]; |
| 712 unitMap[path] = unit; | 608 libraryUnitElement = libraryUnit.element; |
| 713 }); | 609 librarySource = libraryUnitElement.source; |
| 714 | 610 libraryElement = outputs[LIBRARY_ELEMENT1]; |
| 715 libraryUnit = result.libraryUnit; | 611 partUnits = |
| 716 libraryUnitElement = result.libraryUnitElement; | 612 task.inputs[BuildLibraryElementTask.PARTS_RESOLVED_UNIT1_INPUT_NAME]; |
| 717 librarySource = result.librarySource; | |
| 718 partUnits = result.partUnits; | |
| 719 | |
| 720 task = result.task; | |
| 721 outputs = result.outputs; | |
| 722 libraryElement = result.libraryElement; | |
| 723 } | 613 } |
| 724 } | 614 } |
| 725 | 615 |
| 726 @reflectiveTest | 616 @reflectiveTest |
| 727 class BuildPublicNamespaceTaskTest extends _AbstractDartTaskTest { | 617 class BuildPublicNamespaceTaskTest extends _AbstractDartTaskTest { |
| 728 test_buildInputs() { | 618 test_buildInputs() { |
| 729 AnalysisTarget target = new TestSource(); | |
| 730 Map<String, TaskInput> inputs = | 619 Map<String, TaskInput> inputs = |
| 731 BuildPublicNamespaceTask.buildInputs(target); | 620 BuildPublicNamespaceTask.buildInputs(emptySource); |
| 732 expect(inputs, isNotNull); | 621 expect(inputs, isNotNull); |
| 733 expect(inputs.keys, unorderedEquals( | 622 expect(inputs.keys, unorderedEquals( |
| 734 [BuildPublicNamespaceTask.BUILT_LIBRARY_ELEMENT_INPUT_NAME])); | 623 [BuildPublicNamespaceTask.BUILT_LIBRARY_ELEMENT_INPUT_NAME])); |
| 735 } | 624 } |
| 736 | 625 |
| 737 test_constructor() { | 626 test_constructor() { |
| 738 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 739 AnalysisTarget target = new TestSource(); | |
| 740 BuildPublicNamespaceTask task = | 627 BuildPublicNamespaceTask task = |
| 741 new BuildPublicNamespaceTask(context, target); | 628 new BuildPublicNamespaceTask(context, emptySource); |
| 742 expect(task, isNotNull); | 629 expect(task, isNotNull); |
| 743 expect(task.context, context); | 630 expect(task.context, context); |
| 744 expect(task.target, target); | 631 expect(task.target, emptySource); |
| 745 } | 632 } |
| 746 | 633 |
| 747 test_createTask() { | 634 test_createTask() { |
| 748 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 749 AnalysisTarget target = new TestSource(); | |
| 750 BuildPublicNamespaceTask task = | 635 BuildPublicNamespaceTask task = |
| 751 BuildPublicNamespaceTask.createTask(context, target); | 636 BuildPublicNamespaceTask.createTask(context, emptySource); |
| 752 expect(task, isNotNull); | 637 expect(task, isNotNull); |
| 753 expect(task.context, context); | 638 expect(task.context, context); |
| 754 expect(task.target, target); | 639 expect(task.target, emptySource); |
| 755 } | 640 } |
| 756 | 641 |
| 757 test_description() { | 642 test_description() { |
| 758 AnalysisTarget target = new TestSource(); | 643 BuildPublicNamespaceTask task = |
| 759 BuildPublicNamespaceTask task = new BuildPublicNamespaceTask(null, target); | 644 new BuildPublicNamespaceTask(null, emptySource); |
| 760 expect(task.description, isNotNull); | 645 expect(task.description, isNotNull); |
| 761 } | 646 } |
| 762 | 647 |
| 763 test_descriptor() { | 648 test_descriptor() { |
| 764 TaskDescriptor descriptor = BuildPublicNamespaceTask.DESCRIPTOR; | 649 TaskDescriptor descriptor = BuildPublicNamespaceTask.DESCRIPTOR; |
| 765 expect(descriptor, isNotNull); | 650 expect(descriptor, isNotNull); |
| 766 } | 651 } |
| 767 | 652 |
| 768 test_perform() { | 653 test_perform() { |
| 769 var buildLibraryElementResult = _buildLibraryElement({ | 654 List<Source> sources = _newSources({ |
| 770 '/lib.dart': ''' | 655 '/lib.dart': ''' |
| 771 library lib; | 656 library lib; |
| 772 part 'part.dart'; | 657 part 'part.dart'; |
| 773 a() {} | 658 a() {} |
| 774 _b() {} | 659 _b() {} |
| 775 ''', | 660 ''', |
| 776 '/part.dart': ''' | 661 '/part.dart': ''' |
| 777 part of lib; | 662 part of lib; |
| 778 _c() {} | 663 _c() {} |
| 779 d() {} | 664 d() {} |
| 780 ''' | 665 ''' |
| 781 }); | 666 }); |
| 782 Source librarySource = buildLibraryElementResult.librarySource; | 667 _computeResult(sources.first, PUBLIC_NAMESPACE); |
| 783 LibraryElement libraryElement = buildLibraryElementResult.libraryElement; | 668 expect(task, new isInstanceOf<BuildPublicNamespaceTask>()); |
| 784 // perform task | |
| 785 BuildPublicNamespaceTask task = | |
| 786 new BuildPublicNamespaceTask(context, librarySource); | |
| 787 task.inputs = { | |
| 788 BuildPublicNamespaceTask.BUILT_LIBRARY_ELEMENT_INPUT_NAME: libraryElement | |
| 789 }; | |
| 790 Map<ResultDescriptor, dynamic> outputs = _performTask(task); | |
| 791 // validate | 669 // validate |
| 792 Namespace namespace = outputs[PUBLIC_NAMESPACE]; | 670 Namespace namespace = outputs[PUBLIC_NAMESPACE]; |
| 793 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd'])); | 671 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd'])); |
| 794 } | 672 } |
| 795 } | 673 } |
| 796 | 674 |
| 797 @reflectiveTest | 675 @reflectiveTest |
| 798 class ParseDartTaskTest extends EngineTestCase { | 676 class ParseDartTaskTest extends _AbstractDartTaskTest { |
| 799 test_buildInputs() { | 677 test_buildInputs() { |
| 800 AnalysisTarget target = new TestSource(); | 678 Map<String, TaskInput> inputs = ParseDartTask.buildInputs(emptySource); |
| 801 Map<String, TaskInput> inputs = ParseDartTask.buildInputs(target); | |
| 802 expect(inputs, isNotNull); | 679 expect(inputs, isNotNull); |
| 803 expect(inputs.keys, unorderedEquals([ | 680 expect(inputs.keys, unorderedEquals([ |
| 804 ParseDartTask.LINE_INFO_INPUT_NAME, | 681 ParseDartTask.LINE_INFO_INPUT_NAME, |
| 805 ParseDartTask.TOKEN_STREAM_INPUT_NAME | 682 ParseDartTask.TOKEN_STREAM_INPUT_NAME |
| 806 ])); | 683 ])); |
| 807 } | 684 } |
| 808 | 685 |
| 809 test_constructor() { | 686 test_constructor() { |
| 810 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 687 ParseDartTask task = new ParseDartTask(context, emptySource); |
| 811 AnalysisTarget target = new TestSource(); | |
| 812 ParseDartTask task = new ParseDartTask(context, target); | |
| 813 expect(task, isNotNull); | 688 expect(task, isNotNull); |
| 814 expect(task.context, context); | 689 expect(task.context, context); |
| 815 expect(task.target, target); | 690 expect(task.target, emptySource); |
| 816 } | 691 } |
| 817 | 692 |
| 818 test_createTask() { | 693 test_createTask() { |
| 819 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 694 ParseDartTask task = ParseDartTask.createTask(context, emptySource); |
| 820 AnalysisTarget target = new TestSource(); | |
| 821 ParseDartTask task = ParseDartTask.createTask(context, target); | |
| 822 expect(task, isNotNull); | 695 expect(task, isNotNull); |
| 823 expect(task.context, context); | 696 expect(task.context, context); |
| 824 expect(task.target, target); | 697 expect(task.target, emptySource); |
| 825 } | 698 } |
| 826 | 699 |
| 827 test_description() { | 700 test_description() { |
| 828 AnalysisTarget target = new TestSource(); | 701 ParseDartTask task = new ParseDartTask(null, emptySource); |
| 829 ParseDartTask task = new ParseDartTask(null, target); | |
| 830 expect(task.description, isNotNull); | 702 expect(task.description, isNotNull); |
| 831 } | 703 } |
| 832 | 704 |
| 833 test_descriptor() { | 705 test_descriptor() { |
| 834 TaskDescriptor descriptor = ParseDartTask.DESCRIPTOR; | 706 TaskDescriptor descriptor = ParseDartTask.DESCRIPTOR; |
| 835 expect(descriptor, isNotNull); | 707 expect(descriptor, isNotNull); |
| 836 } | 708 } |
| 837 | 709 |
| 838 test_perform() { | 710 test_perform() { |
| 839 ParseDartTask task = _performParseTask(r''' | 711 _performParseTask(r''' |
| 840 part of lib; | 712 part of lib; |
| 841 class B {}'''); | 713 class B {}'''); |
| 842 | |
| 843 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; | |
| 844 expect(outputs, hasLength(6)); | 714 expect(outputs, hasLength(6)); |
| 845 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 715 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 846 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); | 716 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 847 expect(outputs[INCLUDED_PARTS], hasLength(0)); | 717 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 848 expect(outputs[PARSE_ERRORS], hasLength(0)); | 718 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 849 expect(outputs[PARSED_UNIT], isNotNull); | 719 expect(outputs[PARSED_UNIT], isNotNull); |
| 850 expect(outputs[SOURCE_KIND], SourceKind.PART); | 720 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 851 } | 721 } |
| 852 | 722 |
| 853 test_perform_invalidDirectives() { | 723 test_perform_invalidDirectives() { |
| 854 ParseDartTask task = _performParseTask(r''' | 724 _performParseTask(r''' |
| 855 library lib; | 725 library lib; |
| 856 import '/does/not/exist.dart'; | 726 import '/does/not/exist.dart'; |
| 857 import '://invaliduri.dart'; | 727 import '://invaliduri.dart'; |
| 858 export '${a}lib3.dart'; | 728 export '${a}lib3.dart'; |
| 859 part 'part.dart'; | 729 part 'part.dart'; |
| 860 class A {}'''); | 730 class A {}'''); |
| 861 | |
| 862 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; | |
| 863 expect(outputs, hasLength(6)); | 731 expect(outputs, hasLength(6)); |
| 864 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 732 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 865 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); | 733 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 866 expect(outputs[INCLUDED_PARTS], hasLength(1)); | 734 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 867 expect(outputs[PARSE_ERRORS], hasLength(2)); | 735 expect(outputs[PARSE_ERRORS], hasLength(2)); |
| 868 expect(outputs[PARSED_UNIT], isNotNull); | 736 expect(outputs[PARSED_UNIT], isNotNull); |
| 869 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 737 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 870 } | 738 } |
| 871 | 739 |
| 872 test_perform_library() { | 740 test_perform_library() { |
| 873 ParseDartTask task = _performParseTask(r''' | 741 _performParseTask(r''' |
| 874 library lib; | 742 library lib; |
| 875 import 'lib2.dart'; | 743 import 'lib2.dart'; |
| 876 export 'lib3.dart'; | 744 export 'lib3.dart'; |
| 877 part 'part.dart'; | 745 part 'part.dart'; |
| 878 class A {'''); | 746 class A {'''); |
| 879 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; | |
| 880 expect(outputs, hasLength(6)); | 747 expect(outputs, hasLength(6)); |
| 881 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); | 748 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); |
| 882 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); | 749 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 883 expect(outputs[INCLUDED_PARTS], hasLength(1)); | 750 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 884 expect(outputs[PARSE_ERRORS], hasLength(1)); | 751 expect(outputs[PARSE_ERRORS], hasLength(1)); |
| 885 expect(outputs[PARSED_UNIT], isNotNull); | 752 expect(outputs[PARSED_UNIT], isNotNull); |
| 886 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 753 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 887 } | 754 } |
| 888 | 755 |
| 889 ParseDartTask _performParseTask(String content) { | 756 void _performParseTask(String content) { |
| 890 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 757 AnalysisTarget target = _newSource('/test.dart', content); |
| 891 AnalysisTarget target = new TestSource(); | 758 _computeResult(target, PARSED_UNIT); |
| 892 | 759 expect(task, new isInstanceOf<ParseDartTask>()); |
| 893 ScanDartTask scanTask = new ScanDartTask(context, target); | |
| 894 scanTask.inputs = {ScanDartTask.CONTENT_INPUT_NAME: content}; | |
| 895 scanTask.perform(); | |
| 896 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; | |
| 897 | |
| 898 ParseDartTask parseTask = new ParseDartTask(context, target); | |
| 899 parseTask.inputs = { | |
| 900 ParseDartTask.LINE_INFO_INPUT_NAME: scanOutputs[LINE_INFO], | |
| 901 ParseDartTask.TOKEN_STREAM_INPUT_NAME: scanOutputs[TOKEN_STREAM] | |
| 902 }; | |
| 903 parseTask.perform(); | |
| 904 return parseTask; | |
| 905 } | 760 } |
| 906 | 761 |
| 907 static void _assertHasCore(List<Source> sources, int lenght) { | 762 static void _assertHasCore(List<Source> sources, int lenght) { |
| 908 expect(sources, hasLength(lenght)); | 763 expect(sources, hasLength(lenght)); |
| 909 expect(sources, contains(predicate((Source s) { | 764 expect(sources, contains(predicate((Source s) { |
| 910 return s.fullName.endsWith('core.dart'); | 765 return s.fullName.endsWith('core.dart'); |
| 911 }))); | 766 }))); |
| 912 } | 767 } |
| 913 } | 768 } |
| 914 | 769 |
| 915 @reflectiveTest | 770 @reflectiveTest |
| 916 class ScanDartTaskTest extends EngineTestCase { | 771 class ScanDartTaskTest extends _AbstractDartTaskTest { |
| 917 test_buildInputs() { | 772 test_buildInputs() { |
| 918 AnalysisTarget target = new TestSource(); | 773 Map<String, TaskInput> inputs = ScanDartTask.buildInputs(emptySource); |
| 919 Map<String, TaskInput> inputs = ScanDartTask.buildInputs(target); | |
| 920 expect(inputs, isNotNull); | 774 expect(inputs, isNotNull); |
| 921 expect(inputs.keys, unorderedEquals([ScanDartTask.CONTENT_INPUT_NAME])); | 775 expect(inputs.keys, unorderedEquals([ScanDartTask.CONTENT_INPUT_NAME])); |
| 922 } | 776 } |
| 923 | 777 |
| 924 test_constructor() { | 778 test_constructor() { |
| 925 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 779 ScanDartTask task = new ScanDartTask(context, emptySource); |
| 926 AnalysisTarget target = new TestSource(); | |
| 927 ScanDartTask task = new ScanDartTask(context, target); | |
| 928 expect(task, isNotNull); | 780 expect(task, isNotNull); |
| 929 expect(task.context, context); | 781 expect(task.context, context); |
| 930 expect(task.target, target); | 782 expect(task.target, emptySource); |
| 931 } | 783 } |
| 932 | 784 |
| 933 test_createTask() { | 785 test_createTask() { |
| 934 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 786 ScanDartTask task = ScanDartTask.createTask(context, emptySource); |
| 935 AnalysisTarget target = new TestSource(); | |
| 936 ScanDartTask task = ScanDartTask.createTask(context, target); | |
| 937 expect(task, isNotNull); | 787 expect(task, isNotNull); |
| 938 expect(task.context, context); | 788 expect(task.context, context); |
| 939 expect(task.target, target); | 789 expect(task.target, emptySource); |
| 940 } | 790 } |
| 941 | 791 |
| 942 test_description() { | 792 test_description() { |
| 943 AnalysisTarget target = new TestSource(); | 793 ScanDartTask task = new ScanDartTask(null, emptySource); |
| 944 ScanDartTask task = new ScanDartTask(null, target); | |
| 945 expect(task.description, isNotNull); | 794 expect(task.description, isNotNull); |
| 946 } | 795 } |
| 947 | 796 |
| 948 test_descriptor() { | 797 test_descriptor() { |
| 949 TaskDescriptor descriptor = ScanDartTask.DESCRIPTOR; | 798 TaskDescriptor descriptor = ScanDartTask.DESCRIPTOR; |
| 950 expect(descriptor, isNotNull); | 799 expect(descriptor, isNotNull); |
| 951 } | 800 } |
| 952 | 801 |
| 953 test_perform_errors() { | 802 test_perform_errors() { |
| 954 ScanDartTask scanTask = _performScanTask('import "'); | 803 _performScanTask('import "'); |
| 955 | 804 expect(outputs, hasLength(3)); |
| 956 expect(scanTask.caughtException, isNull); | 805 expect(outputs[LINE_INFO], isNotNull); |
| 957 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; | 806 expect(outputs[SCAN_ERRORS], hasLength(1)); |
| 958 expect(scanOutputs, hasLength(3)); | 807 expect(outputs[TOKEN_STREAM], isNotNull); |
| 959 expect(scanOutputs[LINE_INFO], isNotNull); | |
| 960 expect(scanOutputs[SCAN_ERRORS], hasLength(1)); | |
| 961 expect(scanOutputs[TOKEN_STREAM], isNotNull); | |
| 962 } | 808 } |
| 963 | 809 |
| 964 test_perform_noErrors() { | 810 test_perform_noErrors() { |
| 965 ScanDartTask scanTask = _performScanTask('class A {}'); | 811 _performScanTask('class A {}'); |
| 966 | 812 expect(outputs, hasLength(3)); |
| 967 expect(scanTask.caughtException, isNull); | 813 expect(outputs[LINE_INFO], isNotNull); |
| 968 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; | 814 expect(outputs[SCAN_ERRORS], hasLength(0)); |
| 969 expect(scanOutputs, hasLength(3)); | 815 expect(outputs[TOKEN_STREAM], isNotNull); |
| 970 expect(scanOutputs[LINE_INFO], isNotNull); | |
| 971 expect(scanOutputs[SCAN_ERRORS], hasLength(0)); | |
| 972 expect(scanOutputs[TOKEN_STREAM], isNotNull); | |
| 973 } | 816 } |
| 974 | 817 |
| 975 ScanDartTask _performScanTask(String content) { | 818 void _performScanTask(String content) { |
| 976 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 819 AnalysisTarget target = _newSource('/test.dart', content); |
| 977 AnalysisTarget target = new TestSource(); | 820 _computeResult(target, TOKEN_STREAM); |
| 978 | 821 expect(task, new isInstanceOf<ScanDartTask>()); |
| 979 ScanDartTask scanTask = new ScanDartTask(context, target); | |
| 980 scanTask.inputs = {ScanDartTask.CONTENT_INPUT_NAME: content}; | |
| 981 scanTask.perform(); | |
| 982 return scanTask; | |
| 983 } | 822 } |
| 984 } | 823 } |
| 985 | 824 |
| 986 class _AbstractDartTaskTest extends EngineTestCase { | 825 class _AbstractDartTaskTest extends EngineTestCase { |
| 987 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); | 826 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 827 Source emptySource; |
| 988 | 828 |
| 989 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 829 DartSdk sdk = new MockSdk(); |
| 830 _MockContext context = new _MockContext(); |
| 990 Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{}; | 831 Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{}; |
| 991 | 832 |
| 833 TaskManager taskManager = new TaskManager(); |
| 834 AnalysisDriver analysisDriver; |
| 835 |
| 992 AnalysisTask task; | 836 AnalysisTask task; |
| 993 Map<ResultDescriptor<dynamic>, dynamic> outputs; | 837 Map<ResultDescriptor<dynamic>, dynamic> outputs; |
| 994 GatheringErrorListener errorListener = new GatheringErrorListener(); | 838 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 995 | 839 |
| 996 CacheEntry getCacheEntry(AnalysisTarget target) { | 840 CacheEntry getCacheEntry(AnalysisTarget target) { |
| 997 return entryMap.putIfAbsent(target, () => new CacheEntry()); | 841 return entryMap.putIfAbsent(target, () => new CacheEntry()); |
| 998 } | 842 } |
| 999 | 843 |
| 1000 void setUp() { | 844 void setUp() { |
| 1001 DartSdk sdk = context.sourceFactory.dartSdk; | 845 emptySource = _newSource('/test.dart'); |
| 846 // prepare AnalysisContext |
| 1002 context.sourceFactory = new SourceFactory(<UriResolver>[ | 847 context.sourceFactory = new SourceFactory(<UriResolver>[ |
| 1003 new DartUriResolver(sdk), | 848 new DartUriResolver(sdk), |
| 1004 new ResourceUriResolver(resourceProvider) | 849 new ResourceUriResolver(resourceProvider) |
| 1005 ]); | 850 ]); |
| 851 // prepare TaskManager |
| 852 taskManager.addTaskDescriptor(GetContentTask.DESCRIPTOR); |
| 853 taskManager.addTaskDescriptor(ScanDartTask.DESCRIPTOR); |
| 854 taskManager.addTaskDescriptor(ParseDartTask.DESCRIPTOR); |
| 855 taskManager.addTaskDescriptor(BuildCompilationUnitElementTask.DESCRIPTOR); |
| 856 taskManager.addTaskDescriptor(BuildLibraryElementTask.DESCRIPTOR); |
| 857 taskManager.addTaskDescriptor(BuildPublicNamespaceTask.DESCRIPTOR); |
| 858 taskManager.addTaskDescriptor(BuildDirectiveElementsTask.DESCRIPTOR); |
| 859 // prepare AnalysisDriver |
| 860 analysisDriver = new AnalysisDriver(taskManager, context); |
| 1006 } | 861 } |
| 1007 | 862 |
| 1008 CompilationUnit _buildCompilationUnit(String path, String content) { | 863 void _computeResult(AnalysisTarget target, ResultDescriptor result) { |
| 1009 File file = resourceProvider.newFile(path, content); | 864 task = analysisDriver.computeResult(target, result); |
| 1010 Source source = file.createSource(); | 865 outputs = task.outputs; |
| 1011 // scan | |
| 1012 ScanDartTask scanTask = new ScanDartTask(context, source); | |
| 1013 scanTask.inputs = {ScanDartTask.CONTENT_INPUT_NAME: content}; | |
| 1014 var scanOutputs = _performTask(scanTask); | |
| 1015 // parse | |
| 1016 ParseDartTask parseTask = new ParseDartTask(context, source); | |
| 1017 parseTask.inputs = { | |
| 1018 ParseDartTask.LINE_INFO_INPUT_NAME: scanOutputs[LINE_INFO], | |
| 1019 ParseDartTask.TOKEN_STREAM_INPUT_NAME: scanOutputs[TOKEN_STREAM] | |
| 1020 }; | |
| 1021 var parseOutputs = _performTask(parseTask); | |
| 1022 // build CompilationUnit | |
| 1023 BuildCompilationUnitElementTask buildTask = | |
| 1024 new BuildCompilationUnitElementTask(context, source); | |
| 1025 buildTask.inputs = { | |
| 1026 BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME: | |
| 1027 parseOutputs[PARSED_UNIT] | |
| 1028 }; | |
| 1029 var buildUnitOutputs = _performTask(buildTask); | |
| 1030 // done | |
| 1031 return buildUnitOutputs[RESOLVED_UNIT1]; | |
| 1032 } | |
| 1033 | |
| 1034 _BuildLibraryElementTaskResult _buildLibraryElement( | |
| 1035 Map<String, String> sourceMap) { | |
| 1036 Map<String, CompilationUnit> unitMap = <String, CompilationUnit>{}; | |
| 1037 sourceMap.forEach((String path, String content) { | |
| 1038 CompilationUnit unit = _buildCompilationUnit(path, content); | |
| 1039 unitMap[path] = unit; | |
| 1040 }); | |
| 1041 | |
| 1042 CompilationUnit libraryUnit = unitMap.values.first; | |
| 1043 CompilationUnitElement libraryUnitElement = libraryUnit.element; | |
| 1044 Source librarySource = libraryUnitElement.source; | |
| 1045 List<CompilationUnit> partUnits = unitMap.values.skip(1).toList(); | |
| 1046 | |
| 1047 BuildLibraryElementTask task = | |
| 1048 new BuildLibraryElementTask(context, librarySource); | |
| 1049 task.inputs = { | |
| 1050 BuildLibraryElementTask.DEFINING_RESOLVER_UNIT1_INPUT_NAME: libraryUnit, | |
| 1051 BuildLibraryElementTask.PARTS_RESOLVED_UNIT1_INPUT_NAME: partUnits | |
| 1052 }; | |
| 1053 Map<ResultDescriptor, dynamic> outputs = _performTask(task); | |
| 1054 | |
| 1055 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT1]; | |
| 1056 return new _BuildLibraryElementTaskResult(librarySource, libraryUnit, | |
| 1057 libraryUnitElement, partUnits, task, outputs, libraryElement); | |
| 1058 } | 866 } |
| 1059 | 867 |
| 1060 /** | 868 /** |
| 1061 * Fill [errorListener] with [result] errors in the current [task]. | 869 * Fill [errorListener] with [result] errors in the current [task]. |
| 1062 */ | 870 */ |
| 1063 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 871 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 1064 List<AnalysisError> errors = task.outputs[result]; | 872 List<AnalysisError> errors = task.outputs[result]; |
| 1065 expect(errors, isNotNull, reason: result.name); | 873 expect(errors, isNotNull, reason: result.name); |
| 1066 errorListener = new GatheringErrorListener(); | 874 errorListener = new GatheringErrorListener(); |
| 1067 errorListener.addAll(errors); | 875 errorListener.addAll(errors); |
| 1068 } | 876 } |
| 1069 | 877 |
| 1070 /** | 878 Source _newSource(String path, [String content = '']) { |
| 1071 * Perform the given [task], record and return its outputs. | 879 File file = resourceProvider.newFile(path, content); |
| 1072 */ | 880 return file.createSource(); |
| 1073 Map<ResultDescriptor, dynamic> _performTask(AnalysisTask task) { | 881 } |
| 1074 this.task = task; | 882 |
| 1075 AnalysisTarget target = task.target; | 883 List<Source> _newSources(Map<String, String> sourceMap) { |
| 1076 // perform the task | 884 List<Source> sources = <Source>[]; |
| 1077 task.perform(); | 885 sourceMap.forEach((String path, String content) { |
| 1078 expect(task.caughtException, isNull); | 886 File file = resourceProvider.newFile(path, content); |
| 1079 outputs = task.outputs; | 887 Source source = file.createSource(); |
| 1080 // file the cache entry | 888 sources.add(source); |
| 1081 CacheEntry cacheEntry = getCacheEntry(target); | |
| 1082 outputs.forEach((result, value) { | |
| 1083 cacheEntry.setValue(result, value); | |
| 1084 }); | 889 }); |
| 1085 return outputs; | 890 return sources; |
| 1086 } | 891 } |
| 1087 } | 892 } |
| 1088 | 893 |
| 1089 class _BuildLibraryElementTaskResult { | 894 class _MockContext extends TypedMock implements ExtendedAnalysisContext { |
| 1090 final Source librarySource; | 895 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 1091 final CompilationUnit libraryUnit; | 896 SourceFactory sourceFactory; |
| 1092 final CompilationUnitElement libraryUnitElement; | |
| 1093 final List<CompilationUnit> partUnits; | |
| 1094 final BuildLibraryElementTask task; | |
| 1095 final Map<ResultDescriptor, dynamic> outputs; | |
| 1096 final LibraryElement libraryElement; | |
| 1097 _BuildLibraryElementTaskResult(this.librarySource, this.libraryUnit, | |
| 1098 this.libraryUnitElement, this.partUnits, this.task, this.outputs, | |
| 1099 this.libraryElement); | |
| 1100 } | |
| 1101 | 897 |
| 1102 class _MockContext extends TypedMock implements ExtendedAnalysisContext { | |
| 1103 Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{}; | 898 Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{}; |
| 1104 | 899 |
| 900 String get name => '_MockContext'; |
| 901 |
| 902 bool exists(Source source) => source.exists(); |
| 903 |
| 1105 @override | 904 @override |
| 1106 CacheEntry getCacheEntry(AnalysisTarget target) { | 905 CacheEntry getCacheEntry(AnalysisTarget target) { |
| 1107 return entryMap.putIfAbsent(target, () => new CacheEntry()); | 906 return entryMap.putIfAbsent(target, () => new CacheEntry()); |
| 1108 } | 907 } |
| 1109 | 908 |
| 1110 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 909 TimestampedData<String> getContents(Source source) => source.contents; |
| 910 |
| 911 noSuchMethod(Invocation invocation) { |
| 912 print('noSuchMethod: ${invocation.memberName}'); |
| 913 return super.noSuchMethod(invocation); |
| 914 } |
| 1111 } | 915 } |
| OLD | NEW |