| 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, 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/task/dart.dart'; | 20 import 'package:analyzer/src/task/dart.dart'; |
| 20 import 'package:analyzer/src/task/driver.dart'; | 21 import 'package:analyzer/src/task/driver.dart'; |
| 21 import 'package:analyzer/task/dart.dart'; | 22 import 'package:analyzer/task/dart.dart'; |
| 22 import 'package:analyzer/task/general.dart'; | 23 import 'package:analyzer/task/general.dart'; |
| 23 import 'package:analyzer/task/model.dart'; | 24 import 'package:analyzer/task/model.dart'; |
| 24 import 'package:typed_mock/typed_mock.dart'; | 25 import 'package:typed_mock/typed_mock.dart'; |
| 25 import 'package:unittest/unittest.dart'; | 26 import 'package:unittest/unittest.dart'; |
| 26 | 27 |
| 27 import '../../generated/resolver_test.dart'; | 28 import '../../generated/resolver_test.dart'; |
| 28 import '../../generated/test_support.dart'; | 29 import '../../generated/test_support.dart'; |
| 29 import '../../reflective_tests.dart'; | 30 import '../../reflective_tests.dart'; |
| 30 | 31 |
| 31 main() { | 32 main() { |
| 32 groupSep = ' | '; | 33 groupSep = ' | '; |
| 33 runReflectiveTests(BuildCompilationUnitElementTaskTest); | 34 runReflectiveTests(BuildCompilationUnitElementTaskTest); |
| 35 runReflectiveTests(BuildDirectiveElementsTaskTest); |
| 34 runReflectiveTests(BuildLibraryElementTaskTest); | 36 runReflectiveTests(BuildLibraryElementTaskTest); |
| 35 runReflectiveTests(BuildPublicNamespaceTaskTest); | 37 runReflectiveTests(BuildPublicNamespaceTaskTest); |
| 36 runReflectiveTests(ParseDartTaskTest); | 38 runReflectiveTests(ParseDartTaskTest); |
| 37 runReflectiveTests(ScanDartTaskTest); | 39 runReflectiveTests(ScanDartTaskTest); |
| 38 } | 40 } |
| 39 | 41 |
| 40 @reflectiveTest | 42 @reflectiveTest |
| 41 class BuildCompilationUnitElementTaskTest extends EngineTestCase { | 43 class BuildCompilationUnitElementTaskTest extends EngineTestCase { |
| 42 test_buildInputs() { | 44 test_buildInputs() { |
| 43 AnalysisTarget target = new TestSource(); | 45 AnalysisTarget target = new TestSource(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 83 } |
| 82 | 84 |
| 83 test_perform_library() { | 85 test_perform_library() { |
| 84 BuildCompilationUnitElementTask task = _performBuildTask(r''' | 86 BuildCompilationUnitElementTask task = _performBuildTask(r''' |
| 85 library lib; | 87 library lib; |
| 86 import 'lib2.dart'; | 88 import 'lib2.dart'; |
| 87 export 'lib3.dart'; | 89 export 'lib3.dart'; |
| 88 part 'part.dart'; | 90 part 'part.dart'; |
| 89 class A {'''); | 91 class A {'''); |
| 90 | 92 |
| 91 expect(task.caughtException, isNull); | |
| 92 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; | 93 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; |
| 93 expect(outputs, hasLength(2)); | 94 expect(outputs, hasLength(2)); |
| 94 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); | 95 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); |
| 95 expect(outputs[BUILT_UNIT], isNotNull); | 96 expect(outputs[RESOLVED_UNIT1], isNotNull); |
| 96 } | 97 } |
| 97 | 98 |
| 98 BuildCompilationUnitElementTask _performBuildTask(String content) { | 99 BuildCompilationUnitElementTask _performBuildTask(String content) { |
| 99 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 100 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 100 AnalysisTarget target = new TestSource(); | 101 AnalysisTarget target = new TestSource(); |
| 101 | 102 |
| 102 ScanDartTask scanTask = new ScanDartTask(context, target); | 103 ScanDartTask scanTask = new ScanDartTask(context, target); |
| 103 scanTask.inputs = {ScanDartTask.CONTENT_INPUT_NAME: content}; | 104 scanTask.inputs = {ScanDartTask.CONTENT_INPUT_NAME: content}; |
| 104 scanTask.perform(); | 105 scanTask.perform(); |
| 105 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; | 106 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 118 BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME: | 119 BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME: |
| 119 parseOutputs[PARSED_UNIT] | 120 parseOutputs[PARSED_UNIT] |
| 120 }; | 121 }; |
| 121 buildTask.perform(); | 122 buildTask.perform(); |
| 122 | 123 |
| 123 return buildTask; | 124 return buildTask; |
| 124 } | 125 } |
| 125 } | 126 } |
| 126 | 127 |
| 127 @reflectiveTest | 128 @reflectiveTest |
| 129 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { |
| 130 test_buildInputs() { |
| 131 ExtendedAnalysisContext context = new _MockContext(); |
| 132 // prepare sources |
| 133 File fileA = resourceProvider.newFile('/libA.dart', ''); |
| 134 File fileB = resourceProvider.newFile('/libB.dart', ''); |
| 135 File fileC = resourceProvider.newFile('/libC.dart', ''); |
| 136 Source sourceA = fileA.createSource(); |
| 137 Source sourceB = fileB.createSource(); |
| 138 Source sourceC = fileC.createSource(); |
| 139 // configure "sourceA" |
| 140 CompilationUnit unitA = AstFactory.compilationUnit(); |
| 141 context.getCacheEntry(sourceA).setValue( |
| 142 IMPORTED_LIBRARIES, <Source>[sourceB]); |
| 143 context.getCacheEntry(sourceA).setValue( |
| 144 EXPORTED_LIBRARIES, <Source>[sourceC]); |
| 145 context.getCacheEntry(sourceA).setValue(RESOLVED_UNIT2, unitA); |
| 146 // configure "sourceB" |
| 147 LibraryElement libraryElementB = ElementFactory.library(context, 'libB'); |
| 148 context.getCacheEntry(sourceB).setValue(LIBRARY_ELEMENT1, libraryElementB); |
| 149 context.getCacheEntry(sourceB).setValue(SOURCE_KIND, SourceKind.LIBRARY); |
| 150 // configure "sourceC" |
| 151 LibraryElement libraryElementC = ElementFactory.library(context, 'libC'); |
| 152 context.getCacheEntry(sourceC).setValue(LIBRARY_ELEMENT1, libraryElementC); |
| 153 context.getCacheEntry(sourceC).setValue(SOURCE_KIND, SourceKind.LIBRARY); |
| 154 // request inputs |
| 155 WorkItem workItem = |
| 156 new WorkItem(context, sourceA, BuildDirectiveElementsTask.DESCRIPTOR); |
| 157 workItem.gatherInputs(null); |
| 158 Map<String, dynamic> inputs = workItem.inputs; |
| 159 expect(inputs, hasLength(5)); |
| 160 expect(inputs[BuildDirectiveElementsTask.RESOLVED_UNIT2_INPUT_NAME], unitA); |
| 161 expect( |
| 162 inputs[BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME], |
| 163 containsPair(sourceB, libraryElementB)); |
| 164 expect( |
| 165 inputs[BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME], |
| 166 containsPair(sourceC, libraryElementC)); |
| 167 expect(inputs[BuildDirectiveElementsTask.IMPORTS_SOURCE_KIND_INPUT_NAME], |
| 168 containsPair(sourceB, SourceKind.LIBRARY)); |
| 169 expect(inputs[BuildDirectiveElementsTask.EXPORTS_SOURCE_KIND_INPUT_NAME], |
| 170 containsPair(sourceC, SourceKind.LIBRARY)); |
| 171 } |
| 172 |
| 173 test_constructor() { |
| 174 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 175 AnalysisTarget target = new TestSource(); |
| 176 BuildDirectiveElementsTask task = |
| 177 new BuildDirectiveElementsTask(context, target); |
| 178 expect(task, isNotNull); |
| 179 expect(task.context, context); |
| 180 expect(task.target, target); |
| 181 } |
| 182 |
| 183 test_createTask() { |
| 184 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 185 AnalysisTarget target = new TestSource(); |
| 186 BuildDirectiveElementsTask task = |
| 187 BuildDirectiveElementsTask.createTask(context, target); |
| 188 expect(task, isNotNull); |
| 189 expect(task.context, context); |
| 190 expect(task.target, target); |
| 191 } |
| 192 |
| 193 test_description() { |
| 194 AnalysisTarget target = new TestSource(); |
| 195 BuildDirectiveElementsTask task = |
| 196 new BuildDirectiveElementsTask(null, target); |
| 197 expect(task.description, isNotNull); |
| 198 } |
| 199 |
| 200 test_descriptor() { |
| 201 TaskDescriptor descriptor = BuildDirectiveElementsTask.DESCRIPTOR; |
| 202 expect(descriptor, isNotNull); |
| 203 } |
| 204 |
| 205 test_perform() { |
| 206 // TODO |
| 207 var libraryResultA = _buildLibraryElement({ |
| 208 '/libA.dart': ''' |
| 209 library libA; |
| 210 import 'libB.dart'; |
| 211 export 'libC.dart'; |
| 212 ''' |
| 213 }); |
| 214 var libraryResultB = _buildLibraryElement({ |
| 215 '/libB.dart': ''' |
| 216 library libB; |
| 217 ''' |
| 218 }); |
| 219 var libraryResultC = _buildLibraryElement({ |
| 220 '/libC.dart': ''' |
| 221 library libC; |
| 222 ''' |
| 223 }); |
| 224 // perform task |
| 225 BuildDirectiveElementsTask task = |
| 226 new BuildDirectiveElementsTask(context, libraryResultA.librarySource); |
| 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 |
| 245 CompilationUnit libraryUnitA = outputs[RESOLVED_UNIT3]; |
| 246 LibraryElement libraryElementA = libraryUnitA.element.library; |
| 247 // no errors |
| 248 _assertErrorsWithCodes([]); |
| 249 // validate directives |
| 250 { |
| 251 ImportDirective importNode = libraryUnitA.directives[1]; |
| 252 ImportElement importElement = importNode.element; |
| 253 expect(importElement, isNotNull); |
| 254 expect(importElement.importedLibrary, libraryResultB.libraryElement); |
| 255 expect(importElement.prefix, isNull); |
| 256 expect(importElement.nameOffset, 14); |
| 257 expect(importElement.uriOffset, 21); |
| 258 expect(importElement.uriEnd, 32); |
| 259 } |
| 260 { |
| 261 ExportDirective exportNode = libraryUnitA.directives[2]; |
| 262 ExportElement exportElement = exportNode.element; |
| 263 expect(exportElement, isNotNull); |
| 264 expect(exportElement.exportedLibrary, libraryResultC.libraryElement); |
| 265 expect(exportElement.nameOffset, 34); |
| 266 expect(exportElement.uriOffset, 41); |
| 267 expect(exportElement.uriEnd, 52); |
| 268 } |
| 269 // validate LibraryElement |
| 270 expect(libraryElementA.hasExtUri, isFalse); |
| 271 // has an artificial "dart:core" import |
| 272 { |
| 273 List<ImportElement> imports = libraryElementA.imports; |
| 274 expect(imports, hasLength(2)); |
| 275 // TODO(scheglov) use FS-based MockDartSdk |
| 276 // expect(imports[1].importedLibrary.isDartCore, isTrue); |
| 277 } |
| 278 } |
| 279 |
| 280 test_perform_combinators() { |
| 281 var libraryResultA = _buildLibraryElement({ |
| 282 '/libA.dart': ''' |
| 283 library libA; |
| 284 import 'libB.dart' show A, B hide C, D; |
| 285 ''' |
| 286 }); |
| 287 Source sourceB = _newSource('/libB.dart'); |
| 288 // perform task |
| 289 BuildDirectiveElementsTask task = |
| 290 new BuildDirectiveElementsTask(context, libraryResultA.librarySource); |
| 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 |
| 305 CompilationUnit libraryUnitA = outputs[RESOLVED_UNIT3]; |
| 306 // no errors |
| 307 _assertErrorsWithCodes([]); |
| 308 // validate directives |
| 309 ImportDirective importNode = libraryUnitA.directives[1]; |
| 310 ImportElement importElement = importNode.element; |
| 311 List<NamespaceCombinator> combinators = importElement.combinators; |
| 312 expect(combinators, hasLength(2)); |
| 313 { |
| 314 ShowElementCombinator combinator = combinators[0]; |
| 315 expect(combinator.offset, 33); |
| 316 expect(combinator.end, 42); |
| 317 expect(combinator.shownNames, ['A', 'B']); |
| 318 } |
| 319 { |
| 320 HideElementCombinator combinator = combinators[1]; |
| 321 expect(combinator.hiddenNames, ['C', 'D']); |
| 322 } |
| 323 } |
| 324 |
| 325 test_perform_error_exportOfNonLibrary() { |
| 326 var libraryResultA = _buildLibraryElement({ |
| 327 '/libA.dart': ''' |
| 328 library libA; |
| 329 export 'part.dart'; |
| 330 ''' |
| 331 }); |
| 332 Source sourceB = _newSource('/part.dart'); |
| 333 // perform task |
| 334 BuildDirectiveElementsTask task = |
| 335 new BuildDirectiveElementsTask(context, libraryResultA.librarySource); |
| 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 |
| 350 _assertErrorsWithCodes([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); |
| 351 } |
| 352 |
| 353 test_perform_error_importOfNonLibrary() { |
| 354 var libraryResultA = _buildLibraryElement({ |
| 355 '/libA.dart': ''' |
| 356 library libA; |
| 357 import 'part.dart'; |
| 358 ''' |
| 359 }); |
| 360 Source sourceB = _newSource('/part.dart'); |
| 361 // perform task |
| 362 BuildDirectiveElementsTask task = |
| 363 new BuildDirectiveElementsTask(context, libraryResultA.librarySource); |
| 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 |
| 378 _assertErrorsWithCodes([CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); |
| 379 } |
| 380 |
| 381 test_perform_hasExtUri() { |
| 382 var libraryResult = _buildLibraryElement({ |
| 383 '/lib.dart': ''' |
| 384 library lib; |
| 385 import 'dart-ext:doesNotExist.dart'; |
| 386 ''' |
| 387 }); |
| 388 // perform task |
| 389 BuildDirectiveElementsTask task = |
| 390 new BuildDirectiveElementsTask(context, libraryResult.librarySource); |
| 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 |
| 401 CompilationUnit libraryUnit = outputs[RESOLVED_UNIT3]; |
| 402 LibraryElement libraryElement = libraryUnit.element.library; |
| 403 expect(libraryElement.hasExtUri, isTrue); |
| 404 } |
| 405 |
| 406 test_perform_importPrefix() { |
| 407 var libraryResultA = _buildLibraryElement({ |
| 408 '/libA.dart': ''' |
| 409 library libA; |
| 410 import 'libB.dart' as pref; |
| 411 import 'libC.dart' as pref; |
| 412 ''' |
| 413 }); |
| 414 var libraryResultB = _buildLibraryElement({ |
| 415 '/libB.dart': ''' |
| 416 library libB; |
| 417 ''' |
| 418 }); |
| 419 var libraryResultC = _buildLibraryElement({ |
| 420 '/libC.dart': ''' |
| 421 library libC; |
| 422 ''' |
| 423 }); |
| 424 // perform task |
| 425 BuildDirectiveElementsTask task = |
| 426 new BuildDirectiveElementsTask(context, libraryResultA.librarySource); |
| 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 |
| 443 CompilationUnit libraryUnitA = outputs[RESOLVED_UNIT3]; |
| 444 // validate directives |
| 445 { |
| 446 ImportDirective importNodeB = libraryUnitA.directives[1]; |
| 447 SimpleIdentifier prefixNodeB = importNodeB.prefix; |
| 448 ImportElement importElementB = importNodeB.element; |
| 449 PrefixElement prefixElement = importElementB.prefix; |
| 450 expect(importElementB, isNotNull); |
| 451 expect(importElementB.importedLibrary, libraryResultB.libraryElement); |
| 452 expect(prefixElement, isNotNull); |
| 453 // TODO(scheglov) remove "prefixOffset" |
| 454 expect(importElementB.prefixOffset, prefixElement.nameOffset); |
| 455 expect(prefixNodeB.staticElement, prefixElement); |
| 456 // PrefixElement "pref" is shared |
| 457 ImportDirective importNodeC = libraryUnitA.directives[2]; |
| 458 SimpleIdentifier prefixNodeC = importNodeC.prefix; |
| 459 ImportElement importElementC = importNodeC.element; |
| 460 expect(prefixNodeC.staticElement, prefixElement); |
| 461 expect(importElementC.prefix, prefixElement); |
| 462 } |
| 463 } |
| 464 |
| 465 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| 466 _fillErrorListener(BUILD_DIRECTIVES_ERRORS); |
| 467 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 468 } |
| 469 |
| 470 Source _newSource(String path, [String content = '']) { |
| 471 File file = resourceProvider.newFile(path, content); |
| 472 return file.createSource(); |
| 473 } |
| 474 } |
| 475 |
| 476 @reflectiveTest |
| 128 class BuildLibraryElementTaskTest extends _AbstractDartTaskTest { | 477 class BuildLibraryElementTaskTest extends _AbstractDartTaskTest { |
| 129 Source librarySource; | 478 Source librarySource; |
| 130 CompilationUnit libraryUnit; | 479 CompilationUnit libraryUnit; |
| 131 CompilationUnitElement libraryUnitElement; | 480 CompilationUnitElement libraryUnitElement; |
| 132 List<CompilationUnit> partUnits; | 481 List<CompilationUnit> partUnits; |
| 133 | 482 |
| 134 LibraryElement libraryElement; | 483 LibraryElement libraryElement; |
| 135 | 484 |
| 136 test_buildInputs() { | 485 test_buildInputs() { |
| 137 ExtendedAnalysisContext context = new _MockContext(); | 486 ExtendedAnalysisContext context = new _MockContext(); |
| 138 // prepare sources | 487 // prepare sources |
| 139 File libraryFile = resourceProvider.newFile('/lib.dart', ''); | 488 File libraryFile = resourceProvider.newFile('/lib.dart', ''); |
| 140 File partFile1 = resourceProvider.newFile('/part1.dart', ''); | 489 File partFile1 = resourceProvider.newFile('/part1.dart', ''); |
| 141 File partFile2 = resourceProvider.newFile('/part2.dart', ''); | 490 File partFile2 = resourceProvider.newFile('/part2.dart', ''); |
| 142 Source librarySource = libraryFile.createSource(); | 491 Source librarySource = libraryFile.createSource(); |
| 143 Source partSource1 = partFile1.createSource(); | 492 Source partSource1 = partFile1.createSource(); |
| 144 Source partSource2 = partFile2.createSource(); | 493 Source partSource2 = partFile2.createSource(); |
| 145 // set INCLUDED_PARTS | 494 // set INCLUDED_PARTS |
| 146 context.getCacheEntry(librarySource).setValue( | 495 context.getCacheEntry(librarySource).setValue( |
| 147 INCLUDED_PARTS, <Source>[partSource1, partSource2]); | 496 INCLUDED_PARTS, <Source>[partSource1, partSource2]); |
| 148 // set BUILT_UNIT | 497 // set BUILT_UNIT |
| 149 CompilationUnit libraryUnit = AstFactory.compilationUnit(); | 498 CompilationUnit libraryUnit = AstFactory.compilationUnit(); |
| 150 CompilationUnit partUnit1 = AstFactory.compilationUnit(); | 499 CompilationUnit partUnit1 = AstFactory.compilationUnit(); |
| 151 CompilationUnit partUnit2 = AstFactory.compilationUnit(); | 500 CompilationUnit partUnit2 = AstFactory.compilationUnit(); |
| 152 context.getCacheEntry(librarySource).setValue(BUILT_UNIT, libraryUnit); | 501 context.getCacheEntry(librarySource).setValue(RESOLVED_UNIT1, libraryUnit); |
| 153 context.getCacheEntry(partSource1).setValue(BUILT_UNIT, partUnit1); | 502 context.getCacheEntry(partSource1).setValue(RESOLVED_UNIT1, partUnit1); |
| 154 context.getCacheEntry(partSource2).setValue(BUILT_UNIT, partUnit2); | 503 context.getCacheEntry(partSource2).setValue(RESOLVED_UNIT1, partUnit2); |
| 155 // request inputs | 504 // request inputs |
| 156 WorkItem workItem = new WorkItem( | 505 WorkItem workItem = new WorkItem( |
| 157 context, librarySource, BuildLibraryElementTask.DESCRIPTOR); | 506 context, librarySource, BuildLibraryElementTask.DESCRIPTOR); |
| 158 workItem.gatherInputs(null); | 507 workItem.gatherInputs(null); |
| 159 Map<String, dynamic> inputs = workItem.inputs; | 508 Map<String, dynamic> inputs = workItem.inputs; |
| 160 expect(inputs, hasLength(2)); | 509 expect(inputs, hasLength(2)); |
| 161 expect(inputs[BuildLibraryElementTask.DEFINING_BUILT_UNIT_INPUT_NAME], | 510 expect(inputs[BuildLibraryElementTask.DEFINING_RESOLVER_UNIT1_INPUT_NAME], |
| 162 libraryUnit); | 511 libraryUnit); |
| 163 expect(inputs[BuildLibraryElementTask.PART_BUILT_UNITS_INPUT_NAME], | 512 expect(inputs[BuildLibraryElementTask.PARTS_RESOLVED_UNIT1_INPUT_NAME], |
| 164 unorderedEquals([partUnit1, partUnit2])); | 513 unorderedEquals([partUnit1, partUnit2])); |
| 165 } | 514 } |
| 166 | 515 |
| 167 test_constructor() { | 516 test_constructor() { |
| 168 AnalysisTarget target = new TestSource(); | 517 AnalysisTarget target = new TestSource(); |
| 169 BuildLibraryElementTask task = new BuildLibraryElementTask(context, target); | 518 BuildLibraryElementTask task = new BuildLibraryElementTask(context, target); |
| 170 expect(task, isNotNull); | 519 expect(task, isNotNull); |
| 171 expect(task.context, context); | 520 expect(task.context, context); |
| 172 expect(task.target, target); | 521 expect(task.target, target); |
| 173 } | 522 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 199 part 'part1.dart'; | 548 part 'part1.dart'; |
| 200 part 'part2.dart'; | 549 part 'part2.dart'; |
| 201 ''', | 550 ''', |
| 202 '/part1.dart': ''' | 551 '/part1.dart': ''' |
| 203 part of lib; | 552 part of lib; |
| 204 ''', | 553 ''', |
| 205 '/part2.dart': ''' | 554 '/part2.dart': ''' |
| 206 part of lib; | 555 part of lib; |
| 207 ''' | 556 ''' |
| 208 }); | 557 }); |
| 209 expect(task.caughtException, isNull); | 558 expect(outputs, hasLength(5)); |
| 210 expect(outputs, hasLength(4)); | |
| 211 // simple outputs | 559 // simple outputs |
| 212 expect(outputs[BUILD_LIBRARY_ERRORS], isEmpty); | 560 expect(outputs[BUILD_LIBRARY_ERRORS], isEmpty); |
| 561 expect(outputs[RESOLVED_UNIT2], same(libraryUnit)); |
| 213 expect(outputs[IS_LAUNCHABLE], isFalse); | 562 expect(outputs[IS_LAUNCHABLE], isFalse); |
| 214 expect(outputs[HAS_HTML_IMPORT], isFalse); | 563 expect(outputs[HAS_HTML_IMPORT], isFalse); |
| 215 // LibraryElement output | 564 // LibraryElement output |
| 216 expect(libraryElement, isNotNull); | 565 expect(libraryElement, isNotNull); |
| 217 expect(libraryElement.entryPoint, isNull); | 566 expect(libraryElement.entryPoint, isNull); |
| 218 expect(libraryElement.source, same(librarySource)); | 567 expect(libraryElement.source, same(librarySource)); |
| 219 expect(libraryElement.definingCompilationUnit, libraryUnitElement); | 568 expect(libraryElement.definingCompilationUnit, libraryUnitElement); |
| 220 expect(libraryElement.parts, | 569 expect(libraryElement.parts, |
| 221 unorderedEquals([partUnits[0].element, partUnits[1].element])); | 570 unorderedEquals([partUnits[0].element, partUnits[1].element])); |
| 222 // LibraryElement references | 571 // LibraryElement references |
| (...skipping 24 matching lines...) Expand all Loading... |
| 247 | 596 |
| 248 test_perform_error_missingLibraryDirectiveWithPart() { | 597 test_perform_error_missingLibraryDirectiveWithPart() { |
| 249 _performBuildTask({ | 598 _performBuildTask({ |
| 250 '/lib.dart': ''' | 599 '/lib.dart': ''' |
| 251 part 'part.dart'; | 600 part 'part.dart'; |
| 252 ''', | 601 ''', |
| 253 '/part.dart': ''' | 602 '/part.dart': ''' |
| 254 part of lib; | 603 part of lib; |
| 255 ''' | 604 ''' |
| 256 }); | 605 }); |
| 257 expect(task.caughtException, isNull); | |
| 258 _assertErrorsWithCodes( | 606 _assertErrorsWithCodes( |
| 259 [ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART]); | 607 [ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART]); |
| 260 } | 608 } |
| 261 | 609 |
| 262 test_perform_error_partOfDifferentLibrary() { | 610 test_perform_error_partOfDifferentLibrary() { |
| 263 _performBuildTask({ | 611 _performBuildTask({ |
| 264 '/lib.dart': ''' | 612 '/lib.dart': ''' |
| 265 library lib; | 613 library lib; |
| 266 part 'part.dart'; | 614 part 'part.dart'; |
| 267 ''', | 615 ''', |
| 268 '/part.dart': ''' | 616 '/part.dart': ''' |
| 269 part of someOtherLib; | 617 part of someOtherLib; |
| 270 ''' | 618 ''' |
| 271 }); | 619 }); |
| 272 expect(task.caughtException, isNull); | |
| 273 _assertErrorsWithCodes([StaticWarningCode.PART_OF_DIFFERENT_LIBRARY]); | 620 _assertErrorsWithCodes([StaticWarningCode.PART_OF_DIFFERENT_LIBRARY]); |
| 274 } | 621 } |
| 275 | 622 |
| 276 test_perform_error_partOfNonPart() { | 623 test_perform_error_partOfNonPart() { |
| 277 _performBuildTask({ | 624 _performBuildTask({ |
| 278 '/lib.dart': ''' | 625 '/lib.dart': ''' |
| 279 library lib; | 626 library lib; |
| 280 part 'part.dart'; | 627 part 'part.dart'; |
| 281 ''', | 628 ''', |
| 282 '/part.dart': ''' | 629 '/part.dart': ''' |
| 283 // no part of | 630 // no part of |
| 284 ''' | 631 ''' |
| 285 }); | 632 }); |
| 286 expect(task.caughtException, isNull); | |
| 287 _assertErrorsWithCodes([CompileTimeErrorCode.PART_OF_NON_PART]); | 633 _assertErrorsWithCodes([CompileTimeErrorCode.PART_OF_NON_PART]); |
| 288 } | 634 } |
| 289 | 635 |
| 290 test_perform_hasHtmlImport() { | 636 test_perform_hasHtmlImport() { |
| 291 _performBuildTask({ | 637 _performBuildTask({ |
| 292 '/lib.dart': ''' | 638 '/lib.dart': ''' |
| 293 import 'dart:html'; | 639 import 'dart:html'; |
| 294 ''' | 640 ''' |
| 295 }); | 641 }); |
| 296 expect(outputs[HAS_HTML_IMPORT], isTrue); | 642 expect(outputs[HAS_HTML_IMPORT], isTrue); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 PropertyInducingElement variable = getter.variable; | 693 PropertyInducingElement variable = getter.variable; |
| 348 expect(getter.isGetter, isTrue); | 694 expect(getter.isGetter, isTrue); |
| 349 expect(setter.isSetter, isTrue); | 695 expect(setter.isSetter, isTrue); |
| 350 expect(variable, isNotNull); | 696 expect(variable, isNotNull); |
| 351 expect(setter.variable, same(variable)); | 697 expect(setter.variable, same(variable)); |
| 352 expect(unitElement1.topLevelVariables, [variable]); | 698 expect(unitElement1.topLevelVariables, [variable]); |
| 353 expect(unitElement2.topLevelVariables, [variable]); | 699 expect(unitElement2.topLevelVariables, [variable]); |
| 354 } | 700 } |
| 355 | 701 |
| 356 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { | 702 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| 357 List<AnalysisError> errors = outputs[BUILD_LIBRARY_ERRORS]; | 703 _fillErrorListener(BUILD_LIBRARY_ERRORS); |
| 358 GatheringErrorListener errorListener = new GatheringErrorListener(); | |
| 359 errorListener.addAll(errors); | |
| 360 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 704 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 361 } | 705 } |
| 362 | 706 |
| 363 void _performBuildTask(Map<String, String> sourceMap) { | 707 void _performBuildTask(Map<String, String> sourceMap) { |
| 364 _BuildLibraryElementTaskResult result = _buildLibraryElement(sourceMap); | 708 _BuildLibraryElementTaskResult result = _buildLibraryElement(sourceMap); |
| 365 Map<String, CompilationUnit> unitMap = <String, CompilationUnit>{}; | 709 Map<String, CompilationUnit> unitMap = <String, CompilationUnit>{}; |
| 366 sourceMap.forEach((String path, String content) { | 710 sourceMap.forEach((String path, String content) { |
| 367 CompilationUnit unit = _buildCompilationUnit(path, content); | 711 CompilationUnit unit = _buildCompilationUnit(path, content); |
| 368 unitMap[path] = unit; | 712 unitMap[path] = unit; |
| 369 }); | 713 }); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 test_descriptor() { | 833 test_descriptor() { |
| 490 TaskDescriptor descriptor = ParseDartTask.DESCRIPTOR; | 834 TaskDescriptor descriptor = ParseDartTask.DESCRIPTOR; |
| 491 expect(descriptor, isNotNull); | 835 expect(descriptor, isNotNull); |
| 492 } | 836 } |
| 493 | 837 |
| 494 test_perform() { | 838 test_perform() { |
| 495 ParseDartTask task = _performParseTask(r''' | 839 ParseDartTask task = _performParseTask(r''' |
| 496 part of lib; | 840 part of lib; |
| 497 class B {}'''); | 841 class B {}'''); |
| 498 | 842 |
| 499 expect(task.caughtException, isNull); | |
| 500 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; | 843 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; |
| 501 expect(outputs, hasLength(6)); | 844 expect(outputs, hasLength(6)); |
| 502 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 845 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 503 expect(outputs[IMPORTED_LIBRARIES], hasLength(0)); | 846 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 504 expect(outputs[INCLUDED_PARTS], hasLength(0)); | 847 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 505 expect(outputs[PARSE_ERRORS], hasLength(0)); | 848 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 506 expect(outputs[PARSED_UNIT], isNotNull); | 849 expect(outputs[PARSED_UNIT], isNotNull); |
| 507 expect(outputs[SOURCE_KIND], SourceKind.PART); | 850 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 508 } | 851 } |
| 509 | 852 |
| 510 test_perform_invalidDirectives() { | 853 test_perform_invalidDirectives() { |
| 511 ParseDartTask task = _performParseTask(r''' | 854 ParseDartTask task = _performParseTask(r''' |
| 512 library lib; | 855 library lib; |
| 513 import '/does/not/exist.dart'; | 856 import '/does/not/exist.dart'; |
| 514 import '://invaliduri.dart'; | 857 import '://invaliduri.dart'; |
| 515 export '${a}lib3.dart'; | 858 export '${a}lib3.dart'; |
| 516 part 'part.dart'; | 859 part 'part.dart'; |
| 517 class A {}'''); | 860 class A {}'''); |
| 518 | 861 |
| 519 expect(task.caughtException, isNull); | |
| 520 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; | 862 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; |
| 521 expect(outputs, hasLength(6)); | 863 expect(outputs, hasLength(6)); |
| 522 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 864 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 523 expect(outputs[IMPORTED_LIBRARIES], hasLength(1)); | 865 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 524 expect(outputs[INCLUDED_PARTS], hasLength(1)); | 866 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 525 expect(outputs[PARSE_ERRORS], hasLength(2)); | 867 expect(outputs[PARSE_ERRORS], hasLength(2)); |
| 526 expect(outputs[PARSED_UNIT], isNotNull); | 868 expect(outputs[PARSED_UNIT], isNotNull); |
| 527 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 869 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 528 } | 870 } |
| 529 | 871 |
| 530 test_perform_library() { | 872 test_perform_library() { |
| 531 ParseDartTask task = _performParseTask(r''' | 873 ParseDartTask task = _performParseTask(r''' |
| 532 library lib; | 874 library lib; |
| 533 import 'lib2.dart'; | 875 import 'lib2.dart'; |
| 534 export 'lib3.dart'; | 876 export 'lib3.dart'; |
| 535 part 'part.dart'; | 877 part 'part.dart'; |
| 536 class A {'''); | 878 class A {'''); |
| 537 | |
| 538 expect(task.caughtException, isNull); | |
| 539 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; | 879 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; |
| 540 expect(outputs, hasLength(6)); | 880 expect(outputs, hasLength(6)); |
| 541 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); | 881 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); |
| 542 expect(outputs[IMPORTED_LIBRARIES], hasLength(1)); | 882 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 543 expect(outputs[INCLUDED_PARTS], hasLength(1)); | 883 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 544 expect(outputs[PARSE_ERRORS], hasLength(1)); | 884 expect(outputs[PARSE_ERRORS], hasLength(1)); |
| 545 expect(outputs[PARSED_UNIT], isNotNull); | 885 expect(outputs[PARSED_UNIT], isNotNull); |
| 546 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 886 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 547 } | 887 } |
| 548 | 888 |
| 549 ParseDartTask _performParseTask(String content) { | 889 ParseDartTask _performParseTask(String content) { |
| 550 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 890 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 551 AnalysisTarget target = new TestSource(); | 891 AnalysisTarget target = new TestSource(); |
| 552 | 892 |
| 553 ScanDartTask scanTask = new ScanDartTask(context, target); | 893 ScanDartTask scanTask = new ScanDartTask(context, target); |
| 554 scanTask.inputs = {ScanDartTask.CONTENT_INPUT_NAME: content}; | 894 scanTask.inputs = {ScanDartTask.CONTENT_INPUT_NAME: content}; |
| 555 scanTask.perform(); | 895 scanTask.perform(); |
| 556 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; | 896 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; |
| 557 | 897 |
| 558 ParseDartTask parseTask = new ParseDartTask(context, target); | 898 ParseDartTask parseTask = new ParseDartTask(context, target); |
| 559 parseTask.inputs = { | 899 parseTask.inputs = { |
| 560 ParseDartTask.LINE_INFO_INPUT_NAME: scanOutputs[LINE_INFO], | 900 ParseDartTask.LINE_INFO_INPUT_NAME: scanOutputs[LINE_INFO], |
| 561 ParseDartTask.TOKEN_STREAM_INPUT_NAME: scanOutputs[TOKEN_STREAM] | 901 ParseDartTask.TOKEN_STREAM_INPUT_NAME: scanOutputs[TOKEN_STREAM] |
| 562 }; | 902 }; |
| 563 parseTask.perform(); | 903 parseTask.perform(); |
| 564 return parseTask; | 904 return parseTask; |
| 565 } | 905 } |
| 906 |
| 907 static void _assertHasCore(List<Source> sources, int lenght) { |
| 908 expect(sources, hasLength(lenght)); |
| 909 expect(sources, contains(predicate((Source s) { |
| 910 return s.fullName.endsWith('core.dart'); |
| 911 }))); |
| 912 } |
| 566 } | 913 } |
| 567 | 914 |
| 568 @reflectiveTest | 915 @reflectiveTest |
| 569 class ScanDartTaskTest extends EngineTestCase { | 916 class ScanDartTaskTest extends EngineTestCase { |
| 570 test_buildInputs() { | 917 test_buildInputs() { |
| 571 AnalysisTarget target = new TestSource(); | 918 AnalysisTarget target = new TestSource(); |
| 572 Map<String, TaskInput> inputs = ScanDartTask.buildInputs(target); | 919 Map<String, TaskInput> inputs = ScanDartTask.buildInputs(target); |
| 573 expect(inputs, isNotNull); | 920 expect(inputs, isNotNull); |
| 574 expect(inputs.keys, unorderedEquals([ScanDartTask.CONTENT_INPUT_NAME])); | 921 expect(inputs.keys, unorderedEquals([ScanDartTask.CONTENT_INPUT_NAME])); |
| 575 } | 922 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 } | 984 } |
| 638 | 985 |
| 639 class _AbstractDartTaskTest extends EngineTestCase { | 986 class _AbstractDartTaskTest extends EngineTestCase { |
| 640 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); | 987 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 641 | 988 |
| 642 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 989 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 643 Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{}; | 990 Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{}; |
| 644 | 991 |
| 645 AnalysisTask task; | 992 AnalysisTask task; |
| 646 Map<ResultDescriptor<dynamic>, dynamic> outputs; | 993 Map<ResultDescriptor<dynamic>, dynamic> outputs; |
| 994 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 647 | 995 |
| 648 CacheEntry getCacheEntry(AnalysisTarget target) { | 996 CacheEntry getCacheEntry(AnalysisTarget target) { |
| 649 return entryMap.putIfAbsent(target, () => new CacheEntry()); | 997 return entryMap.putIfAbsent(target, () => new CacheEntry()); |
| 650 } | 998 } |
| 651 | 999 |
| 652 void setUp() { | 1000 void setUp() { |
| 653 DartSdk sdk = context.sourceFactory.dartSdk; | 1001 DartSdk sdk = context.sourceFactory.dartSdk; |
| 654 context.sourceFactory = new SourceFactory(<UriResolver>[ | 1002 context.sourceFactory = new SourceFactory(<UriResolver>[ |
| 655 new DartUriResolver(sdk), | 1003 new DartUriResolver(sdk), |
| 656 new ResourceUriResolver(resourceProvider) | 1004 new ResourceUriResolver(resourceProvider) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 673 var parseOutputs = _performTask(parseTask); | 1021 var parseOutputs = _performTask(parseTask); |
| 674 // build CompilationUnit | 1022 // build CompilationUnit |
| 675 BuildCompilationUnitElementTask buildTask = | 1023 BuildCompilationUnitElementTask buildTask = |
| 676 new BuildCompilationUnitElementTask(context, source); | 1024 new BuildCompilationUnitElementTask(context, source); |
| 677 buildTask.inputs = { | 1025 buildTask.inputs = { |
| 678 BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME: | 1026 BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME: |
| 679 parseOutputs[PARSED_UNIT] | 1027 parseOutputs[PARSED_UNIT] |
| 680 }; | 1028 }; |
| 681 var buildUnitOutputs = _performTask(buildTask); | 1029 var buildUnitOutputs = _performTask(buildTask); |
| 682 // done | 1030 // done |
| 683 return buildUnitOutputs[BUILT_UNIT]; | 1031 return buildUnitOutputs[RESOLVED_UNIT1]; |
| 684 } | 1032 } |
| 685 | 1033 |
| 686 _BuildLibraryElementTaskResult _buildLibraryElement( | 1034 _BuildLibraryElementTaskResult _buildLibraryElement( |
| 687 Map<String, String> sourceMap) { | 1035 Map<String, String> sourceMap) { |
| 688 Map<String, CompilationUnit> unitMap = <String, CompilationUnit>{}; | 1036 Map<String, CompilationUnit> unitMap = <String, CompilationUnit>{}; |
| 689 sourceMap.forEach((String path, String content) { | 1037 sourceMap.forEach((String path, String content) { |
| 690 CompilationUnit unit = _buildCompilationUnit(path, content); | 1038 CompilationUnit unit = _buildCompilationUnit(path, content); |
| 691 unitMap[path] = unit; | 1039 unitMap[path] = unit; |
| 692 }); | 1040 }); |
| 693 | 1041 |
| 694 CompilationUnit libraryUnit = unitMap.values.first; | 1042 CompilationUnit libraryUnit = unitMap.values.first; |
| 695 CompilationUnitElement libraryUnitElement = libraryUnit.element; | 1043 CompilationUnitElement libraryUnitElement = libraryUnit.element; |
| 696 Source librarySource = libraryUnitElement.source; | 1044 Source librarySource = libraryUnitElement.source; |
| 697 List<CompilationUnit> partUnits = unitMap.values.skip(1).toList(); | 1045 List<CompilationUnit> partUnits = unitMap.values.skip(1).toList(); |
| 698 | 1046 |
| 699 BuildLibraryElementTask task = | 1047 BuildLibraryElementTask task = |
| 700 new BuildLibraryElementTask(context, librarySource); | 1048 new BuildLibraryElementTask(context, librarySource); |
| 701 task.inputs = { | 1049 task.inputs = { |
| 702 BuildLibraryElementTask.DEFINING_BUILT_UNIT_INPUT_NAME: libraryUnit, | 1050 BuildLibraryElementTask.DEFINING_RESOLVER_UNIT1_INPUT_NAME: libraryUnit, |
| 703 BuildLibraryElementTask.PART_BUILT_UNITS_INPUT_NAME: partUnits | 1051 BuildLibraryElementTask.PARTS_RESOLVED_UNIT1_INPUT_NAME: partUnits |
| 704 }; | 1052 }; |
| 705 Map<ResultDescriptor, dynamic> outputs = _performTask(task); | 1053 Map<ResultDescriptor, dynamic> outputs = _performTask(task); |
| 706 | 1054 |
| 707 LibraryElement libraryElement = outputs[BUILT_LIBRARY_ELEMENT]; | 1055 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT1]; |
| 708 return new _BuildLibraryElementTaskResult(librarySource, libraryUnit, | 1056 return new _BuildLibraryElementTaskResult(librarySource, libraryUnit, |
| 709 libraryUnitElement, partUnits, task, outputs, libraryElement); | 1057 libraryUnitElement, partUnits, task, outputs, libraryElement); |
| 710 } | 1058 } |
| 711 | 1059 |
| 712 /** | 1060 /** |
| 1061 * Fill [errorListener] with [result] errors in the current [task]. |
| 1062 */ |
| 1063 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 1064 List<AnalysisError> errors = task.outputs[result]; |
| 1065 expect(errors, isNotNull, reason: result.name); |
| 1066 errorListener = new GatheringErrorListener(); |
| 1067 errorListener.addAll(errors); |
| 1068 } |
| 1069 |
| 1070 /** |
| 713 * Perform the given [task], record and return its outputs. | 1071 * Perform the given [task], record and return its outputs. |
| 714 */ | 1072 */ |
| 715 Map<ResultDescriptor, dynamic> _performTask(AnalysisTask task) { | 1073 Map<ResultDescriptor, dynamic> _performTask(AnalysisTask task) { |
| 1074 this.task = task; |
| 716 AnalysisTarget target = task.target; | 1075 AnalysisTarget target = task.target; |
| 717 // perform the task | 1076 // perform the task |
| 718 task.perform(); | 1077 task.perform(); |
| 719 Map<ResultDescriptor, dynamic> outputs = task.outputs; | 1078 expect(task.caughtException, isNull); |
| 1079 outputs = task.outputs; |
| 720 // file the cache entry | 1080 // file the cache entry |
| 721 CacheEntry cacheEntry = getCacheEntry(target); | 1081 CacheEntry cacheEntry = getCacheEntry(target); |
| 722 outputs.forEach((result, value) { | 1082 outputs.forEach((result, value) { |
| 723 cacheEntry.setValue(result, value); | 1083 cacheEntry.setValue(result, value); |
| 724 }); | 1084 }); |
| 725 return outputs; | 1085 return outputs; |
| 726 } | 1086 } |
| 727 } | 1087 } |
| 728 | 1088 |
| 729 class _BuildLibraryElementTaskResult { | 1089 class _BuildLibraryElementTaskResult { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 742 class _MockContext extends TypedMock implements ExtendedAnalysisContext { | 1102 class _MockContext extends TypedMock implements ExtendedAnalysisContext { |
| 743 Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{}; | 1103 Map<AnalysisTarget, CacheEntry> entryMap = <AnalysisTarget, CacheEntry>{}; |
| 744 | 1104 |
| 745 @override | 1105 @override |
| 746 CacheEntry getCacheEntry(AnalysisTarget target) { | 1106 CacheEntry getCacheEntry(AnalysisTarget target) { |
| 747 return entryMap.putIfAbsent(target, () => new CacheEntry()); | 1107 return entryMap.putIfAbsent(target, () => new CacheEntry()); |
| 748 } | 1108 } |
| 749 | 1109 |
| 750 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1110 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 751 } | 1111 } |
| OLD | NEW |