| 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/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/constant.dart'; | 9 import 'package:analyzer/src/generated/constant.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 import '../../generated/test_support.dart'; | 25 import '../../generated/test_support.dart'; |
| 26 import '../../reflective_tests.dart'; | 26 import '../../reflective_tests.dart'; |
| 27 import '../../utils.dart'; | 27 import '../../utils.dart'; |
| 28 import '../context/abstract_context.dart'; | 28 import '../context/abstract_context.dart'; |
| 29 | 29 |
| 30 main() { | 30 main() { |
| 31 initializeTestEnvironment(); | 31 initializeTestEnvironment(); |
| 32 runReflectiveTests(BuildCompilationUnitElementTaskTest); | 32 runReflectiveTests(BuildCompilationUnitElementTaskTest); |
| 33 runReflectiveTests(BuildDirectiveElementsTaskTest); | 33 runReflectiveTests(BuildDirectiveElementsTaskTest); |
| 34 runReflectiveTests(BuildEnumMemberElementsTaskTest); | 34 runReflectiveTests(BuildEnumMemberElementsTaskTest); |
| 35 runReflectiveTests(BuildSourceExportClosureTaskTest); | |
| 36 runReflectiveTests(BuildSourceImportExportClosureTaskTest); | |
| 37 runReflectiveTests(BuildExportNamespaceTaskTest); | 35 runReflectiveTests(BuildExportNamespaceTaskTest); |
| 38 runReflectiveTests(BuildLibraryElementTaskTest); | 36 runReflectiveTests(BuildLibraryElementTaskTest); |
| 39 runReflectiveTests(BuildPublicNamespaceTaskTest); | 37 runReflectiveTests(BuildPublicNamespaceTaskTest); |
| 38 runReflectiveTests(BuildSourceExportClosureTaskTest); |
| 39 runReflectiveTests(BuildSourceImportExportClosureTaskTest); |
| 40 runReflectiveTests(BuildTypeProviderTaskTest); | 40 runReflectiveTests(BuildTypeProviderTaskTest); |
| 41 runReflectiveTests(ComputeConstantDependenciesTaskTest); | 41 runReflectiveTests(ComputeConstantDependenciesTaskTest); |
| 42 runReflectiveTests(ComputeConstantValueTaskTest); | 42 runReflectiveTests(ComputeConstantValueTaskTest); |
| 43 runReflectiveTests(ComputeInferableStaticVariableDependenciesTaskTest); | 43 runReflectiveTests(ComputeInferableStaticVariableDependenciesTaskTest); |
| 44 runReflectiveTests(ContainingLibrariesTaskTest); | 44 runReflectiveTests(ContainingLibrariesTaskTest); |
| 45 runReflectiveTests(DartErrorsTaskTest); | 45 runReflectiveTests(DartErrorsTaskTest); |
| 46 runReflectiveTests(EvaluateUnitConstantsTaskTest); | 46 runReflectiveTests(EvaluateUnitConstantsTaskTest); |
| 47 runReflectiveTests(GatherUsedImportedElementsTaskTest); | 47 runReflectiveTests(GatherUsedImportedElementsTaskTest); |
| 48 runReflectiveTests(GatherUsedLocalElementsTaskTest); | 48 runReflectiveTests(GatherUsedLocalElementsTaskTest); |
| 49 runReflectiveTests(GenerateHintsTaskTest); | 49 runReflectiveTests(GenerateHintsTaskTest); |
| 50 runReflectiveTests(InferInstanceMembersInUnitTaskTest); | 50 runReflectiveTests(InferInstanceMembersInUnitTaskTest); |
| 51 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest); | 51 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest); |
| 52 runReflectiveTests(InferStaticVariableTypeTaskTest); | 52 runReflectiveTests(InferStaticVariableTypeTaskTest); |
| 53 runReflectiveTests(LibraryErrorsReadyTaskTest); | 53 runReflectiveTests(LibraryErrorsReadyTaskTest); |
| 54 runReflectiveTests(LibraryUnitErrorsTaskTest); | 54 runReflectiveTests(LibraryUnitErrorsTaskTest); |
| 55 runReflectiveTests(ParseDartTaskTest); | 55 runReflectiveTests(ParseDartTaskTest); |
| 56 runReflectiveTests(PartiallyResolveReferencesTaskTest); | 56 runReflectiveTests(PartiallyResolveUnitReferencesTaskTest); |
| 57 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); |
| 58 runReflectiveTests(ResolveUnitReferencesTaskTest); |
| 57 runReflectiveTests(ResolveUnitTypeNamesTaskTest); | 59 runReflectiveTests(ResolveUnitTypeNamesTaskTest); |
| 58 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); | |
| 59 runReflectiveTests(ResolveReferencesTaskTest); | |
| 60 runReflectiveTests(ResolveVariableReferencesTaskTest); | 60 runReflectiveTests(ResolveVariableReferencesTaskTest); |
| 61 runReflectiveTests(ScanDartTaskTest); | 61 runReflectiveTests(ScanDartTaskTest); |
| 62 runReflectiveTests(VerifyUnitTaskTest); | 62 runReflectiveTests(VerifyUnitTaskTest); |
| 63 } | 63 } |
| 64 | 64 |
| 65 isInstanceOf isBuildCompilationUnitElementTask = |
| 66 new isInstanceOf<BuildCompilationUnitElementTask>(); |
| 67 isInstanceOf isBuildDirectiveElementsTask = |
| 68 new isInstanceOf<BuildDirectiveElementsTask>(); |
| 69 isInstanceOf isBuildEnumMemberElementsTask = |
| 70 new isInstanceOf<BuildEnumMemberElementsTask>(); |
| 71 isInstanceOf isBuildExportNamespaceTask = |
| 72 new isInstanceOf<BuildExportNamespaceTask>(); |
| 73 isInstanceOf isBuildLibraryElementTask = |
| 74 new isInstanceOf<BuildLibraryElementTask>(); |
| 75 isInstanceOf isBuildPublicNamespaceTask = |
| 76 new isInstanceOf<BuildPublicNamespaceTask>(); |
| 77 isInstanceOf isBuildSourceExportClosureTask = |
| 78 new isInstanceOf<BuildSourceExportClosureTask>(); |
| 79 isInstanceOf isBuildSourceImportExportClosureTask = |
| 80 new isInstanceOf<BuildSourceImportExportClosureTask>(); |
| 81 isInstanceOf isBuildTypeProviderTask = |
| 82 new isInstanceOf<BuildTypeProviderTask>(); |
| 83 isInstanceOf isComputeConstantDependenciesTask = |
| 84 new isInstanceOf<ComputeConstantDependenciesTask>(); |
| 85 isInstanceOf isComputeConstantValueTask = |
| 86 new isInstanceOf<ComputeConstantValueTask>(); |
| 87 isInstanceOf isComputeInferableStaticVariableDependenciesTask = |
| 88 new isInstanceOf<ComputeInferableStaticVariableDependenciesTask>(); |
| 89 isInstanceOf isContainingLibrariesTask = |
| 90 new isInstanceOf<ContainingLibrariesTask>(); |
| 91 isInstanceOf isDartErrorsTask = new isInstanceOf<DartErrorsTask>(); |
| 92 isInstanceOf isEvaluateUnitConstantsTask = |
| 93 new isInstanceOf<EvaluateUnitConstantsTask>(); |
| 94 isInstanceOf isGatherUsedImportedElementsTask = |
| 95 new isInstanceOf<GatherUsedImportedElementsTask>(); |
| 96 isInstanceOf isGatherUsedLocalElementsTask = |
| 97 new isInstanceOf<GatherUsedLocalElementsTask>(); |
| 98 isInstanceOf isGenerateHintsTask = new isInstanceOf<GenerateHintsTask>(); |
| 99 isInstanceOf isInferInstanceMembersInUnitTask = |
| 100 new isInstanceOf<InferInstanceMembersInUnitTask>(); |
| 101 isInstanceOf isInferStaticVariableTypesInUnitTask = |
| 102 new isInstanceOf<InferStaticVariableTypesInUnitTask>(); |
| 103 isInstanceOf isInferStaticVariableTypeTask = |
| 104 new isInstanceOf<InferStaticVariableTypeTask>(); |
| 105 isInstanceOf isLibraryErrorsReadyTask = |
| 106 new isInstanceOf<LibraryErrorsReadyTask>(); |
| 107 isInstanceOf isLibraryUnitErrorsTask = |
| 108 new isInstanceOf<LibraryUnitErrorsTask>(); |
| 109 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>(); |
| 110 isInstanceOf isPartiallyResolveUnitReferencesTask = |
| 111 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); |
| 112 isInstanceOf isResolveLibraryTypeNamesTask = |
| 113 new isInstanceOf<ResolveLibraryTypeNamesTask>(); |
| 114 isInstanceOf isResolveUnitReferencesTask = |
| 115 new isInstanceOf<ResolveUnitReferencesTask>(); |
| 116 isInstanceOf isResolveUnitTypeNamesTask = |
| 117 new isInstanceOf<ResolveUnitTypeNamesTask>(); |
| 118 isInstanceOf isResolveVariableReferencesTask = |
| 119 new isInstanceOf<ResolveVariableReferencesTask>(); |
| 120 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>(); |
| 121 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>(); |
| 122 |
| 65 @reflectiveTest | 123 @reflectiveTest |
| 66 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { | 124 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { |
| 67 Source source; | 125 Source source; |
| 68 LibrarySpecificUnit target; | 126 LibrarySpecificUnit target; |
| 69 | 127 |
| 70 test_buildInputs() { | 128 test_buildInputs() { |
| 71 LibrarySpecificUnit target = | 129 LibrarySpecificUnit target = |
| 72 new LibrarySpecificUnit(emptySource, emptySource); | 130 new LibrarySpecificUnit(emptySource, emptySource); |
| 73 Map<String, TaskInput> inputs = | 131 Map<String, TaskInput> inputs = |
| 74 BuildCompilationUnitElementTask.buildInputs(target); | 132 BuildCompilationUnitElementTask.buildInputs(target); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 class B = Object with A; | 219 class B = Object with A; |
| 162 '''); | 220 '''); |
| 163 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 221 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 164 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT]; | 222 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT]; |
| 165 expect(unit, isNotNull); | 223 expect(unit, isNotNull); |
| 166 expect(unitElement, isNotNull); | 224 expect(unitElement, isNotNull); |
| 167 // invalidate RESOLVED_UNIT1 | 225 // invalidate RESOLVED_UNIT1 |
| 168 CacheEntry cacheEntry = analysisCache.get(target); | 226 CacheEntry cacheEntry = analysisCache.get(target); |
| 169 cacheEntry.setState(RESOLVED_UNIT1, CacheState.INVALID); | 227 cacheEntry.setState(RESOLVED_UNIT1, CacheState.INVALID); |
| 170 // compute again | 228 // compute again |
| 171 computeResult(target, RESOLVED_UNIT1); | 229 computeResult(target, RESOLVED_UNIT1, |
| 230 matcher: isBuildCompilationUnitElementTask); |
| 172 expect(outputs[COMPILATION_UNIT_ELEMENT], same(unitElement)); | 231 expect(outputs[COMPILATION_UNIT_ELEMENT], same(unitElement)); |
| 173 expect(outputs[RESOLVED_UNIT1], isNot(same(unit))); | 232 expect(outputs[RESOLVED_UNIT1], isNot(same(unit))); |
| 174 } | 233 } |
| 175 | 234 |
| 176 void _performBuildTask(String content) { | 235 void _performBuildTask(String content) { |
| 177 source = newSource('/test.dart', content); | 236 source = newSource('/test.dart', content); |
| 178 target = new LibrarySpecificUnit(source, source); | 237 target = new LibrarySpecificUnit(source, source); |
| 179 computeResult(target, RESOLVED_UNIT1); | 238 computeResult(target, RESOLVED_UNIT1, |
| 180 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>()); | 239 matcher: isBuildCompilationUnitElementTask); |
| 181 } | 240 } |
| 182 } | 241 } |
| 183 | 242 |
| 184 @reflectiveTest | 243 @reflectiveTest |
| 185 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { | 244 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { |
| 186 test_constructor() { | 245 test_constructor() { |
| 187 BuildDirectiveElementsTask task = | 246 BuildDirectiveElementsTask task = |
| 188 new BuildDirectiveElementsTask(context, emptySource); | 247 new BuildDirectiveElementsTask(context, emptySource); |
| 189 expect(task, isNotNull); | 248 expect(task, isNotNull); |
| 190 expect(task.context, context); | 249 expect(task.context, context); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 221 library libB; | 280 library libB; |
| 222 ''', | 281 ''', |
| 223 '/libC.dart': ''' | 282 '/libC.dart': ''' |
| 224 library libC; | 283 library libC; |
| 225 ''' | 284 ''' |
| 226 }); | 285 }); |
| 227 Source sourceA = sources[0]; | 286 Source sourceA = sources[0]; |
| 228 Source sourceB = sources[1]; | 287 Source sourceB = sources[1]; |
| 229 Source sourceC = sources[2]; | 288 Source sourceC = sources[2]; |
| 230 // perform task | 289 // perform task |
| 231 computeResult(sourceA, LIBRARY_ELEMENT2); | 290 computeResult(sourceA, LIBRARY_ELEMENT2, |
| 232 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 291 matcher: isBuildDirectiveElementsTask); |
| 233 // prepare outputs | 292 // prepare outputs |
| 234 LibraryElement libraryElementA = outputs[LIBRARY_ELEMENT2]; | 293 LibraryElement libraryElementA = outputs[LIBRARY_ELEMENT2]; |
| 235 LibraryElement libraryElementB = _getImportLibraryInput(sourceB); | 294 LibraryElement libraryElementB = _getImportLibraryInput(sourceB); |
| 236 LibraryElement libraryElementC = _getExportLibraryInput(sourceC); | 295 LibraryElement libraryElementC = _getExportLibraryInput(sourceC); |
| 237 // no errors | 296 // no errors |
| 238 _assertErrorsWithCodes([]); | 297 _assertErrorsWithCodes([]); |
| 239 // validate directives | 298 // validate directives |
| 240 CompilationUnit libraryUnitA = context | 299 CompilationUnit libraryUnitA = context |
| 241 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) | 300 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) |
| 242 .getValue(RESOLVED_UNIT1); | 301 .getValue(RESOLVED_UNIT1); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 '/libA.dart': ''' | 334 '/libA.dart': ''' |
| 276 library libA; | 335 library libA; |
| 277 import 'libB.dart' show A, B hide C, D; | 336 import 'libB.dart' show A, B hide C, D; |
| 278 ''', | 337 ''', |
| 279 '/libB.dart': ''' | 338 '/libB.dart': ''' |
| 280 library libB; | 339 library libB; |
| 281 ''' | 340 ''' |
| 282 }); | 341 }); |
| 283 Source sourceA = sources[0]; | 342 Source sourceA = sources[0]; |
| 284 // perform task | 343 // perform task |
| 285 computeResult(sourceA, LIBRARY_ELEMENT2); | 344 computeResult(sourceA, LIBRARY_ELEMENT2, |
| 286 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 345 matcher: isBuildDirectiveElementsTask); |
| 287 // prepare outputs | 346 // prepare outputs |
| 288 CompilationUnit libraryUnitA = context | 347 CompilationUnit libraryUnitA = context |
| 289 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) | 348 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) |
| 290 .getValue(RESOLVED_UNIT1); | 349 .getValue(RESOLVED_UNIT1); |
| 291 // no errors | 350 // no errors |
| 292 _assertErrorsWithCodes([]); | 351 _assertErrorsWithCodes([]); |
| 293 // validate directives | 352 // validate directives |
| 294 ImportDirective importNode = libraryUnitA.directives[1]; | 353 ImportDirective importNode = libraryUnitA.directives[1]; |
| 295 ImportElement importElement = importNode.element; | 354 ImportElement importElement = importNode.element; |
| 296 List<NamespaceCombinator> combinators = importElement.combinators; | 355 List<NamespaceCombinator> combinators = importElement.combinators; |
| 297 expect(combinators, hasLength(2)); | 356 expect(combinators, hasLength(2)); |
| 298 { | 357 { |
| 299 ShowElementCombinator combinator = combinators[0]; | 358 ShowElementCombinator combinator = combinators[0]; |
| 300 expect(combinator.offset, 33); | 359 expect(combinator.offset, 33); |
| 301 expect(combinator.end, 42); | 360 expect(combinator.end, 42); |
| 302 expect(combinator.shownNames, ['A', 'B']); | 361 expect(combinator.shownNames, ['A', 'B']); |
| 303 } | 362 } |
| 304 { | 363 { |
| 305 HideElementCombinator combinator = combinators[1]; | 364 HideElementCombinator combinator = combinators[1]; |
| 306 expect(combinator.hiddenNames, ['C', 'D']); | 365 expect(combinator.hiddenNames, ['C', 'D']); |
| 307 } | 366 } |
| 308 } | 367 } |
| 309 | 368 |
| 310 test_perform_dartCoreContext() { | 369 test_perform_dartCoreContext() { |
| 311 List<Source> sources = newSources({'/libA.dart': ''}); | 370 List<Source> sources = newSources({'/libA.dart': ''}); |
| 312 Source source = sources[0]; | 371 Source source = sources[0]; |
| 313 // perform task | 372 // perform task |
| 314 computeResult(source, LIBRARY_ELEMENT2); | 373 computeResult(source, LIBRARY_ELEMENT2, |
| 315 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 374 matcher: isBuildDirectiveElementsTask); |
| 316 // prepare outputs | 375 // prepare outputs |
| 317 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; | 376 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; |
| 318 // verify that dart:core has SDK context | 377 // verify that dart:core has SDK context |
| 319 { | 378 { |
| 320 LibraryElement coreLibrary = libraryElement.importedLibraries[0]; | 379 LibraryElement coreLibrary = libraryElement.importedLibraries[0]; |
| 321 DartSdk dartSdk = context.sourceFactory.dartSdk; | 380 DartSdk dartSdk = context.sourceFactory.dartSdk; |
| 322 expect(coreLibrary.context, same(dartSdk.context)); | 381 expect(coreLibrary.context, same(dartSdk.context)); |
| 323 } | 382 } |
| 324 } | 383 } |
| 325 | 384 |
| 326 test_perform_error_exportOfNonLibrary() { | 385 test_perform_error_exportOfNonLibrary() { |
| 327 List<Source> sources = newSources({ | 386 List<Source> sources = newSources({ |
| 328 '/libA.dart': ''' | 387 '/libA.dart': ''' |
| 329 library libA; | 388 library libA; |
| 330 export 'part.dart'; | 389 export 'part.dart'; |
| 331 ''', | 390 ''', |
| 332 '/part.dart': ''' | 391 '/part.dart': ''' |
| 333 part of notLib; | 392 part of notLib; |
| 334 ''' | 393 ''' |
| 335 }); | 394 }); |
| 336 Source sourceA = sources[0]; | 395 Source sourceA = sources[0]; |
| 337 // perform task | 396 // perform task |
| 338 computeResult(sourceA, LIBRARY_ELEMENT2); | 397 computeResult(sourceA, LIBRARY_ELEMENT2, |
| 339 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 398 matcher: isBuildDirectiveElementsTask); |
| 340 // validate errors | 399 // validate errors |
| 341 _assertErrorsWithCodes([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); | 400 _assertErrorsWithCodes([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); |
| 342 } | 401 } |
| 343 | 402 |
| 344 test_perform_error_importOfNonLibrary() { | 403 test_perform_error_importOfNonLibrary() { |
| 345 List<Source> sources = newSources({ | 404 List<Source> sources = newSources({ |
| 346 '/libA.dart': ''' | 405 '/libA.dart': ''' |
| 347 library libA; | 406 library libA; |
| 348 import 'part.dart'; | 407 import 'part.dart'; |
| 349 ''', | 408 ''', |
| 350 '/part.dart': ''' | 409 '/part.dart': ''' |
| 351 part of notLib; | 410 part of notLib; |
| 352 ''' | 411 ''' |
| 353 }); | 412 }); |
| 354 Source sourceA = sources[0]; | 413 Source sourceA = sources[0]; |
| 355 // perform task | 414 // perform task |
| 356 computeResult(sourceA, LIBRARY_ELEMENT2); | 415 computeResult(sourceA, LIBRARY_ELEMENT2, |
| 357 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 416 matcher: isBuildDirectiveElementsTask); |
| 358 // validate errors | 417 // validate errors |
| 359 _assertErrorsWithCodes([CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); | 418 _assertErrorsWithCodes([CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); |
| 360 } | 419 } |
| 361 | 420 |
| 362 test_perform_explicitDartCoreImport() { | 421 test_perform_explicitDartCoreImport() { |
| 363 List<Source> sources = newSources({ | 422 List<Source> sources = newSources({ |
| 364 '/lib.dart': ''' | 423 '/lib.dart': ''' |
| 365 library lib; | 424 library lib; |
| 366 import 'dart:core' show List; | 425 import 'dart:core' show List; |
| 367 ''' | 426 ''' |
| 368 }); | 427 }); |
| 369 Source source = sources[0]; | 428 Source source = sources[0]; |
| 370 // perform task | 429 // perform task |
| 371 computeResult(source, LIBRARY_ELEMENT2); | 430 computeResult(source, LIBRARY_ELEMENT2, |
| 372 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 431 matcher: isBuildDirectiveElementsTask); |
| 373 // prepare outputs | 432 // prepare outputs |
| 374 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; | 433 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; |
| 375 // has an explicit "dart:core" import | 434 // has an explicit "dart:core" import |
| 376 { | 435 { |
| 377 List<ImportElement> imports = libraryElement.imports; | 436 List<ImportElement> imports = libraryElement.imports; |
| 378 expect(imports, hasLength(1)); | 437 expect(imports, hasLength(1)); |
| 379 expect(imports[0].importedLibrary.isDartCore, isTrue); | 438 expect(imports[0].importedLibrary.isDartCore, isTrue); |
| 380 expect(imports[0].isSynthetic, isFalse); | 439 expect(imports[0].isSynthetic, isFalse); |
| 381 } | 440 } |
| 382 } | 441 } |
| 383 | 442 |
| 384 test_perform_hasExtUri() { | 443 test_perform_hasExtUri() { |
| 385 List<Source> sources = newSources({ | 444 List<Source> sources = newSources({ |
| 386 '/lib.dart': ''' | 445 '/lib.dart': ''' |
| 387 import 'dart-ext:doesNotExist.dart'; | 446 import 'dart-ext:doesNotExist.dart'; |
| 388 ''' | 447 ''' |
| 389 }); | 448 }); |
| 390 Source source = sources[0]; | 449 Source source = sources[0]; |
| 391 // perform task | 450 // perform task |
| 392 computeResult(source, LIBRARY_ELEMENT2); | 451 computeResult(source, LIBRARY_ELEMENT2, |
| 393 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 452 matcher: isBuildDirectiveElementsTask); |
| 394 // prepare outputs | 453 // prepare outputs |
| 395 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; | 454 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; |
| 396 expect(libraryElement.hasExtUri, isTrue); | 455 expect(libraryElement.hasExtUri, isTrue); |
| 397 } | 456 } |
| 398 | 457 |
| 399 test_perform_importPrefix() { | 458 test_perform_importPrefix() { |
| 400 List<Source> sources = newSources({ | 459 List<Source> sources = newSources({ |
| 401 '/libA.dart': ''' | 460 '/libA.dart': ''' |
| 402 library libA; | 461 library libA; |
| 403 import 'libB.dart' as pref; | 462 import 'libB.dart' as pref; |
| 404 import 'libC.dart' as pref; | 463 import 'libC.dart' as pref; |
| 405 ''', | 464 ''', |
| 406 '/libB.dart': ''' | 465 '/libB.dart': ''' |
| 407 library libB; | 466 library libB; |
| 408 ''', | 467 ''', |
| 409 '/libC.dart': ''' | 468 '/libC.dart': ''' |
| 410 library libC; | 469 library libC; |
| 411 ''' | 470 ''' |
| 412 }); | 471 }); |
| 413 Source sourceA = sources[0]; | 472 Source sourceA = sources[0]; |
| 414 Source sourceB = sources[1]; | 473 Source sourceB = sources[1]; |
| 415 // perform task | 474 // perform task |
| 416 computeResult(sourceA, LIBRARY_ELEMENT2); | 475 computeResult(sourceA, LIBRARY_ELEMENT2, |
| 417 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); | 476 matcher: isBuildDirectiveElementsTask); |
| 418 // prepare outputs | 477 // prepare outputs |
| 419 CompilationUnit libraryUnitA = context | 478 CompilationUnit libraryUnitA = context |
| 420 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) | 479 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) |
| 421 .getValue(RESOLVED_UNIT1); | 480 .getValue(RESOLVED_UNIT1); |
| 422 // validate directives | 481 // validate directives |
| 423 { | 482 ImportDirective importNodeB = libraryUnitA.directives[1]; |
| 424 ImportDirective importNodeB = libraryUnitA.directives[1]; | 483 SimpleIdentifier prefixNodeB = importNodeB.prefix; |
| 425 SimpleIdentifier prefixNodeB = importNodeB.prefix; | 484 ImportElement importElementB = importNodeB.element; |
| 426 ImportElement importElementB = importNodeB.element; | 485 PrefixElement prefixElement = importElementB.prefix; |
| 427 PrefixElement prefixElement = importElementB.prefix; | 486 expect(importElementB, isNotNull); |
| 428 expect(importElementB, isNotNull); | 487 expect(importElementB.importedLibrary, _getImportLibraryInput(sourceB)); |
| 429 expect(importElementB.importedLibrary, _getImportLibraryInput(sourceB)); | 488 expect(prefixElement, isNotNull); |
| 430 expect(prefixElement, isNotNull); | 489 expect(importElementB.prefixOffset, prefixElement.nameOffset); |
| 431 expect(importElementB.prefixOffset, prefixElement.nameOffset); | 490 expect(prefixNodeB.staticElement, prefixElement); |
| 432 expect(prefixNodeB.staticElement, prefixElement); | 491 // PrefixElement "pref" is shared |
| 433 // PrefixElement "pref" is shared | 492 ImportDirective importNodeC = libraryUnitA.directives[2]; |
| 434 ImportDirective importNodeC = libraryUnitA.directives[2]; | 493 SimpleIdentifier prefixNodeC = importNodeC.prefix; |
| 435 SimpleIdentifier prefixNodeC = importNodeC.prefix; | 494 ImportElement importElementC = importNodeC.element; |
| 436 ImportElement importElementC = importNodeC.element; | 495 expect(prefixNodeC.staticElement, prefixElement); |
| 437 expect(prefixNodeC.staticElement, prefixElement); | 496 expect(importElementC.prefix, prefixElement); |
| 438 expect(importElementC.prefix, prefixElement); | |
| 439 } | |
| 440 } | 497 } |
| 441 | 498 |
| 442 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { | 499 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| 443 _fillErrorListener(BUILD_DIRECTIVES_ERRORS); | 500 _fillErrorListener(BUILD_DIRECTIVES_ERRORS); |
| 444 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 501 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 445 } | 502 } |
| 446 | 503 |
| 447 _getExportLibraryInput(Source source) { | 504 _getExportLibraryInput(Source source) { |
| 448 var key = BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT_INPUT_NAME; | 505 var key = BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT_INPUT_NAME; |
| 449 return task.inputs[key][source]; | 506 return task.inputs[key][source]; |
| 450 } | 507 } |
| 451 | 508 |
| 452 _getImportLibraryInput(Source source) { | 509 _getImportLibraryInput(Source source) { |
| 453 var key = BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT_INPUT_NAME; | 510 var key = BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT_INPUT_NAME; |
| 454 return task.inputs[key][source]; | 511 return task.inputs[key][source]; |
| 455 } | 512 } |
| 456 } | 513 } |
| 457 | 514 |
| 458 @reflectiveTest | 515 @reflectiveTest |
| 459 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { | 516 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { |
| 460 test_perform() { | 517 test_perform() { |
| 461 Source source = newSource( | 518 Source source = newSource( |
| 462 '/test.dart', | 519 '/test.dart', |
| 463 ''' | 520 ''' |
| 464 enum MyEnum { | 521 enum MyEnum { |
| 465 A, B | 522 A, B |
| 466 } | 523 } |
| 467 '''); | 524 '''); |
| 468 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT2); | 525 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT2, |
| 469 expect(task, new isInstanceOf<BuildEnumMemberElementsTask>()); | 526 matcher: isBuildEnumMemberElementsTask); |
| 470 CompilationUnit unit = outputs[RESOLVED_UNIT2]; | 527 CompilationUnit unit = outputs[RESOLVED_UNIT2]; |
| 471 // validate Element | 528 // validate Element |
| 472 ClassElement enumElement = unit.element.getEnum('MyEnum'); | 529 ClassElement enumElement = unit.element.getEnum('MyEnum'); |
| 473 List<FieldElement> fields = enumElement.fields; | 530 List<FieldElement> fields = enumElement.fields; |
| 474 expect(fields, hasLength(4)); | 531 expect(fields, hasLength(4)); |
| 475 { | 532 { |
| 476 FieldElementImpl index = fields[0]; | 533 FieldElementImpl index = fields[0]; |
| 477 expect(index, isNotNull); | 534 expect(index, isNotNull); |
| 478 expect(index.name, 'index'); | 535 expect(index.name, 'index'); |
| 479 expect(index.isStatic, isFalse); | 536 expect(index.isStatic, isFalse); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 ''' | 584 ''' |
| 528 library lib_a; | 585 library lib_a; |
| 529 export 'b.dart'; | 586 export 'b.dart'; |
| 530 '''); | 587 '''); |
| 531 Source sourceB = newSource( | 588 Source sourceB = newSource( |
| 532 '/b.dart', | 589 '/b.dart', |
| 533 ''' | 590 ''' |
| 534 library lib_b; | 591 library lib_b; |
| 535 main() {} | 592 main() {} |
| 536 '''); | 593 '''); |
| 537 computeResult(sourceA, LIBRARY_ELEMENT4); | 594 computeResult(sourceA, LIBRARY_ELEMENT4, |
| 538 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); | 595 matcher: isBuildExportNamespaceTask); |
| 539 // validate | 596 // validate |
| 540 { | 597 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 541 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 598 FunctionElement entryPoint = library.entryPoint; |
| 542 FunctionElement entryPoint = library.entryPoint; | 599 expect(entryPoint, isNotNull); |
| 543 expect(entryPoint, isNotNull); | 600 expect(entryPoint.source, sourceB); |
| 544 expect(entryPoint.source, sourceB); | |
| 545 } | |
| 546 } | 601 } |
| 547 | 602 |
| 548 test_perform_hideCombinator() { | 603 test_perform_hideCombinator() { |
| 549 Source sourceA = newSource( | 604 Source sourceA = newSource( |
| 550 '/a.dart', | 605 '/a.dart', |
| 551 ''' | 606 ''' |
| 552 library lib_a; | 607 library lib_a; |
| 553 export 'b.dart' hide B1; | 608 export 'b.dart' hide B1; |
| 554 class A1 {} | 609 class A1 {} |
| 555 class A2 {} | 610 class A2 {} |
| 556 class _A3 {} | 611 class _A3 {} |
| 557 '''); | 612 '''); |
| 558 newSource( | 613 newSource( |
| 559 '/b.dart', | 614 '/b.dart', |
| 560 ''' | 615 ''' |
| 561 library lib_b; | 616 library lib_b; |
| 562 class B1 {} | 617 class B1 {} |
| 563 class B2 {} | 618 class B2 {} |
| 564 class B3 {} | 619 class B3 {} |
| 565 class _B4 {} | 620 class _B4 {} |
| 566 '''); | 621 '''); |
| 567 newSource( | 622 newSource( |
| 568 '/c.dart', | 623 '/c.dart', |
| 569 ''' | 624 ''' |
| 570 library lib_c; | 625 library lib_c; |
| 571 class C1 {} | 626 class C1 {} |
| 572 class C2 {} | 627 class C2 {} |
| 573 class C3 {} | 628 class C3 {} |
| 574 '''); | 629 '''); |
| 575 computeResult(sourceA, LIBRARY_ELEMENT4); | 630 computeResult(sourceA, LIBRARY_ELEMENT4, |
| 576 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); | 631 matcher: isBuildExportNamespaceTask); |
| 577 // validate | 632 // validate |
| 578 { | 633 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 579 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 634 Namespace namespace = library.exportNamespace; |
| 580 Namespace namespace = library.exportNamespace; | 635 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 581 Iterable<String> definedKeys = namespace.definedNames.keys; | 636 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B2', 'B3'])); |
| 582 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B2', 'B3'])); | |
| 583 } | |
| 584 } | 637 } |
| 585 | 638 |
| 586 test_perform_showCombinator() { | 639 test_perform_showCombinator() { |
| 587 Source sourceA = newSource( | 640 Source sourceA = newSource( |
| 588 '/a.dart', | 641 '/a.dart', |
| 589 ''' | 642 ''' |
| 590 library lib_a; | 643 library lib_a; |
| 591 export 'b.dart' show B1; | 644 export 'b.dart' show B1; |
| 592 class A1 {} | 645 class A1 {} |
| 593 class A2 {} | 646 class A2 {} |
| 594 class _A3 {} | 647 class _A3 {} |
| 595 '''); | 648 '''); |
| 596 newSource( | 649 newSource( |
| 597 '/b.dart', | 650 '/b.dart', |
| 598 ''' | 651 ''' |
| 599 library lib_b; | 652 library lib_b; |
| 600 class B1 {} | 653 class B1 {} |
| 601 class B2 {} | 654 class B2 {} |
| 602 class _B3 {} | 655 class _B3 {} |
| 603 '''); | 656 '''); |
| 604 computeResult(sourceA, LIBRARY_ELEMENT4); | 657 computeResult(sourceA, LIBRARY_ELEMENT4, |
| 605 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); | 658 matcher: isBuildExportNamespaceTask); |
| 606 // validate | 659 // validate |
| 607 { | 660 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 608 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 661 Namespace namespace = library.exportNamespace; |
| 609 Namespace namespace = library.exportNamespace; | 662 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 610 Iterable<String> definedKeys = namespace.definedNames.keys; | 663 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B1'])); |
| 611 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B1'])); | |
| 612 } | |
| 613 } | 664 } |
| 614 | 665 |
| 615 test_perform_showCombinator_setter() { | 666 test_perform_showCombinator_setter() { |
| 616 Source sourceA = newSource( | 667 Source sourceA = newSource( |
| 617 '/a.dart', | 668 '/a.dart', |
| 618 ''' | 669 ''' |
| 619 library lib_a; | 670 library lib_a; |
| 620 export 'b.dart' show topLevelB; | 671 export 'b.dart' show topLevelB; |
| 621 class A {} | 672 class A {} |
| 622 '''); | 673 '''); |
| 623 newSource( | 674 newSource( |
| 624 '/b.dart', | 675 '/b.dart', |
| 625 ''' | 676 ''' |
| 626 library lib_b; | 677 library lib_b; |
| 627 int topLevelB; | 678 int topLevelB; |
| 628 '''); | 679 '''); |
| 629 computeResult(sourceA, LIBRARY_ELEMENT4); | 680 computeResult(sourceA, LIBRARY_ELEMENT4, |
| 630 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); | 681 matcher: isBuildExportNamespaceTask); |
| 631 // validate | 682 // validate |
| 632 { | 683 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 633 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 684 Namespace namespace = library.exportNamespace; |
| 634 Namespace namespace = library.exportNamespace; | 685 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 635 Iterable<String> definedKeys = namespace.definedNames.keys; | 686 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); |
| 636 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); | |
| 637 } | |
| 638 } | 687 } |
| 639 } | 688 } |
| 640 | 689 |
| 641 @reflectiveTest | 690 @reflectiveTest |
| 642 class BuildLibraryElementTaskTest extends _AbstractDartTaskTest { | 691 class BuildLibraryElementTaskTest extends _AbstractDartTaskTest { |
| 643 Source librarySource; | 692 Source librarySource; |
| 644 CompilationUnit libraryUnit; | 693 CompilationUnit libraryUnit; |
| 645 CompilationUnitElement libraryUnitElement; | 694 CompilationUnitElement libraryUnitElement; |
| 646 List<CompilationUnit> partUnits; | 695 List<CompilationUnit> partUnits; |
| 647 | 696 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 } | 936 } |
| 888 | 937 |
| 889 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { | 938 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| 890 _fillErrorListener(BUILD_LIBRARY_ERRORS); | 939 _fillErrorListener(BUILD_LIBRARY_ERRORS); |
| 891 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 940 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 892 } | 941 } |
| 893 | 942 |
| 894 void _performBuildTask(Map<String, String> sourceMap) { | 943 void _performBuildTask(Map<String, String> sourceMap) { |
| 895 List<Source> sources = newSources(sourceMap); | 944 List<Source> sources = newSources(sourceMap); |
| 896 Source libSource = sources.first; | 945 Source libSource = sources.first; |
| 897 computeResult(libSource, LIBRARY_ELEMENT1); | 946 computeResult(libSource, LIBRARY_ELEMENT1, |
| 898 expect(task, new isInstanceOf<BuildLibraryElementTask>()); | 947 matcher: isBuildLibraryElementTask); |
| 899 libraryUnit = context | 948 libraryUnit = context |
| 900 .getCacheEntry(new LibrarySpecificUnit(libSource, libSource)) | 949 .getCacheEntry(new LibrarySpecificUnit(libSource, libSource)) |
| 901 .getValue(RESOLVED_UNIT1); | 950 .getValue(RESOLVED_UNIT1); |
| 902 libraryUnitElement = libraryUnit.element; | 951 libraryUnitElement = libraryUnit.element; |
| 903 librarySource = libraryUnitElement.source; | 952 librarySource = libraryUnitElement.source; |
| 904 libraryElement = outputs[LIBRARY_ELEMENT1]; | 953 libraryElement = outputs[LIBRARY_ELEMENT1]; |
| 905 partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT]; | 954 partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT]; |
| 906 } | 955 } |
| 907 } | 956 } |
| 908 | 957 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 part 'part.dart'; | 999 part 'part.dart'; |
| 951 a() {} | 1000 a() {} |
| 952 _b() {} | 1001 _b() {} |
| 953 ''', | 1002 ''', |
| 954 '/part.dart': ''' | 1003 '/part.dart': ''' |
| 955 part of lib; | 1004 part of lib; |
| 956 _c() {} | 1005 _c() {} |
| 957 d() {} | 1006 d() {} |
| 958 ''' | 1007 ''' |
| 959 }); | 1008 }); |
| 960 computeResult(sources.first, LIBRARY_ELEMENT3); | 1009 computeResult(sources.first, LIBRARY_ELEMENT3, |
| 961 expect(task, new isInstanceOf<BuildPublicNamespaceTask>()); | 1010 matcher: isBuildPublicNamespaceTask); |
| 962 // validate | 1011 // validate |
| 963 LibraryElement library = outputs[LIBRARY_ELEMENT3]; | 1012 LibraryElement library = outputs[LIBRARY_ELEMENT3]; |
| 964 Namespace namespace = library.publicNamespace; | 1013 Namespace namespace = library.publicNamespace; |
| 965 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd'])); | 1014 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd'])); |
| 966 } | 1015 } |
| 967 } | 1016 } |
| 968 | 1017 |
| 969 @reflectiveTest | 1018 @reflectiveTest |
| 970 class BuildSourceExportClosureTaskTest extends _AbstractDartTaskTest { | 1019 class BuildSourceExportClosureTaskTest extends _AbstractDartTaskTest { |
| 971 test_perform_exportClosure() { | 1020 test_perform_exportClosure() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 987 library lib_c; | 1036 library lib_c; |
| 988 export 'a.dart'; | 1037 export 'a.dart'; |
| 989 '''); | 1038 '''); |
| 990 Source sourceD = newSource( | 1039 Source sourceD = newSource( |
| 991 '/d.dart', | 1040 '/d.dart', |
| 992 ''' | 1041 ''' |
| 993 library lib_d; | 1042 library lib_d; |
| 994 '''); | 1043 '''); |
| 995 // a.dart | 1044 // a.dart |
| 996 { | 1045 { |
| 997 computeResult(sourceA, EXPORT_SOURCE_CLOSURE); | 1046 computeResult(sourceA, EXPORT_SOURCE_CLOSURE, |
| 998 expect(task, new isInstanceOf<BuildSourceExportClosureTask>()); | 1047 matcher: isBuildSourceExportClosureTask); |
| 999 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; | 1048 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; |
| 1000 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); | 1049 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); |
| 1001 } | 1050 } |
| 1002 // c.dart | 1051 // c.dart |
| 1003 { | 1052 { |
| 1004 computeResult(sourceC, EXPORT_SOURCE_CLOSURE); | 1053 computeResult(sourceC, EXPORT_SOURCE_CLOSURE, |
| 1005 expect(task, new isInstanceOf<BuildSourceExportClosureTask>()); | 1054 matcher: isBuildSourceExportClosureTask); |
| 1006 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; | 1055 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; |
| 1007 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); | 1056 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); |
| 1008 } | 1057 } |
| 1009 // d.dart | 1058 // d.dart |
| 1010 { | 1059 { |
| 1011 computeResult(sourceD, EXPORT_SOURCE_CLOSURE); | 1060 computeResult(sourceD, EXPORT_SOURCE_CLOSURE, |
| 1012 expect(task, new isInstanceOf<BuildSourceExportClosureTask>()); | 1061 matcher: isBuildSourceExportClosureTask); |
| 1013 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; | 1062 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; |
| 1014 expect(closure, unorderedEquals([sourceD])); | 1063 expect(closure, unorderedEquals([sourceD])); |
| 1015 } | 1064 } |
| 1016 } | 1065 } |
| 1017 } | 1066 } |
| 1018 | 1067 |
| 1019 @reflectiveTest | 1068 @reflectiveTest |
| 1020 class BuildSourceImportExportClosureTaskTest extends _AbstractDartTaskTest { | 1069 class BuildSourceImportExportClosureTaskTest extends _AbstractDartTaskTest { |
| 1021 test_perform_importExportClosure() { | 1070 test_perform_importExportClosure() { |
| 1022 Source sourceA = newSource( | 1071 Source sourceA = newSource( |
| 1023 '/a.dart', | 1072 '/a.dart', |
| 1024 ''' | 1073 ''' |
| 1025 library lib_a; | 1074 library lib_a; |
| 1026 '''); | 1075 '''); |
| 1027 Source sourceB = newSource( | 1076 Source sourceB = newSource( |
| 1028 '/b.dart', | 1077 '/b.dart', |
| 1029 ''' | 1078 ''' |
| 1030 library lib_b; | 1079 library lib_b; |
| 1031 export 'a.dart'; | 1080 export 'a.dart'; |
| 1032 '''); | 1081 '''); |
| 1033 Source sourceC = newSource( | 1082 Source sourceC = newSource( |
| 1034 '/c.dart', | 1083 '/c.dart', |
| 1035 ''' | 1084 ''' |
| 1036 library lib_c; | 1085 library lib_c; |
| 1037 import 'b.dart'; | 1086 import 'b.dart'; |
| 1038 '''); | 1087 '''); |
| 1039 Source coreSource = context.sourceFactory.resolveUri(null, 'dart:core'); | 1088 Source coreSource = context.sourceFactory.resolveUri(null, 'dart:core'); |
| 1040 // c.dart | 1089 // c.dart |
| 1041 { | 1090 { |
| 1042 computeResult(sourceC, IMPORT_EXPORT_SOURCE_CLOSURE); | 1091 computeResult(sourceC, IMPORT_EXPORT_SOURCE_CLOSURE, |
| 1043 expect(task, new isInstanceOf<BuildSourceImportExportClosureTask>()); | 1092 matcher: isBuildSourceImportExportClosureTask); |
| 1044 List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE]; | 1093 List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE]; |
| 1045 expect(closure, contains(sourceA)); | 1094 expect(closure, contains(sourceA)); |
| 1046 expect(closure, contains(sourceB)); | 1095 expect(closure, contains(sourceB)); |
| 1047 expect(closure, contains(sourceC)); | 1096 expect(closure, contains(sourceC)); |
| 1048 expect(closure, contains(coreSource)); | 1097 expect(closure, contains(coreSource)); |
| 1049 } | 1098 } |
| 1050 // b.dart | 1099 // b.dart |
| 1051 { | 1100 { |
| 1052 computeResult(sourceB, IMPORT_EXPORT_SOURCE_CLOSURE); | 1101 computeResult(sourceB, IMPORT_EXPORT_SOURCE_CLOSURE, |
| 1053 expect(task, new isInstanceOf<BuildSourceImportExportClosureTask>()); | 1102 matcher: isBuildSourceImportExportClosureTask); |
| 1054 List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE]; | 1103 List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE]; |
| 1055 expect(closure, contains(sourceA)); | 1104 expect(closure, contains(sourceA)); |
| 1056 expect(closure, contains(sourceB)); | 1105 expect(closure, contains(sourceB)); |
| 1057 expect(closure, contains(coreSource)); | 1106 expect(closure, contains(coreSource)); |
| 1058 } | 1107 } |
| 1059 } | 1108 } |
| 1060 | 1109 |
| 1061 test_perform_isClient_false() { | 1110 test_perform_isClient_false() { |
| 1062 Source sourceA = newSource( | 1111 Source sourceA = newSource( |
| 1063 '/a.dart', | 1112 '/a.dart', |
| 1064 ''' | 1113 ''' |
| 1065 library lib_a; | 1114 library lib_a; |
| 1066 import 'b.dart'; | 1115 import 'b.dart'; |
| 1067 '''); | 1116 '''); |
| 1068 newSource( | 1117 newSource( |
| 1069 '/b.dart', | 1118 '/b.dart', |
| 1070 ''' | 1119 ''' |
| 1071 library lib_b; | 1120 library lib_b; |
| 1072 '''); | 1121 '''); |
| 1073 computeResult(sourceA, IS_CLIENT); | 1122 computeResult(sourceA, IS_CLIENT, |
| 1074 expect(task, new isInstanceOf<BuildSourceImportExportClosureTask>()); | 1123 matcher: isBuildSourceImportExportClosureTask); |
| 1075 expect(outputs[IS_CLIENT], isFalse); | 1124 expect(outputs[IS_CLIENT], isFalse); |
| 1076 } | 1125 } |
| 1077 | 1126 |
| 1078 test_perform_isClient_true_export_indirect() { | 1127 test_perform_isClient_true_export_indirect() { |
| 1079 newSource( | 1128 newSource( |
| 1080 '/exports_html.dart', | 1129 '/exports_html.dart', |
| 1081 ''' | 1130 ''' |
| 1082 library lib_exports_html; | 1131 library lib_exports_html; |
| 1083 export 'dart:html'; | 1132 export 'dart:html'; |
| 1084 '''); | 1133 '''); |
| 1085 Source source = newSource( | 1134 Source source = newSource( |
| 1086 '/test.dart', | 1135 '/test.dart', |
| 1087 ''' | 1136 ''' |
| 1088 import 'exports_html.dart'; | 1137 import 'exports_html.dart'; |
| 1089 '''); | 1138 '''); |
| 1090 computeResult(source, IS_CLIENT); | 1139 computeResult(source, IS_CLIENT, |
| 1091 expect(task, new isInstanceOf<BuildSourceImportExportClosureTask>()); | 1140 matcher: isBuildSourceImportExportClosureTask); |
| 1092 expect(outputs[IS_CLIENT], isTrue); | 1141 expect(outputs[IS_CLIENT], isTrue); |
| 1093 } | 1142 } |
| 1094 | 1143 |
| 1095 test_perform_isClient_true_import_direct() { | 1144 test_perform_isClient_true_import_direct() { |
| 1096 Source sourceA = newSource( | 1145 Source sourceA = newSource( |
| 1097 '/a.dart', | 1146 '/a.dart', |
| 1098 ''' | 1147 ''' |
| 1099 library lib_a; | 1148 library lib_a; |
| 1100 import 'dart:html'; | 1149 import 'dart:html'; |
| 1101 '''); | 1150 '''); |
| 1102 computeResult(sourceA, IS_CLIENT); | 1151 computeResult(sourceA, IS_CLIENT, |
| 1103 expect(task, new isInstanceOf<BuildSourceImportExportClosureTask>()); | 1152 matcher: isBuildSourceImportExportClosureTask); |
| 1104 expect(outputs[IS_CLIENT], isTrue); | 1153 expect(outputs[IS_CLIENT], isTrue); |
| 1105 } | 1154 } |
| 1106 | 1155 |
| 1107 test_perform_isClient_true_import_indirect() { | 1156 test_perform_isClient_true_import_indirect() { |
| 1108 Source sourceA = newSource( | 1157 Source sourceA = newSource( |
| 1109 '/a.dart', | 1158 '/a.dart', |
| 1110 ''' | 1159 ''' |
| 1111 library lib_a; | 1160 library lib_a; |
| 1112 import 'b.dart'; | 1161 import 'b.dart'; |
| 1113 '''); | 1162 '''); |
| 1114 newSource( | 1163 newSource( |
| 1115 '/b.dart', | 1164 '/b.dart', |
| 1116 ''' | 1165 ''' |
| 1117 library lib_b; | 1166 library lib_b; |
| 1118 import 'dart:html'; | 1167 import 'dart:html'; |
| 1119 '''); | 1168 '''); |
| 1120 computeResult(sourceA, IS_CLIENT); | 1169 computeResult(sourceA, IS_CLIENT, |
| 1121 expect(task, new isInstanceOf<BuildSourceImportExportClosureTask>()); | 1170 matcher: isBuildSourceImportExportClosureTask); |
| 1122 expect(outputs[IS_CLIENT], isTrue); | 1171 expect(outputs[IS_CLIENT], isTrue); |
| 1123 } | 1172 } |
| 1124 } | 1173 } |
| 1125 | 1174 |
| 1126 @reflectiveTest | 1175 @reflectiveTest |
| 1127 class BuildTypeProviderTaskTest extends _AbstractDartTaskTest { | 1176 class BuildTypeProviderTaskTest extends _AbstractDartTaskTest { |
| 1128 test_perform() { | 1177 test_perform() { |
| 1129 computeResult(AnalysisContextTarget.request, TYPE_PROVIDER); | 1178 computeResult(AnalysisContextTarget.request, TYPE_PROVIDER, |
| 1130 expect(task, new isInstanceOf<BuildTypeProviderTask>()); | 1179 matcher: isBuildTypeProviderTask); |
| 1131 // validate | 1180 // validate |
| 1132 TypeProvider typeProvider = outputs[TYPE_PROVIDER]; | 1181 TypeProvider typeProvider = outputs[TYPE_PROVIDER]; |
| 1133 expect(typeProvider, isNotNull); | 1182 expect(typeProvider, isNotNull); |
| 1134 expect(typeProvider.boolType, isNotNull); | 1183 expect(typeProvider.boolType, isNotNull); |
| 1135 expect(typeProvider.intType, isNotNull); | 1184 expect(typeProvider.intType, isNotNull); |
| 1136 expect(typeProvider.futureType, isNotNull); | 1185 expect(typeProvider.futureType, isNotNull); |
| 1137 } | 1186 } |
| 1138 } | 1187 } |
| 1139 | 1188 |
| 1140 @reflectiveTest | 1189 @reflectiveTest |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 List<ClassElement> types = unit.element.types; | 1221 List<ClassElement> types = unit.element.types; |
| 1173 Element constructorForD = | 1222 Element constructorForD = |
| 1174 types.firstWhere((ClassElement cls) => cls.name == 'D').constructors[0]; | 1223 types.firstWhere((ClassElement cls) => cls.name == 'D').constructors[0]; |
| 1175 Annotation annotation = findClassAnnotation(unit, 'C'); | 1224 Annotation annotation = findClassAnnotation(unit, 'C'); |
| 1176 // Now compute the dependencies for the annotation, and check that it is | 1225 // Now compute the dependencies for the annotation, and check that it is |
| 1177 // the set [x, constructorForD]. | 1226 // the set [x, constructorForD]. |
| 1178 // TODO(paulberry): test librarySource != source | 1227 // TODO(paulberry): test librarySource != source |
| 1179 computeResult( | 1228 computeResult( |
| 1180 new ConstantEvaluationTarget_Annotation( | 1229 new ConstantEvaluationTarget_Annotation( |
| 1181 context, source, source, annotation), | 1230 context, source, source, annotation), |
| 1182 CONSTANT_DEPENDENCIES); | 1231 CONSTANT_DEPENDENCIES, |
| 1232 matcher: isComputeConstantDependenciesTask); |
| 1183 expect( | 1233 expect( |
| 1184 outputs[CONSTANT_DEPENDENCIES].toSet(), [x, constructorForD].toSet()); | 1234 outputs[CONSTANT_DEPENDENCIES].toSet(), [x, constructorForD].toSet()); |
| 1185 } | 1235 } |
| 1186 | 1236 |
| 1187 test_annotation_without_args() { | 1237 test_annotation_without_args() { |
| 1188 Source source = newSource( | 1238 Source source = newSource( |
| 1189 '/test.dart', | 1239 '/test.dart', |
| 1190 ''' | 1240 ''' |
| 1191 const x = 1; | 1241 const x = 1; |
| 1192 @x class C {} | 1242 @x class C {} |
| 1193 '''); | 1243 '''); |
| 1194 // First compute the resolved unit for the source. | 1244 // First compute the resolved unit for the source. |
| 1195 LibrarySpecificUnit librarySpecificUnit = | 1245 LibrarySpecificUnit librarySpecificUnit = |
| 1196 new LibrarySpecificUnit(source, source); | 1246 new LibrarySpecificUnit(source, source); |
| 1197 computeResult(librarySpecificUnit, RESOLVED_UNIT1); | 1247 computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
| 1198 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 1248 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 1199 // Find the element for x and the annotation on C. | 1249 // Find the element for x and the annotation on C. |
| 1200 List<PropertyAccessorElement> accessors = unit.element.accessors; | 1250 List<PropertyAccessorElement> accessors = unit.element.accessors; |
| 1201 Element x = accessors | 1251 Element x = accessors |
| 1202 .firstWhere((PropertyAccessorElement accessor) => | 1252 .firstWhere((PropertyAccessorElement accessor) => |
| 1203 accessor.isGetter && accessor.name == 'x') | 1253 accessor.isGetter && accessor.name == 'x') |
| 1204 .variable; | 1254 .variable; |
| 1205 Annotation annotation = findClassAnnotation(unit, 'C'); | 1255 Annotation annotation = findClassAnnotation(unit, 'C'); |
| 1206 // Now compute the dependencies for the annotation, and check that it is | 1256 // Now compute the dependencies for the annotation, and check that it is |
| 1207 // the list [x]. | 1257 // the list [x]. |
| 1208 computeResult( | 1258 computeResult( |
| 1209 new ConstantEvaluationTarget_Annotation( | 1259 new ConstantEvaluationTarget_Annotation( |
| 1210 context, source, source, annotation), | 1260 context, source, source, annotation), |
| 1211 CONSTANT_DEPENDENCIES); | 1261 CONSTANT_DEPENDENCIES, |
| 1262 matcher: isComputeConstantDependenciesTask); |
| 1212 expect(outputs[CONSTANT_DEPENDENCIES], [x]); | 1263 expect(outputs[CONSTANT_DEPENDENCIES], [x]); |
| 1213 } | 1264 } |
| 1214 | 1265 |
| 1215 test_enumConstant() { | 1266 test_enumConstant() { |
| 1216 Source source = newSource( | 1267 Source source = newSource( |
| 1217 '/test.dart', | 1268 '/test.dart', |
| 1218 ''' | 1269 ''' |
| 1219 enum E {A, B, C} | 1270 enum E {A, B, C} |
| 1220 '''); | 1271 '''); |
| 1221 // First compute the resolved unit for the source. | 1272 // First compute the resolved unit for the source. |
| 1222 LibrarySpecificUnit librarySpecificUnit = | 1273 LibrarySpecificUnit librarySpecificUnit = |
| 1223 new LibrarySpecificUnit(source, source); | 1274 new LibrarySpecificUnit(source, source); |
| 1224 computeResult(librarySpecificUnit, RESOLVED_UNIT2); | 1275 computeResult(librarySpecificUnit, RESOLVED_UNIT2); |
| 1225 CompilationUnit unit = outputs[RESOLVED_UNIT2]; | 1276 CompilationUnit unit = outputs[RESOLVED_UNIT2]; |
| 1226 // Find the element for 'A' | 1277 // Find the element for 'A' |
| 1227 EnumDeclaration enumDeclaration = unit.declarations[0]; | 1278 EnumDeclaration enumDeclaration = unit.declarations[0]; |
| 1228 EnumConstantDeclaration constantDeclaration = enumDeclaration.constants[0]; | 1279 EnumConstantDeclaration constantDeclaration = enumDeclaration.constants[0]; |
| 1229 FieldElement constantElement = constantDeclaration.element; | 1280 FieldElement constantElement = constantDeclaration.element; |
| 1230 // Now compute the dependencies for the constant and check that there are | 1281 // Now compute the dependencies for the constant and check that there are |
| 1231 // none. | 1282 // none. |
| 1232 computeResult(constantElement, CONSTANT_DEPENDENCIES); | 1283 computeResult(constantElement, CONSTANT_DEPENDENCIES, |
| 1284 matcher: isComputeConstantDependenciesTask); |
| 1233 expect(outputs[CONSTANT_DEPENDENCIES], isEmpty); | 1285 expect(outputs[CONSTANT_DEPENDENCIES], isEmpty); |
| 1234 } | 1286 } |
| 1235 | 1287 |
| 1236 test_perform() { | 1288 test_perform() { |
| 1237 Source source = newSource( | 1289 Source source = newSource( |
| 1238 '/test.dart', | 1290 '/test.dart', |
| 1239 ''' | 1291 ''' |
| 1240 const x = y; | 1292 const x = y; |
| 1241 const y = 1; | 1293 const y = 1; |
| 1242 '''); | 1294 '''); |
| 1243 // First compute the resolved unit for the source. | 1295 // First compute the resolved unit for the source. |
| 1244 LibrarySpecificUnit librarySpecificUnit = | 1296 LibrarySpecificUnit librarySpecificUnit = |
| 1245 new LibrarySpecificUnit(source, source); | 1297 new LibrarySpecificUnit(source, source); |
| 1246 computeResult(librarySpecificUnit, RESOLVED_UNIT1); | 1298 computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
| 1247 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 1299 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 1248 // Find the elements for the constants x and y. | 1300 // Find the elements for the constants x and y. |
| 1249 List<PropertyAccessorElement> accessors = unit.element.accessors; | 1301 List<PropertyAccessorElement> accessors = unit.element.accessors; |
| 1250 Element x = accessors | 1302 Element x = accessors |
| 1251 .firstWhere((PropertyAccessorElement accessor) => | 1303 .firstWhere((PropertyAccessorElement accessor) => |
| 1252 accessor.isGetter && accessor.name == 'x') | 1304 accessor.isGetter && accessor.name == 'x') |
| 1253 .variable; | 1305 .variable; |
| 1254 Element y = accessors | 1306 Element y = accessors |
| 1255 .firstWhere((PropertyAccessorElement accessor) => | 1307 .firstWhere((PropertyAccessorElement accessor) => |
| 1256 accessor.isGetter && accessor.name == 'y') | 1308 accessor.isGetter && accessor.name == 'y') |
| 1257 .variable; | 1309 .variable; |
| 1258 // Now compute the dependencies for x, and check that it is the list [y]. | 1310 // Now compute the dependencies for x, and check that it is the list [y]. |
| 1259 computeResult(x, CONSTANT_DEPENDENCIES); | 1311 computeResult(x, CONSTANT_DEPENDENCIES, |
| 1312 matcher: isComputeConstantDependenciesTask); |
| 1260 expect(outputs[CONSTANT_DEPENDENCIES], [y]); | 1313 expect(outputs[CONSTANT_DEPENDENCIES], [y]); |
| 1261 } | 1314 } |
| 1262 } | 1315 } |
| 1263 | 1316 |
| 1264 @reflectiveTest | 1317 @reflectiveTest |
| 1265 class ComputeConstantValueTaskTest extends _AbstractDartTaskTest { | 1318 class ComputeConstantValueTaskTest extends _AbstractDartTaskTest { |
| 1266 EvaluationResultImpl computeClassAnnotation( | 1319 EvaluationResultImpl computeClassAnnotation( |
| 1267 Source source, CompilationUnit unit, String className) { | 1320 Source source, CompilationUnit unit, String className) { |
| 1268 for (CompilationUnitMember member in unit.declarations) { | 1321 for (CompilationUnitMember member in unit.declarations) { |
| 1269 if (member is ClassDeclaration && member.name.name == className) { | 1322 if (member is ClassDeclaration && member.name.name == className) { |
| 1270 expect(member.metadata, hasLength(1)); | 1323 expect(member.metadata, hasLength(1)); |
| 1271 Annotation annotation = member.metadata[0]; | 1324 Annotation annotation = member.metadata[0]; |
| 1272 ConstantEvaluationTarget_Annotation target = | 1325 ConstantEvaluationTarget_Annotation target = |
| 1273 new ConstantEvaluationTarget_Annotation( | 1326 new ConstantEvaluationTarget_Annotation( |
| 1274 context, source, source, annotation); | 1327 context, source, source, annotation); |
| 1275 computeResult(target, CONSTANT_VALUE); | 1328 computeResult(target, CONSTANT_VALUE, |
| 1329 matcher: isComputeConstantValueTask); |
| 1276 expect(outputs[CONSTANT_VALUE], same(target)); | 1330 expect(outputs[CONSTANT_VALUE], same(target)); |
| 1277 EvaluationResultImpl evaluationResult = (annotation.elementAnnotation | 1331 EvaluationResultImpl evaluationResult = (annotation.elementAnnotation |
| 1278 as ElementAnnotationImpl).evaluationResult; | 1332 as ElementAnnotationImpl).evaluationResult; |
| 1279 return evaluationResult; | 1333 return evaluationResult; |
| 1280 } | 1334 } |
| 1281 } | 1335 } |
| 1282 fail('Annotation not found'); | 1336 fail('Annotation not found'); |
| 1283 return null; | 1337 return null; |
| 1284 } | 1338 } |
| 1285 | 1339 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 EvaluationResultImpl _computeTopLevelVariableConstValue( | 1505 EvaluationResultImpl _computeTopLevelVariableConstValue( |
| 1452 String variableName, String content) { | 1506 String variableName, String content) { |
| 1453 return _evaluateConstant(_resolveUnit(content), variableName); | 1507 return _evaluateConstant(_resolveUnit(content), variableName); |
| 1454 } | 1508 } |
| 1455 | 1509 |
| 1456 EvaluationResultImpl _evaluateConstant( | 1510 EvaluationResultImpl _evaluateConstant( |
| 1457 CompilationUnit unit, String variableName) { | 1511 CompilationUnit unit, String variableName) { |
| 1458 // Find the element for the given constant. | 1512 // Find the element for the given constant. |
| 1459 PropertyInducingElement variableElement = _findVariable(unit, variableName); | 1513 PropertyInducingElement variableElement = _findVariable(unit, variableName); |
| 1460 // Now compute the value of the constant. | 1514 // Now compute the value of the constant. |
| 1461 computeResult(variableElement, CONSTANT_VALUE); | 1515 computeResult(variableElement, CONSTANT_VALUE, |
| 1516 matcher: isComputeConstantValueTask); |
| 1462 expect(outputs[CONSTANT_VALUE], same(variableElement)); | 1517 expect(outputs[CONSTANT_VALUE], same(variableElement)); |
| 1463 EvaluationResultImpl evaluationResult = | 1518 EvaluationResultImpl evaluationResult = |
| 1464 (variableElement as TopLevelVariableElementImpl).evaluationResult; | 1519 (variableElement as TopLevelVariableElementImpl).evaluationResult; |
| 1465 return evaluationResult; | 1520 return evaluationResult; |
| 1466 } | 1521 } |
| 1467 | 1522 |
| 1468 void _expectCircularityError(EvaluationResultImpl evaluationResult) { | 1523 void _expectCircularityError(EvaluationResultImpl evaluationResult) { |
| 1469 expect(evaluationResult, isNotNull); | 1524 expect(evaluationResult, isNotNull); |
| 1470 expect(evaluationResult.value, isNull); | 1525 expect(evaluationResult.value, isNull); |
| 1471 expect(evaluationResult.errors, hasLength(1)); | 1526 expect(evaluationResult.errors, hasLength(1)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1501 ''' | 1556 ''' |
| 1502 const a = b; | 1557 const a = b; |
| 1503 const b = 0; | 1558 const b = 0; |
| 1504 '''); | 1559 '''); |
| 1505 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1560 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1506 computeResult(target, RESOLVED_UNIT5); | 1561 computeResult(target, RESOLVED_UNIT5); |
| 1507 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 1562 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 1508 TopLevelVariableElement elementA = unit.element.topLevelVariables[0]; | 1563 TopLevelVariableElement elementA = unit.element.topLevelVariables[0]; |
| 1509 TopLevelVariableElement elementB = unit.element.topLevelVariables[1]; | 1564 TopLevelVariableElement elementB = unit.element.topLevelVariables[1]; |
| 1510 | 1565 |
| 1511 computeResult(elementA, INFERABLE_STATIC_VARIABLE_DEPENDENCIES); | 1566 computeResult(elementA, INFERABLE_STATIC_VARIABLE_DEPENDENCIES, |
| 1512 expect(task, | 1567 matcher: isComputeInferableStaticVariableDependenciesTask); |
| 1513 new isInstanceOf<ComputeInferableStaticVariableDependenciesTask>()); | |
| 1514 expect(outputs, hasLength(1)); | 1568 expect(outputs, hasLength(1)); |
| 1515 List<VariableElement> dependencies = | 1569 List<VariableElement> dependencies = |
| 1516 outputs[INFERABLE_STATIC_VARIABLE_DEPENDENCIES]; | 1570 outputs[INFERABLE_STATIC_VARIABLE_DEPENDENCIES]; |
| 1517 expect(dependencies, unorderedEquals([elementB])); | 1571 expect(dependencies, unorderedEquals([elementB])); |
| 1518 } | 1572 } |
| 1519 } | 1573 } |
| 1520 | 1574 |
| 1521 @reflectiveTest | 1575 @reflectiveTest |
| 1522 class ContainingLibrariesTaskTest extends _AbstractDartTaskTest { | 1576 class ContainingLibrariesTaskTest extends _AbstractDartTaskTest { |
| 1523 test_buildInputs() { | 1577 test_buildInputs() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1550 } | 1604 } |
| 1551 | 1605 |
| 1552 test_descriptor() { | 1606 test_descriptor() { |
| 1553 TaskDescriptor descriptor = ContainingLibrariesTask.DESCRIPTOR; | 1607 TaskDescriptor descriptor = ContainingLibrariesTask.DESCRIPTOR; |
| 1554 expect(descriptor, isNotNull); | 1608 expect(descriptor, isNotNull); |
| 1555 } | 1609 } |
| 1556 | 1610 |
| 1557 test_perform_definingCompilationUnit() { | 1611 test_perform_definingCompilationUnit() { |
| 1558 AnalysisTarget library = newSource('/test.dart', 'library test;'); | 1612 AnalysisTarget library = newSource('/test.dart', 'library test;'); |
| 1559 computeResult(library, INCLUDED_PARTS); | 1613 computeResult(library, INCLUDED_PARTS); |
| 1560 computeResult(library, CONTAINING_LIBRARIES); | 1614 computeResult(library, CONTAINING_LIBRARIES, |
| 1561 expect(task, new isInstanceOf<ContainingLibrariesTask>()); | 1615 matcher: isContainingLibrariesTask); |
| 1562 expect(outputs, hasLength(1)); | 1616 expect(outputs, hasLength(1)); |
| 1563 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; | 1617 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; |
| 1564 expect(containingLibraries, unorderedEquals([library])); | 1618 expect(containingLibraries, unorderedEquals([library])); |
| 1565 } | 1619 } |
| 1566 | 1620 |
| 1567 test_perform_partInMultipleLibraries() { | 1621 test_perform_partInMultipleLibraries() { |
| 1568 AnalysisTarget library1 = | 1622 AnalysisTarget library1 = |
| 1569 newSource('/lib1.dart', 'library test; part "part.dart";'); | 1623 newSource('/lib1.dart', 'library test; part "part.dart";'); |
| 1570 AnalysisTarget library2 = | 1624 AnalysisTarget library2 = |
| 1571 newSource('/lib2.dart', 'library test; part "part.dart";'); | 1625 newSource('/lib2.dart', 'library test; part "part.dart";'); |
| 1572 AnalysisTarget part = newSource('/part.dart', 'part of test;'); | 1626 AnalysisTarget part = newSource('/part.dart', 'part of test;'); |
| 1573 computeResult(library1, INCLUDED_PARTS); | 1627 computeResult(library1, INCLUDED_PARTS); |
| 1574 computeResult(library2, INCLUDED_PARTS); | 1628 computeResult(library2, INCLUDED_PARTS); |
| 1575 computeResult(part, SOURCE_KIND); | 1629 computeResult(part, SOURCE_KIND); |
| 1576 computeResult(part, CONTAINING_LIBRARIES); | 1630 computeResult(part, CONTAINING_LIBRARIES, |
| 1577 expect(task, new isInstanceOf<ContainingLibrariesTask>()); | 1631 matcher: isContainingLibrariesTask); |
| 1578 expect(outputs, hasLength(1)); | 1632 expect(outputs, hasLength(1)); |
| 1579 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; | 1633 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; |
| 1580 expect(containingLibraries, unorderedEquals([library1, library2])); | 1634 expect(containingLibraries, unorderedEquals([library1, library2])); |
| 1581 } | 1635 } |
| 1582 | 1636 |
| 1583 test_perform_partInSingleLibrary() { | 1637 test_perform_partInSingleLibrary() { |
| 1584 AnalysisTarget library = | 1638 AnalysisTarget library = |
| 1585 newSource('/lib.dart', 'library test; part "part.dart";'); | 1639 newSource('/lib.dart', 'library test; part "part.dart";'); |
| 1586 AnalysisTarget part = newSource('/part.dart', 'part of test;'); | 1640 AnalysisTarget part = newSource('/part.dart', 'part of test;'); |
| 1587 computeResult(library, INCLUDED_PARTS); | 1641 computeResult(library, INCLUDED_PARTS); |
| 1588 computeResult(part, SOURCE_KIND); | 1642 computeResult(part, SOURCE_KIND); |
| 1589 computeResult(part, CONTAINING_LIBRARIES); | 1643 computeResult(part, CONTAINING_LIBRARIES, |
| 1590 expect(task, new isInstanceOf<ContainingLibrariesTask>()); | 1644 matcher: isContainingLibrariesTask); |
| 1591 expect(outputs, hasLength(1)); | 1645 expect(outputs, hasLength(1)); |
| 1592 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; | 1646 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; |
| 1593 expect(containingLibraries, unorderedEquals([library])); | 1647 expect(containingLibraries, unorderedEquals([library])); |
| 1594 } | 1648 } |
| 1595 } | 1649 } |
| 1596 | 1650 |
| 1597 @reflectiveTest | 1651 @reflectiveTest |
| 1598 class DartErrorsTaskTest extends _AbstractDartTaskTest { | 1652 class DartErrorsTaskTest extends _AbstractDartTaskTest { |
| 1599 test_buildInputs() { | 1653 test_buildInputs() { |
| 1600 Map<String, TaskInput> inputs = DartErrorsTask.buildInputs(emptySource); | 1654 Map<String, TaskInput> inputs = DartErrorsTask.buildInputs(emptySource); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1631 | 1685 |
| 1632 test_descriptor() { | 1686 test_descriptor() { |
| 1633 TaskDescriptor descriptor = DartErrorsTask.DESCRIPTOR; | 1687 TaskDescriptor descriptor = DartErrorsTask.DESCRIPTOR; |
| 1634 expect(descriptor, isNotNull); | 1688 expect(descriptor, isNotNull); |
| 1635 } | 1689 } |
| 1636 | 1690 |
| 1637 test_perform_definingCompilationUnit() { | 1691 test_perform_definingCompilationUnit() { |
| 1638 AnalysisTarget library = | 1692 AnalysisTarget library = |
| 1639 newSource('/test.dart', 'library test; import "dart:math";'); | 1693 newSource('/test.dart', 'library test; import "dart:math";'); |
| 1640 computeResult(library, INCLUDED_PARTS); | 1694 computeResult(library, INCLUDED_PARTS); |
| 1641 computeResult(library, DART_ERRORS); | 1695 computeResult(library, DART_ERRORS, matcher: isDartErrorsTask); |
| 1642 expect(task, new isInstanceOf<DartErrorsTask>()); | |
| 1643 expect(outputs, hasLength(1)); | 1696 expect(outputs, hasLength(1)); |
| 1644 List<AnalysisError> errors = outputs[DART_ERRORS]; | 1697 List<AnalysisError> errors = outputs[DART_ERRORS]; |
| 1645 expect(errors, hasLength(1)); | 1698 expect(errors, hasLength(1)); |
| 1646 } | 1699 } |
| 1647 | 1700 |
| 1648 test_perform_partInSingleLibrary() { | 1701 test_perform_partInSingleLibrary() { |
| 1649 AnalysisTarget library = newSource( | 1702 AnalysisTarget library = newSource( |
| 1650 '/lib.dart', 'library test; import "dart:math"; part "part.dart";'); | 1703 '/lib.dart', 'library test; import "dart:math"; part "part.dart";'); |
| 1651 AnalysisTarget part = | 1704 AnalysisTarget part = |
| 1652 newSource('/part.dart', 'part of test; class A extends A {}'); | 1705 newSource('/part.dart', 'part of test; class A extends A {}'); |
| 1653 computeResult(library, INCLUDED_PARTS); | 1706 computeResult(library, INCLUDED_PARTS); |
| 1654 computeResult(library, DART_ERRORS); | 1707 computeResult(library, DART_ERRORS); |
| 1655 computeResult(part, DART_ERRORS); | 1708 computeResult(part, DART_ERRORS, matcher: isDartErrorsTask); |
| 1656 expect(task, new isInstanceOf<DartErrorsTask>()); | |
| 1657 expect(outputs, hasLength(1)); | 1709 expect(outputs, hasLength(1)); |
| 1658 List<AnalysisError> errors = outputs[DART_ERRORS]; | 1710 List<AnalysisError> errors = outputs[DART_ERRORS]; |
| 1659 // This should contain only the errors in the part file, not the ones in the | 1711 // This should contain only the errors in the part file, not the ones in the |
| 1660 // library. | 1712 // library. |
| 1661 expect(errors, hasLength(1)); | 1713 expect(errors, hasLength(1)); |
| 1662 } | 1714 } |
| 1663 } | 1715 } |
| 1664 | 1716 |
| 1665 @reflectiveTest | 1717 @reflectiveTest |
| 1666 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest { | 1718 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest { |
| 1667 test_perform() { | 1719 test_perform() { |
| 1668 Source source = newSource( | 1720 Source source = newSource( |
| 1669 '/test.dart', | 1721 '/test.dart', |
| 1670 ''' | 1722 ''' |
| 1671 class C { | 1723 class C { |
| 1672 const C(); | 1724 const C(); |
| 1673 } | 1725 } |
| 1674 | 1726 |
| 1675 @x | 1727 @x |
| 1676 f() {} | 1728 f() {} |
| 1677 | 1729 |
| 1678 const x = const C(); | 1730 const x = const C(); |
| 1679 '''); | 1731 '''); |
| 1680 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1732 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1681 computeResult(target, RESOLVED_UNIT); | 1733 computeResult(target, RESOLVED_UNIT, matcher: isEvaluateUnitConstantsTask); |
| 1682 expect(task, new isInstanceOf<EvaluateUnitConstantsTask>()); | |
| 1683 CompilationUnit unit = outputs[RESOLVED_UNIT]; | 1734 CompilationUnit unit = outputs[RESOLVED_UNIT]; |
| 1684 CompilationUnitElement unitElement = unit.element; | 1735 CompilationUnitElement unitElement = unit.element; |
| 1685 expect( | 1736 expect( |
| 1686 (unitElement.types[0].constructors[0] as ConstructorElementImpl) | 1737 (unitElement.types[0].constructors[0] as ConstructorElementImpl) |
| 1687 .isCycleFree, | 1738 .isCycleFree, |
| 1688 isTrue); | 1739 isTrue); |
| 1689 expect( | 1740 expect( |
| 1690 (unitElement.functions[0].metadata[0] as ElementAnnotationImpl) | 1741 (unitElement.functions[0].metadata[0] as ElementAnnotationImpl) |
| 1691 .evaluationResult, | 1742 .evaluationResult, |
| 1692 isNotNull); | 1743 isNotNull); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1723 main() { | 1774 main() { |
| 1724 new A(); | 1775 new A(); |
| 1725 }'''); | 1776 }'''); |
| 1726 _computeUsedElements(source); | 1777 _computeUsedElements(source); |
| 1727 // validate | 1778 // validate |
| 1728 expect(usedElementNames, unorderedEquals(['A'])); | 1779 expect(usedElementNames, unorderedEquals(['A'])); |
| 1729 } | 1780 } |
| 1730 | 1781 |
| 1731 void _computeUsedElements(Source source) { | 1782 void _computeUsedElements(Source source) { |
| 1732 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1783 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1733 computeResult(target, USED_IMPORTED_ELEMENTS); | 1784 computeResult(target, USED_IMPORTED_ELEMENTS, |
| 1734 expect(task, new isInstanceOf<GatherUsedImportedElementsTask>()); | 1785 matcher: isGatherUsedImportedElementsTask); |
| 1735 usedElements = outputs[USED_IMPORTED_ELEMENTS]; | 1786 usedElements = outputs[USED_IMPORTED_ELEMENTS]; |
| 1736 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); | 1787 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); |
| 1737 } | 1788 } |
| 1738 } | 1789 } |
| 1739 | 1790 |
| 1740 @reflectiveTest | 1791 @reflectiveTest |
| 1741 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { | 1792 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { |
| 1742 UsedLocalElements usedElements; | 1793 UsedLocalElements usedElements; |
| 1743 Set<String> usedElementNames; | 1794 Set<String> usedElementNames; |
| 1744 | 1795 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1771 } | 1822 } |
| 1772 '''); | 1823 '''); |
| 1773 _computeUsedElements(source); | 1824 _computeUsedElements(source); |
| 1774 // validate | 1825 // validate |
| 1775 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2'])); | 1826 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2'])); |
| 1776 expect(usedElements.members, unorderedEquals(['_m2', '_m3'])); | 1827 expect(usedElements.members, unorderedEquals(['_m2', '_m3'])); |
| 1777 } | 1828 } |
| 1778 | 1829 |
| 1779 void _computeUsedElements(Source source) { | 1830 void _computeUsedElements(Source source) { |
| 1780 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1831 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1781 computeResult(target, USED_LOCAL_ELEMENTS); | 1832 computeResult(target, USED_LOCAL_ELEMENTS, |
| 1782 expect(task, new isInstanceOf<GatherUsedLocalElementsTask>()); | 1833 matcher: isGatherUsedLocalElementsTask); |
| 1783 usedElements = outputs[USED_LOCAL_ELEMENTS]; | 1834 usedElements = outputs[USED_LOCAL_ELEMENTS]; |
| 1784 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); | 1835 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); |
| 1785 } | 1836 } |
| 1786 } | 1837 } |
| 1787 | 1838 |
| 1788 @reflectiveTest | 1839 @reflectiveTest |
| 1789 class GenerateHintsTaskTest extends _AbstractDartTaskTest { | 1840 class GenerateHintsTaskTest extends _AbstractDartTaskTest { |
| 1790 test_perform_bestPractices_missingReturn() { | 1841 test_perform_bestPractices_missingReturn() { |
| 1791 Source source = newSource( | 1842 Source source = newSource( |
| 1792 '/test.dart', | 1843 '/test.dart', |
| 1793 ''' | 1844 ''' |
| 1794 int main() { | 1845 int main() { |
| 1795 } | 1846 } |
| 1796 '''); | 1847 '''); |
| 1797 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1848 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1798 computeResult(target, HINTS); | 1849 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 1799 expect(task, new isInstanceOf<GenerateHintsTask>()); | |
| 1800 // validate | 1850 // validate |
| 1801 _fillErrorListener(HINTS); | 1851 _fillErrorListener(HINTS); |
| 1802 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.MISSING_RETURN]); | 1852 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.MISSING_RETURN]); |
| 1803 } | 1853 } |
| 1804 | 1854 |
| 1805 test_perform_dart2js() { | 1855 test_perform_dart2js() { |
| 1806 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 1856 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 1807 options.dart2jsHint = true; | 1857 options.dart2jsHint = true; |
| 1808 prepareAnalysisContext(options); | 1858 prepareAnalysisContext(options); |
| 1809 Source source = newSource( | 1859 Source source = newSource( |
| 1810 '/test.dart', | 1860 '/test.dart', |
| 1811 ''' | 1861 ''' |
| 1812 main(p) { | 1862 main(p) { |
| 1813 if (p is double) { | 1863 if (p is double) { |
| 1814 print('double'); | 1864 print('double'); |
| 1815 } | 1865 } |
| 1816 } | 1866 } |
| 1817 '''); | 1867 '''); |
| 1818 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1868 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1819 computeResult(target, HINTS); | 1869 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 1820 expect(task, new isInstanceOf<GenerateHintsTask>()); | |
| 1821 // validate | 1870 // validate |
| 1822 _fillErrorListener(HINTS); | 1871 _fillErrorListener(HINTS); |
| 1823 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.IS_DOUBLE]); | 1872 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.IS_DOUBLE]); |
| 1824 } | 1873 } |
| 1825 | 1874 |
| 1826 test_perform_deadCode() { | 1875 test_perform_deadCode() { |
| 1827 Source source = newSource( | 1876 Source source = newSource( |
| 1828 '/test.dart', | 1877 '/test.dart', |
| 1829 ''' | 1878 ''' |
| 1830 main() { | 1879 main() { |
| 1831 if (false) { | 1880 if (false) { |
| 1832 print('how?'); | 1881 print('how?'); |
| 1833 } | 1882 } |
| 1834 } | 1883 } |
| 1835 '''); | 1884 '''); |
| 1836 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1885 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1837 computeResult(target, HINTS); | 1886 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 1838 expect(task, new isInstanceOf<GenerateHintsTask>()); | |
| 1839 // validate | 1887 // validate |
| 1840 _fillErrorListener(HINTS); | 1888 _fillErrorListener(HINTS); |
| 1841 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DEAD_CODE]); | 1889 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DEAD_CODE]); |
| 1842 } | 1890 } |
| 1843 | 1891 |
| 1844 test_perform_disabled() { | 1892 test_perform_disabled() { |
| 1845 context.analysisOptions = | 1893 context.analysisOptions = |
| 1846 new AnalysisOptionsImpl.from(context.analysisOptions)..hint = false; | 1894 new AnalysisOptionsImpl.from(context.analysisOptions)..hint = false; |
| 1847 Source source = newSource( | 1895 Source source = newSource( |
| 1848 '/test.dart', | 1896 '/test.dart', |
| 1849 ''' | 1897 ''' |
| 1850 int main() { | 1898 int main() { |
| 1851 } | 1899 } |
| 1852 '''); | 1900 '''); |
| 1853 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1901 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1854 computeResult(target, HINTS); | 1902 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 1855 expect(task, new isInstanceOf<GenerateHintsTask>()); | |
| 1856 // validate | 1903 // validate |
| 1857 _fillErrorListener(HINTS); | 1904 _fillErrorListener(HINTS); |
| 1858 errorListener.assertNoErrors(); | 1905 errorListener.assertNoErrors(); |
| 1859 } | 1906 } |
| 1860 | 1907 |
| 1861 test_perform_imports_duplicateImport() { | 1908 test_perform_imports_duplicateImport() { |
| 1862 newSource( | 1909 newSource( |
| 1863 '/a.dart', | 1910 '/a.dart', |
| 1864 r''' | 1911 r''' |
| 1865 library lib_a; | 1912 library lib_a; |
| 1866 class A {} | 1913 class A {} |
| 1867 '''); | 1914 '''); |
| 1868 Source source = newSource( | 1915 Source source = newSource( |
| 1869 '/test.dart', | 1916 '/test.dart', |
| 1870 r''' | 1917 r''' |
| 1871 import 'a.dart'; | 1918 import 'a.dart'; |
| 1872 import 'a.dart'; | 1919 import 'a.dart'; |
| 1873 main() { | 1920 main() { |
| 1874 new A(); | 1921 new A(); |
| 1875 } | 1922 } |
| 1876 '''); | 1923 '''); |
| 1877 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1924 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1878 computeResult(target, HINTS); | 1925 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 1879 expect(task, new isInstanceOf<GenerateHintsTask>()); | |
| 1880 // validate | 1926 // validate |
| 1881 _fillErrorListener(HINTS); | 1927 _fillErrorListener(HINTS); |
| 1882 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DUPLICATE_IMPORT]); | 1928 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DUPLICATE_IMPORT]); |
| 1883 } | 1929 } |
| 1884 | 1930 |
| 1885 test_perform_imports_unusedImport_one() { | 1931 test_perform_imports_unusedImport_one() { |
| 1886 newSource( | 1932 newSource( |
| 1887 '/a.dart', | 1933 '/a.dart', |
| 1888 r''' | 1934 r''' |
| 1889 library lib_a; | 1935 library lib_a; |
| 1890 class A {} | 1936 class A {} |
| 1891 '''); | 1937 '''); |
| 1892 newSource( | 1938 newSource( |
| 1893 '/b.dart', | 1939 '/b.dart', |
| 1894 r''' | 1940 r''' |
| 1895 library lib_b; | 1941 library lib_b; |
| 1896 class B {} | 1942 class B {} |
| 1897 '''); | 1943 '''); |
| 1898 Source source = newSource( | 1944 Source source = newSource( |
| 1899 '/test.dart', | 1945 '/test.dart', |
| 1900 r''' | 1946 r''' |
| 1901 import 'a.dart'; | 1947 import 'a.dart'; |
| 1902 import 'b.dart'; | 1948 import 'b.dart'; |
| 1903 main() { | 1949 main() { |
| 1904 new A(); | 1950 new A(); |
| 1905 }'''); | 1951 }'''); |
| 1906 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1952 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1907 computeResult(target, HINTS); | 1953 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 1908 expect(task, new isInstanceOf<GenerateHintsTask>()); | |
| 1909 // validate | 1954 // validate |
| 1910 _fillErrorListener(HINTS); | 1955 _fillErrorListener(HINTS); |
| 1911 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_IMPORT]); | 1956 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_IMPORT]); |
| 1912 } | 1957 } |
| 1913 | 1958 |
| 1914 test_perform_imports_unusedImport_zero() { | 1959 test_perform_imports_unusedImport_zero() { |
| 1915 newSource( | 1960 newSource( |
| 1916 '/a.dart', | 1961 '/a.dart', |
| 1917 r''' | 1962 r''' |
| 1918 library lib_a; | 1963 library lib_a; |
| 1919 class A {} | 1964 class A {} |
| 1920 '''); | 1965 '''); |
| 1921 Source source = newSource( | 1966 Source source = newSource( |
| 1922 '/test.dart', | 1967 '/test.dart', |
| 1923 r''' | 1968 r''' |
| 1924 import 'a.dart'; | 1969 import 'a.dart'; |
| 1925 main() { | 1970 main() { |
| 1926 new A(); | 1971 new A(); |
| 1927 }'''); | 1972 }'''); |
| 1928 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1973 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1929 computeResult(target, HINTS); | 1974 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 1930 expect(task, new isInstanceOf<GenerateHintsTask>()); | |
| 1931 // validate | 1975 // validate |
| 1932 _fillErrorListener(HINTS); | 1976 _fillErrorListener(HINTS); |
| 1933 errorListener.assertNoErrors(); | 1977 errorListener.assertNoErrors(); |
| 1934 } | 1978 } |
| 1935 | 1979 |
| 1936 test_perform_overrideVerifier() { | 1980 test_perform_overrideVerifier() { |
| 1937 Source source = newSource( | 1981 Source source = newSource( |
| 1938 '/test.dart', | 1982 '/test.dart', |
| 1939 ''' | 1983 ''' |
| 1940 class A {} | 1984 class A {} |
| 1941 class B { | 1985 class B { |
| 1942 @override | 1986 @override |
| 1943 m() {} | 1987 m() {} |
| 1944 } | 1988 } |
| 1945 '''); | 1989 '''); |
| 1946 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1990 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1947 computeResult(target, HINTS); | 1991 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 1948 expect(task, new isInstanceOf<GenerateHintsTask>()); | |
| 1949 // validate | 1992 // validate |
| 1950 _fillErrorListener(HINTS); | 1993 _fillErrorListener(HINTS); |
| 1951 errorListener.assertErrorsWithCodes( | 1994 errorListener.assertErrorsWithCodes( |
| 1952 <ErrorCode>[HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); | 1995 <ErrorCode>[HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); |
| 1953 } | 1996 } |
| 1954 | 1997 |
| 1955 test_perform_todo() { | 1998 test_perform_todo() { |
| 1956 Source source = newSource( | 1999 Source source = newSource( |
| 1957 '/test.dart', | 2000 '/test.dart', |
| 1958 ''' | 2001 ''' |
| 1959 main() { | 2002 main() { |
| 1960 // TODO(developer) foo bar | 2003 // TODO(developer) foo bar |
| 1961 } | 2004 } |
| 1962 '''); | 2005 '''); |
| 1963 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2006 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1964 computeResult(target, HINTS); | 2007 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 1965 expect(task, new isInstanceOf<GenerateHintsTask>()); | |
| 1966 // validate | 2008 // validate |
| 1967 _fillErrorListener(HINTS); | 2009 _fillErrorListener(HINTS); |
| 1968 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]); | 2010 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]); |
| 1969 } | 2011 } |
| 1970 | 2012 |
| 1971 test_perform_unusedLocalElements_class() { | 2013 test_perform_unusedLocalElements_class() { |
| 1972 Source source = newSource( | 2014 Source source = newSource( |
| 1973 '/test.dart', | 2015 '/test.dart', |
| 1974 ''' | 2016 ''' |
| 1975 class _A {} | 2017 class _A {} |
| 1976 class _B {} | 2018 class _B {} |
| 1977 main() { | 2019 main() { |
| 1978 new _A(); | 2020 new _A(); |
| 1979 } | 2021 } |
| 1980 '''); | 2022 '''); |
| 1981 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2023 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1982 computeResult(target, HINTS); | 2024 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 1983 expect(task, new isInstanceOf<GenerateHintsTask>()); | |
| 1984 // validate | 2025 // validate |
| 1985 _fillErrorListener(HINTS); | 2026 _fillErrorListener(HINTS); |
| 1986 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]); | 2027 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]); |
| 1987 } | 2028 } |
| 1988 | 2029 |
| 1989 test_perform_unusedLocalElements_localVariable() { | 2030 test_perform_unusedLocalElements_localVariable() { |
| 1990 Source source = newSource( | 2031 Source source = newSource( |
| 1991 '/test.dart', | 2032 '/test.dart', |
| 1992 ''' | 2033 ''' |
| 1993 main() { | 2034 main() { |
| 1994 var v = 42; | 2035 var v = 42; |
| 1995 } | 2036 } |
| 1996 '''); | 2037 '''); |
| 1997 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2038 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1998 computeResult(target, HINTS); | 2039 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 1999 expect(task, new isInstanceOf<GenerateHintsTask>()); | |
| 2000 // validate | 2040 // validate |
| 2001 _fillErrorListener(HINTS); | 2041 _fillErrorListener(HINTS); |
| 2002 errorListener | 2042 errorListener |
| 2003 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]); | 2043 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]); |
| 2004 } | 2044 } |
| 2005 | 2045 |
| 2006 test_perform_unusedLocalElements_method() { | 2046 test_perform_unusedLocalElements_method() { |
| 2007 Source source = newSource( | 2047 Source source = newSource( |
| 2008 '/my_lib.dart', | 2048 '/my_lib.dart', |
| 2009 ''' | 2049 ''' |
| 2010 library my_lib; | 2050 library my_lib; |
| 2011 part 'my_part.dart'; | 2051 part 'my_part.dart'; |
| 2012 class A { | 2052 class A { |
| 2013 _ma() {} | 2053 _ma() {} |
| 2014 _mb() {} | 2054 _mb() {} |
| 2015 _mc() {} | 2055 _mc() {} |
| 2016 } | 2056 } |
| 2017 '''); | 2057 '''); |
| 2018 newSource( | 2058 newSource( |
| 2019 '/my_part.dart', | 2059 '/my_part.dart', |
| 2020 ''' | 2060 ''' |
| 2021 part of my_lib; | 2061 part of my_lib; |
| 2022 | 2062 |
| 2023 f(A a) { | 2063 f(A a) { |
| 2024 a._mb(); | 2064 a._mb(); |
| 2025 } | 2065 } |
| 2026 '''); | 2066 '''); |
| 2027 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2067 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2028 computeResult(target, HINTS); | 2068 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2029 expect(task, new isInstanceOf<GenerateHintsTask>()); | |
| 2030 // validate | 2069 // validate |
| 2031 _fillErrorListener(HINTS); | 2070 _fillErrorListener(HINTS); |
| 2032 errorListener.assertErrorsWithCodes( | 2071 errorListener.assertErrorsWithCodes( |
| 2033 <ErrorCode>[HintCode.UNUSED_ELEMENT, HintCode.UNUSED_ELEMENT]); | 2072 <ErrorCode>[HintCode.UNUSED_ELEMENT, HintCode.UNUSED_ELEMENT]); |
| 2034 } | 2073 } |
| 2035 } | 2074 } |
| 2036 | 2075 |
| 2037 @reflectiveTest | 2076 @reflectiveTest |
| 2038 class InferInstanceMembersInUnitTaskTest extends _AbstractDartTaskTest { | 2077 class InferInstanceMembersInUnitTaskTest extends _AbstractDartTaskTest { |
| 2039 void test_perform() { | 2078 void test_perform() { |
| 2040 enableStrongMode(); | 2079 enableStrongMode(); |
| 2041 AnalysisTarget source = newSource( | 2080 AnalysisTarget source = newSource( |
| 2042 '/test.dart', | 2081 '/test.dart', |
| 2043 ''' | 2082 ''' |
| 2044 class A { | 2083 class A { |
| 2045 X f; | 2084 X f; |
| 2046 Y m(Z x) {} | 2085 Y m(Z x) {} |
| 2047 } | 2086 } |
| 2048 class B extends A { | 2087 class B extends A { |
| 2049 var f; | 2088 var f; |
| 2050 m(x) {} | 2089 m(x) {} |
| 2051 } | 2090 } |
| 2052 class X {} | 2091 class X {} |
| 2053 class Y {} | 2092 class Y {} |
| 2054 class Z {} | 2093 class Z {} |
| 2055 '''); | 2094 '''); |
| 2056 computeResult(new LibrarySpecificUnit(source, source), | 2095 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7, |
| 2057 RESOLVED_UNIT7); // new isInstanceOf<InferInstanceMembersInUnitTask>() | 2096 matcher: isInferInstanceMembersInUnitTask); |
| 2058 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 2097 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2059 VariableDeclaration field = getFieldInClass(unit, 'B', 'f'); | 2098 VariableDeclaration field = getFieldInClass(unit, 'B', 'f'); |
| 2060 MethodDeclaration method = getMethodInClass(unit, 'B', 'm'); | 2099 MethodDeclaration method = getMethodInClass(unit, 'B', 'm'); |
| 2061 DartType typeX = getClass(unit, 'X').element.type; | 2100 DartType typeX = getClass(unit, 'X').element.type; |
| 2062 DartType typeY = getClass(unit, 'Y').element.type; | 2101 DartType typeY = getClass(unit, 'Y').element.type; |
| 2063 DartType typeZ = getClass(unit, 'Z').element.type; | 2102 DartType typeZ = getClass(unit, 'Z').element.type; |
| 2064 | 2103 |
| 2065 expect(field.element.type, typeX); | 2104 expect(field.element.type, typeX); |
| 2066 expect(method.element.returnType, typeY); | 2105 expect(method.element.returnType, typeY); |
| 2067 expect(method.element.parameters[0].type, typeZ); | 2106 expect(method.element.parameters[0].type, typeZ); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2081 var c = b; | 2120 var c = b; |
| 2082 '''); | 2121 '''); |
| 2083 AnalysisTarget secondSource = newSource( | 2122 AnalysisTarget secondSource = newSource( |
| 2084 '/second.dart', | 2123 '/second.dart', |
| 2085 ''' | 2124 ''' |
| 2086 import 'first.dart'; | 2125 import 'first.dart'; |
| 2087 | 2126 |
| 2088 var b = a; | 2127 var b = a; |
| 2089 class M {} | 2128 class M {} |
| 2090 '''); | 2129 '''); |
| 2091 computeResult(new LibrarySpecificUnit(firstSource, firstSource), | 2130 computeResult( |
| 2092 RESOLVED_UNIT6); // new isInstanceOf<InferStaticVariableTypesInUnitTask
>() | 2131 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT6, |
| 2132 matcher: isInferStaticVariableTypesInUnitTask); |
| 2093 CompilationUnit firstUnit = outputs[RESOLVED_UNIT6]; | 2133 CompilationUnit firstUnit = outputs[RESOLVED_UNIT6]; |
| 2094 computeResult( | 2134 computeResult( |
| 2095 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT6); | 2135 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT6); |
| 2096 CompilationUnit secondUnit = outputs[RESOLVED_UNIT6]; | 2136 CompilationUnit secondUnit = outputs[RESOLVED_UNIT6]; |
| 2097 | 2137 |
| 2098 VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a'); | 2138 VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a'); |
| 2099 VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b'); | 2139 VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b'); |
| 2100 VariableDeclaration variableC = getTopLevelVariable(firstUnit, 'c'); | 2140 VariableDeclaration variableC = getTopLevelVariable(firstUnit, 'c'); |
| 2101 ClassDeclaration classM = getClass(secondUnit, 'M'); | 2141 ClassDeclaration classM = getClass(secondUnit, 'M'); |
| 2102 DartType typeM = classM.element.type; | 2142 DartType typeM = classM.element.type; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2152 var field = topLevel; | 2192 var field = topLevel; |
| 2153 } | 2193 } |
| 2154 '''); | 2194 '''); |
| 2155 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2195 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 2156 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2196 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2157 VariableElement topLevel = | 2197 VariableElement topLevel = |
| 2158 getTopLevelVariable(unit, 'topLevel').name.staticElement; | 2198 getTopLevelVariable(unit, 'topLevel').name.staticElement; |
| 2159 VariableElement field = | 2199 VariableElement field = |
| 2160 getFieldInClass(unit, 'C', 'field').name.staticElement; | 2200 getFieldInClass(unit, 'C', 'field').name.staticElement; |
| 2161 | 2201 |
| 2162 computeResult(field, INFERRED_STATIC_VARIABLE); | 2202 computeResult(field, INFERRED_STATIC_VARIABLE, |
| 2203 matcher: isInferStaticVariableTypeTask); |
| 2163 InterfaceType stringType = context.typeProvider.stringType; | 2204 InterfaceType stringType = context.typeProvider.stringType; |
| 2164 expect(topLevel.type, stringType); | 2205 expect(topLevel.type, stringType); |
| 2165 expect(field.type, stringType); | 2206 expect(field.type, stringType); |
| 2166 } | 2207 } |
| 2167 | 2208 |
| 2168 void test_perform_cycle() { | 2209 void test_perform_cycle() { |
| 2169 AnalysisTarget source = newSource( | 2210 AnalysisTarget source = newSource( |
| 2170 '/test.dart', | 2211 '/test.dart', |
| 2171 ''' | 2212 ''' |
| 2172 var piFirst = true; | 2213 var piFirst = true; |
| 2173 var pi = piFirst ? 3.14 : tau / 2; | 2214 var pi = piFirst ? 3.14 : tau / 2; |
| 2174 var tau = piFirst ? pi * 2 : 6.28; | 2215 var tau = piFirst ? pi * 2 : 6.28; |
| 2175 '''); | 2216 '''); |
| 2176 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2217 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 2177 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2218 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2178 VariableElement piFirst = | 2219 VariableElement piFirst = |
| 2179 getTopLevelVariable(unit, 'piFirst').name.staticElement; | 2220 getTopLevelVariable(unit, 'piFirst').name.staticElement; |
| 2180 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; | 2221 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; |
| 2181 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; | 2222 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; |
| 2182 | 2223 |
| 2183 computeResult(piFirst, INFERRED_STATIC_VARIABLE); | 2224 computeResult(piFirst, INFERRED_STATIC_VARIABLE, |
| 2225 matcher: isInferStaticVariableTypeTask); |
| 2184 expect(piFirst.type, context.typeProvider.boolType); | 2226 expect(piFirst.type, context.typeProvider.boolType); |
| 2185 expect(pi.type.isDynamic, isTrue); | 2227 expect(pi.type.isDynamic, isTrue); |
| 2186 expect(tau.type.isDynamic, isTrue); | 2228 expect(tau.type.isDynamic, isTrue); |
| 2187 } | 2229 } |
| 2188 | 2230 |
| 2189 void test_perform_null() { | 2231 void test_perform_null() { |
| 2190 AnalysisTarget source = newSource( | 2232 AnalysisTarget source = newSource( |
| 2191 '/test.dart', | 2233 '/test.dart', |
| 2192 ''' | 2234 ''' |
| 2193 var a = null; | 2235 var a = null; |
| 2194 '''); | 2236 '''); |
| 2195 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); | 2237 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); |
| 2196 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2238 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2197 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; | 2239 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; |
| 2198 | 2240 |
| 2199 computeResult(a, INFERRED_STATIC_VARIABLE); | 2241 computeResult(a, INFERRED_STATIC_VARIABLE, |
| 2242 matcher: isInferStaticVariableTypeTask); |
| 2200 expect(a.type.isDynamic, isTrue); | 2243 expect(a.type.isDynamic, isTrue); |
| 2201 } | 2244 } |
| 2202 } | 2245 } |
| 2203 | 2246 |
| 2204 @reflectiveTest | 2247 @reflectiveTest |
| 2205 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { | 2248 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { |
| 2206 test_perform() { | 2249 test_perform() { |
| 2207 Source library = newSource( | 2250 Source library = newSource( |
| 2208 '/lib.dart', | 2251 '/lib.dart', |
| 2209 r''' | 2252 r''' |
| 2210 library lib; | 2253 library lib; |
| 2211 part 'part1.dart'; | 2254 part 'part1.dart'; |
| 2212 part 'part2.dart'; | 2255 part 'part2.dart'; |
| 2213 X v1; | 2256 X v1; |
| 2214 '''); | 2257 '''); |
| 2215 Source part1 = newSource( | 2258 Source part1 = newSource( |
| 2216 '/part1.dart', | 2259 '/part1.dart', |
| 2217 r''' | 2260 r''' |
| 2218 part of lib; | 2261 part of lib; |
| 2219 X v2; | 2262 X v2; |
| 2220 '''); | 2263 '''); |
| 2221 Source part2 = newSource( | 2264 Source part2 = newSource( |
| 2222 '/part2.dart', | 2265 '/part2.dart', |
| 2223 r''' | 2266 r''' |
| 2224 part of lib; | 2267 part of lib; |
| 2225 X v3; | 2268 X v3; |
| 2226 '''); | 2269 '''); |
| 2227 computeResult(library, LIBRARY_ERRORS_READY); | 2270 computeResult(library, LIBRARY_ERRORS_READY, |
| 2228 expect(task, new isInstanceOf<LibraryErrorsReadyTask>()); | 2271 matcher: isLibraryErrorsReadyTask); |
| 2229 expect(outputs, hasLength(1)); | 2272 expect(outputs, hasLength(1)); |
| 2230 bool ready = outputs[LIBRARY_ERRORS_READY]; | 2273 bool ready = outputs[LIBRARY_ERRORS_READY]; |
| 2231 expect(ready, isTrue); | 2274 expect(ready, isTrue); |
| 2232 expect(context.getErrors(library).errors, hasLength(1)); | 2275 expect(context.getErrors(library).errors, hasLength(1)); |
| 2233 expect(context.getErrors(part1).errors, hasLength(1)); | 2276 expect(context.getErrors(part1).errors, hasLength(1)); |
| 2234 expect(context.getErrors(part2).errors, hasLength(1)); | 2277 expect(context.getErrors(part2).errors, hasLength(1)); |
| 2235 } | 2278 } |
| 2236 } | 2279 } |
| 2237 | 2280 |
| 2238 @reflectiveTest | 2281 @reflectiveTest |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2275 | 2318 |
| 2276 test_descriptor() { | 2319 test_descriptor() { |
| 2277 TaskDescriptor descriptor = LibraryUnitErrorsTask.DESCRIPTOR; | 2320 TaskDescriptor descriptor = LibraryUnitErrorsTask.DESCRIPTOR; |
| 2278 expect(descriptor, isNotNull); | 2321 expect(descriptor, isNotNull); |
| 2279 } | 2322 } |
| 2280 | 2323 |
| 2281 test_perform_definingCompilationUnit() { | 2324 test_perform_definingCompilationUnit() { |
| 2282 AnalysisTarget library = | 2325 AnalysisTarget library = |
| 2283 newSource('/test.dart', 'library test; import "dart:math";'); | 2326 newSource('/test.dart', 'library test; import "dart:math";'); |
| 2284 computeResult( | 2327 computeResult( |
| 2285 new LibrarySpecificUnit(library, library), LIBRARY_UNIT_ERRORS); | 2328 new LibrarySpecificUnit(library, library), LIBRARY_UNIT_ERRORS, |
| 2286 expect(task, new isInstanceOf<LibraryUnitErrorsTask>()); | 2329 matcher: isLibraryUnitErrorsTask); |
| 2287 expect(outputs, hasLength(1)); | 2330 expect(outputs, hasLength(1)); |
| 2288 List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS]; | 2331 List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS]; |
| 2289 expect(errors, hasLength(1)); | 2332 expect(errors, hasLength(1)); |
| 2290 } | 2333 } |
| 2291 | 2334 |
| 2292 test_perform_partInSingleLibrary() { | 2335 test_perform_partInSingleLibrary() { |
| 2293 AnalysisTarget library = | 2336 AnalysisTarget library = |
| 2294 newSource('/lib.dart', 'library test; part "part.dart";'); | 2337 newSource('/lib.dart', 'library test; part "part.dart";'); |
| 2295 AnalysisTarget part = newSource('/part.dart', 'part of test;'); | 2338 AnalysisTarget part = newSource('/part.dart', 'part of test;'); |
| 2296 computeResult(new LibrarySpecificUnit(library, part), LIBRARY_UNIT_ERRORS); | 2339 computeResult(new LibrarySpecificUnit(library, part), LIBRARY_UNIT_ERRORS, |
| 2297 expect(task, new isInstanceOf<LibraryUnitErrorsTask>()); | 2340 matcher: isLibraryUnitErrorsTask); |
| 2298 expect(outputs, hasLength(1)); | 2341 expect(outputs, hasLength(1)); |
| 2299 List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS]; | 2342 List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS]; |
| 2300 expect(errors, hasLength(0)); | 2343 expect(errors, hasLength(0)); |
| 2301 } | 2344 } |
| 2302 } | 2345 } |
| 2303 | 2346 |
| 2304 @reflectiveTest | 2347 @reflectiveTest |
| 2305 class ParseDartTaskTest extends _AbstractDartTaskTest { | 2348 class ParseDartTaskTest extends _AbstractDartTaskTest { |
| 2306 Source source; | 2349 Source source; |
| 2307 | 2350 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2444 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); | 2487 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 2445 expect(outputs[INCLUDED_PARTS], hasLength(0)); | 2488 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 2446 expect(outputs[PARSE_ERRORS], hasLength(0)); | 2489 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 2447 expect(outputs[PARSED_UNIT], isNotNull); | 2490 expect(outputs[PARSED_UNIT], isNotNull); |
| 2448 expect(outputs[SOURCE_KIND], SourceKind.PART); | 2491 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 2449 expect(outputs[UNITS], hasLength(1)); | 2492 expect(outputs[UNITS], hasLength(1)); |
| 2450 } | 2493 } |
| 2451 | 2494 |
| 2452 void _performParseTask(String content) { | 2495 void _performParseTask(String content) { |
| 2453 source = newSource('/test.dart', content); | 2496 source = newSource('/test.dart', content); |
| 2454 computeResult(source, PARSED_UNIT); | 2497 computeResult(source, PARSED_UNIT, matcher: isParseDartTask); |
| 2455 expect(task, new isInstanceOf<ParseDartTask>()); | |
| 2456 } | 2498 } |
| 2457 | 2499 |
| 2458 static void _assertHasCore(List<Source> sources, int lenght) { | 2500 static void _assertHasCore(List<Source> sources, int lenght) { |
| 2459 expect(sources, hasLength(lenght)); | 2501 expect(sources, hasLength(lenght)); |
| 2460 expect(sources, contains(predicate((Source s) { | 2502 expect(sources, contains(predicate((Source s) { |
| 2461 return s.fullName.endsWith('core.dart'); | 2503 return s.fullName.endsWith('core.dart'); |
| 2462 }))); | 2504 }))); |
| 2463 } | 2505 } |
| 2464 } | 2506 } |
| 2465 | 2507 |
| 2466 @reflectiveTest | 2508 @reflectiveTest |
| 2467 class PartiallyResolveReferencesTaskTest extends _AbstractDartTaskTest { | 2509 class PartiallyResolveUnitReferencesTaskTest extends _AbstractDartTaskTest { |
| 2468 test_perform() { | 2510 test_perform() { |
| 2469 enableStrongMode(); | 2511 enableStrongMode(); |
| 2470 Source source = newSource( | 2512 Source source = newSource( |
| 2471 '/test.dart', | 2513 '/test.dart', |
| 2472 ''' | 2514 ''' |
| 2473 int a = b; | 2515 int a = b; |
| 2474 int b = c; | 2516 int b = c; |
| 2475 var d = 0; | 2517 var d = 0; |
| 2476 class A {} | 2518 class A {} |
| 2477 class C { | 2519 class C { |
| 2478 static final f = ''; | 2520 static final f = ''; |
| 2479 var g = 0; | 2521 var g = 0; |
| 2480 } | 2522 } |
| 2481 '''); | 2523 '''); |
| 2482 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2524 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2483 computeResult(target, RESOLVED_UNIT5); | 2525 computeResult(target, RESOLVED_UNIT5, |
| 2484 expect(task, new isInstanceOf<PartiallyResolveUnitReferencesTask>()); | 2526 matcher: isPartiallyResolveUnitReferencesTask); |
| 2485 // Test the outputs | 2527 // Test the outputs |
| 2486 expect(outputs[CLASSES_IN_UNIT], hasLength(2)); | 2528 expect(outputs[CLASSES_IN_UNIT], hasLength(2)); |
| 2487 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(2)); | 2529 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(2)); |
| 2488 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2530 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2489 expect(unit, same(outputs[RESOLVED_UNIT5])); | 2531 expect(unit, same(outputs[RESOLVED_UNIT5])); |
| 2490 // Test the state of the AST | 2532 // Test the state of the AST |
| 2491 TopLevelVariableDeclaration a = unit.declarations[0]; | 2533 TopLevelVariableDeclaration a = unit.declarations[0]; |
| 2492 VariableDeclaration variableA = a.variables.variables[0]; | 2534 VariableDeclaration variableA = a.variables.variables[0]; |
| 2493 SimpleIdentifier initializer = variableA.initializer; | 2535 SimpleIdentifier initializer = variableA.initializer; |
| 2494 expect(initializer.staticElement, isNotNull); | 2536 expect(initializer.staticElement, isNotNull); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2515 '''); | 2557 '''); |
| 2516 Source sourceC = newSource( | 2558 Source sourceC = newSource( |
| 2517 '/c.dart', | 2559 '/c.dart', |
| 2518 ''' | 2560 ''' |
| 2519 library c; | 2561 library c; |
| 2520 import 'b.dart'; | 2562 import 'b.dart'; |
| 2521 main() { | 2563 main() { |
| 2522 new A<int>().m(); | 2564 new A<int>().m(); |
| 2523 } | 2565 } |
| 2524 '''); | 2566 '''); |
| 2525 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT5); | 2567 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT5, |
| 2526 expect(task, new isInstanceOf<PartiallyResolveUnitReferencesTask>()); | 2568 matcher: isPartiallyResolveUnitReferencesTask); |
| 2527 // validate | 2569 // validate |
| 2528 expect(outputs[CLASSES_IN_UNIT], hasLength(0)); | 2570 expect(outputs[CLASSES_IN_UNIT], hasLength(0)); |
| 2529 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0)); | 2571 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0)); |
| 2530 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 2572 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 2531 expect(unit, isNotNull); | 2573 expect(unit, isNotNull); |
| 2532 | 2574 |
| 2533 FunctionDeclaration functionDeclaration = unit.declarations[0]; | 2575 FunctionDeclaration functionDeclaration = unit.declarations[0]; |
| 2534 BlockFunctionBody body = functionDeclaration.functionExpression.body; | 2576 BlockFunctionBody body = functionDeclaration.functionExpression.body; |
| 2535 List<Statement> statements = body.block.statements; | 2577 List<Statement> statements = body.block.statements; |
| 2536 ExpressionStatement statement = statements[0]; | 2578 ExpressionStatement statement = statements[0]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2552 part 'my_part.dart'; | 2594 part 'my_part.dart'; |
| 2553 class A {} | 2595 class A {} |
| 2554 class B extends A {} | 2596 class B extends A {} |
| 2555 '''); | 2597 '''); |
| 2556 newSource( | 2598 newSource( |
| 2557 '/my_part.dart', | 2599 '/my_part.dart', |
| 2558 ''' | 2600 ''' |
| 2559 part of my_lib; | 2601 part of my_lib; |
| 2560 class C extends A {} | 2602 class C extends A {} |
| 2561 '''); | 2603 '''); |
| 2562 computeResult(sourceLib, LIBRARY_ELEMENT5); | 2604 computeResult(sourceLib, LIBRARY_ELEMENT5, |
| 2563 expect(task, new isInstanceOf<ResolveLibraryTypeNamesTask>()); | 2605 matcher: isResolveLibraryTypeNamesTask); |
| 2564 // validate | 2606 // validate |
| 2565 LibraryElement library = outputs[LIBRARY_ELEMENT5]; | 2607 LibraryElement library = outputs[LIBRARY_ELEMENT5]; |
| 2566 { | 2608 { |
| 2567 ClassElement classB = library.getType('B'); | 2609 ClassElement classB = library.getType('B'); |
| 2568 expect(classB.supertype.displayName, 'A'); | 2610 expect(classB.supertype.displayName, 'A'); |
| 2569 } | 2611 } |
| 2570 { | 2612 { |
| 2571 ClassElement classC = library.getType('C'); | 2613 ClassElement classC = library.getType('C'); |
| 2572 expect(classC.supertype.displayName, 'A'); | 2614 expect(classC.supertype.displayName, 'A'); |
| 2573 } | 2615 } |
| 2574 } | 2616 } |
| 2575 | 2617 |
| 2576 test_perform_external() { | 2618 test_perform_external() { |
| 2577 Source sourceA = newSource( | 2619 Source sourceA = newSource( |
| 2578 '/a.dart', | 2620 '/a.dart', |
| 2579 ''' | 2621 ''' |
| 2580 library a; | 2622 library a; |
| 2581 import 'b.dart'; | 2623 import 'b.dart'; |
| 2582 class A extends B {} | 2624 class A extends B {} |
| 2583 '''); | 2625 '''); |
| 2584 newSource( | 2626 newSource( |
| 2585 '/b.dart', | 2627 '/b.dart', |
| 2586 ''' | 2628 ''' |
| 2587 library b; | 2629 library b; |
| 2588 class B {} | 2630 class B {} |
| 2589 '''); | 2631 '''); |
| 2590 // The reference A to B should be resolved, but there's no requirement that | 2632 // The reference A to B should be resolved, but there's no requirement that |
| 2591 // the full class hierarchy be resolved. | 2633 // the full class hierarchy be resolved. |
| 2592 computeResult(sourceA, LIBRARY_ELEMENT5); | 2634 computeResult(sourceA, LIBRARY_ELEMENT5, |
| 2593 expect(task, new isInstanceOf<ResolveLibraryTypeNamesTask>()); | 2635 matcher: isResolveLibraryTypeNamesTask); |
| 2594 // validate | 2636 // validate |
| 2595 LibraryElement library = outputs[LIBRARY_ELEMENT5]; | 2637 LibraryElement library = outputs[LIBRARY_ELEMENT5]; |
| 2596 { | 2638 { |
| 2597 ClassElement clazz = library.getType('A'); | 2639 ClassElement clazz = library.getType('A'); |
| 2598 expect(clazz.displayName, 'A'); | 2640 expect(clazz.displayName, 'A'); |
| 2599 clazz = clazz.supertype.element; | 2641 clazz = clazz.supertype.element; |
| 2600 expect(clazz.displayName, 'B'); | 2642 expect(clazz.displayName, 'B'); |
| 2601 } | 2643 } |
| 2602 } | 2644 } |
| 2603 } | 2645 } |
| 2604 | 2646 |
| 2605 @reflectiveTest | 2647 @reflectiveTest |
| 2606 class ResolveReferencesTaskTest extends _AbstractDartTaskTest { | 2648 class ResolveUnitReferencesTaskTest extends _AbstractDartTaskTest { |
| 2607 test_perform() { | 2649 test_perform() { |
| 2608 Source source = newSource( | 2650 Source source = newSource( |
| 2609 '/test.dart', | 2651 '/test.dart', |
| 2610 ''' | 2652 ''' |
| 2611 class A { | 2653 class A { |
| 2612 m() {} | 2654 m() {} |
| 2613 } | 2655 } |
| 2614 main(A a) { | 2656 main(A a) { |
| 2615 a.m(); | 2657 a.m(); |
| 2616 } | 2658 } |
| 2617 '''); | 2659 '''); |
| 2618 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2660 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2619 // prepare unit and "a.m()" invocation | 2661 // prepare unit and "a.m()" invocation |
| 2620 computeResult(target, RESOLVED_UNIT8); | 2662 computeResult(target, RESOLVED_UNIT8, matcher: isResolveUnitReferencesTask); |
| 2621 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 2663 CompilationUnit unit = outputs[RESOLVED_UNIT8]; |
| 2622 // walk the AST | 2664 // walk the AST |
| 2623 FunctionDeclaration function = unit.declarations[1]; | 2665 FunctionDeclaration function = unit.declarations[1]; |
| 2624 BlockFunctionBody body = function.functionExpression.body; | 2666 BlockFunctionBody body = function.functionExpression.body; |
| 2625 ExpressionStatement statement = body.block.statements[0]; | 2667 ExpressionStatement statement = body.block.statements[0]; |
| 2626 MethodInvocation invocation = statement.expression; | 2668 MethodInvocation invocation = statement.expression; |
| 2627 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); | |
| 2628 expect(unit, same(outputs[RESOLVED_UNIT8])); | 2669 expect(unit, same(outputs[RESOLVED_UNIT8])); |
| 2629 // a.m() is resolved now | 2670 // a.m() is resolved now |
| 2630 expect(invocation.methodName.staticElement, isNotNull); | 2671 expect(invocation.methodName.staticElement, isNotNull); |
| 2631 } | 2672 } |
| 2632 | 2673 |
| 2633 test_perform_errors() { | 2674 test_perform_errors() { |
| 2634 Source source = newSource( | 2675 Source source = newSource( |
| 2635 '/test.dart', | 2676 '/test.dart', |
| 2636 ''' | 2677 ''' |
| 2637 class A { | 2678 class A { |
| 2638 } | 2679 } |
| 2639 main(A a) { | 2680 main(A a) { |
| 2640 a.unknownMethod(); | 2681 a.unknownMethod(); |
| 2641 } | 2682 } |
| 2642 '''); | 2683 '''); |
| 2643 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2684 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2644 computeResult(target, RESOLVED_UNIT8); | 2685 computeResult(target, RESOLVED_UNIT8, matcher: isResolveUnitReferencesTask); |
| 2645 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); | |
| 2646 // validate | 2686 // validate |
| 2647 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); | 2687 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); |
| 2648 errorListener.assertErrorsWithCodes( | 2688 errorListener.assertErrorsWithCodes( |
| 2649 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); | 2689 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); |
| 2650 } | 2690 } |
| 2651 | 2691 |
| 2652 test_perform_importExport() { | 2692 test_perform_importExport() { |
| 2653 newSource( | 2693 newSource( |
| 2654 '/a.dart', | 2694 '/a.dart', |
| 2655 ''' | 2695 ''' |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2666 '''); | 2706 '''); |
| 2667 Source sourceC = newSource( | 2707 Source sourceC = newSource( |
| 2668 '/c.dart', | 2708 '/c.dart', |
| 2669 ''' | 2709 ''' |
| 2670 library c; | 2710 library c; |
| 2671 import 'b.dart'; | 2711 import 'b.dart'; |
| 2672 main() { | 2712 main() { |
| 2673 new A<int>().m(); | 2713 new A<int>().m(); |
| 2674 } | 2714 } |
| 2675 '''); | 2715 '''); |
| 2676 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT8); | 2716 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT8, |
| 2677 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); | 2717 matcher: isResolveUnitReferencesTask); |
| 2678 // validate | 2718 // validate |
| 2679 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 2719 CompilationUnit unit = outputs[RESOLVED_UNIT8]; |
| 2680 expect(unit, isNotNull); | 2720 expect(unit, isNotNull); |
| 2681 { | 2721 FunctionDeclaration functionDeclaration = unit.declarations[0]; |
| 2682 FunctionDeclaration functionDeclaration = unit.declarations[0]; | 2722 BlockFunctionBody body = functionDeclaration.functionExpression.body; |
| 2683 BlockFunctionBody body = functionDeclaration.functionExpression.body; | 2723 List<Statement> statements = body.block.statements; |
| 2684 List<Statement> statements = body.block.statements; | 2724 ExpressionStatement statement = statements[0]; |
| 2685 ExpressionStatement statement = statements[0]; | 2725 MethodInvocation invocation = statement.expression; |
| 2686 MethodInvocation invocation = statement.expression; | 2726 MethodElement methodElement = invocation.methodName.staticElement; |
| 2687 MethodElement methodElement = invocation.methodName.staticElement; | 2727 expect(methodElement, isNotNull); |
| 2688 expect(methodElement, isNotNull); | 2728 expect(methodElement.type, isNotNull); |
| 2689 expect(methodElement.type, isNotNull); | 2729 expect(methodElement.returnType.toString(), 'int'); |
| 2690 expect(methodElement.returnType.toString(), 'int'); | |
| 2691 } | |
| 2692 } | 2730 } |
| 2693 } | 2731 } |
| 2694 | 2732 |
| 2695 @reflectiveTest | 2733 @reflectiveTest |
| 2696 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { | 2734 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 2697 test_perform() { | 2735 test_perform() { |
| 2698 Source source = newSource( | 2736 Source source = newSource( |
| 2699 '/test.dart', | 2737 '/test.dart', |
| 2700 ''' | 2738 ''' |
| 2701 class A {} | 2739 class A {} |
| 2702 class B extends A {} | 2740 class B extends A {} |
| 2703 int f(String p) => p.length; | 2741 int f(String p) => p.length; |
| 2704 '''); | 2742 '''); |
| 2705 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2743 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2706 computeResult(target, RESOLVED_UNIT3); | 2744 computeResult(target, RESOLVED_UNIT3, matcher: isResolveUnitTypeNamesTask); |
| 2707 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | |
| 2708 // validate | 2745 // validate |
| 2709 CompilationUnit unit = outputs[RESOLVED_UNIT3]; | 2746 CompilationUnit unit = outputs[RESOLVED_UNIT3]; |
| 2710 { | 2747 { |
| 2711 ClassDeclaration nodeA = unit.declarations[0]; | 2748 ClassDeclaration nodeA = unit.declarations[0]; |
| 2712 ClassDeclaration nodeB = unit.declarations[1]; | 2749 ClassDeclaration nodeB = unit.declarations[1]; |
| 2713 DartType extendsType = nodeB.extendsClause.superclass.type; | 2750 DartType extendsType = nodeB.extendsClause.superclass.type; |
| 2714 expect(extendsType, nodeA.element.type); | 2751 expect(extendsType, nodeA.element.type); |
| 2715 } | 2752 } |
| 2716 { | 2753 { |
| 2717 FunctionDeclaration functionNode = unit.declarations[2]; | 2754 FunctionDeclaration functionNode = unit.declarations[2]; |
| 2718 DartType returnType = functionNode.returnType.type; | 2755 DartType returnType = functionNode.returnType.type; |
| 2719 List<FormalParameter> parameters = | 2756 List<FormalParameter> parameters = |
| 2720 functionNode.functionExpression.parameters.parameters; | 2757 functionNode.functionExpression.parameters.parameters; |
| 2721 expect(returnType.displayName, 'int'); | 2758 expect(returnType.displayName, 'int'); |
| 2722 expect(parameters[0].element.type.displayName, 'String'); | 2759 expect(parameters[0].element.type.displayName, 'String'); |
| 2723 } | 2760 } |
| 2724 } | 2761 } |
| 2725 | 2762 |
| 2726 test_perform_errors() { | 2763 test_perform_errors() { |
| 2727 Source source = newSource( | 2764 Source source = newSource( |
| 2728 '/test.dart', | 2765 '/test.dart', |
| 2729 ''' | 2766 ''' |
| 2730 NoSuchClass f() => null; | 2767 NoSuchClass f() => null; |
| 2731 '''); | 2768 '''); |
| 2732 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2769 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2733 computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); | 2770 computeResult(target, RESOLVE_TYPE_NAMES_ERRORS, |
| 2734 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | 2771 matcher: isResolveUnitTypeNamesTask); |
| 2735 // validate | 2772 // validate |
| 2736 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); | 2773 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); |
| 2737 errorListener | 2774 errorListener |
| 2738 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 2775 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 2739 } | 2776 } |
| 2740 | 2777 |
| 2741 test_perform_typedef() { | 2778 test_perform_typedef() { |
| 2742 Source source = newSource( | 2779 Source source = newSource( |
| 2743 '/test.dart', | 2780 '/test.dart', |
| 2744 ''' | 2781 ''' |
| 2745 typedef int F(G g); | 2782 typedef int F(G g); |
| 2746 typedef String G(int p); | 2783 typedef String G(int p); |
| 2747 '''); | 2784 '''); |
| 2748 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2785 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2749 computeResult(target, RESOLVED_UNIT3); | 2786 computeResult(target, RESOLVED_UNIT3, matcher: isResolveUnitTypeNamesTask); |
| 2750 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | |
| 2751 // validate | 2787 // validate |
| 2752 CompilationUnit unit = outputs[RESOLVED_UNIT3]; | 2788 CompilationUnit unit = outputs[RESOLVED_UNIT3]; |
| 2753 FunctionTypeAlias nodeF = unit.declarations[0]; | 2789 FunctionTypeAlias nodeF = unit.declarations[0]; |
| 2754 FunctionTypeAlias nodeG = unit.declarations[1]; | 2790 FunctionTypeAlias nodeG = unit.declarations[1]; |
| 2755 { | 2791 { |
| 2756 FormalParameter parameter = nodeF.parameters.parameters[0]; | 2792 FormalParameter parameter = nodeF.parameters.parameters[0]; |
| 2757 DartType parameterType = parameter.element.type; | 2793 DartType parameterType = parameter.element.type; |
| 2758 Element returnTypeElement = nodeF.returnType.type.element; | 2794 Element returnTypeElement = nodeF.returnType.type.element; |
| 2759 expect(returnTypeElement.displayName, 'int'); | 2795 expect(returnTypeElement.displayName, 'int'); |
| 2760 expect(parameterType.element, nodeG.element); | 2796 expect(parameterType.element, nodeG.element); |
| 2761 } | 2797 } |
| 2762 { | 2798 { |
| 2763 FormalParameter parameter = nodeG.parameters.parameters[0]; | 2799 FormalParameter parameter = nodeG.parameters.parameters[0]; |
| 2764 DartType parameterType = parameter.element.type; | 2800 DartType parameterType = parameter.element.type; |
| 2765 expect(nodeG.returnType.type.element.displayName, 'String'); | 2801 expect(nodeG.returnType.type.element.displayName, 'String'); |
| 2766 expect(parameterType.element.displayName, 'int'); | 2802 expect(parameterType.element.displayName, 'int'); |
| 2767 } | 2803 } |
| 2768 } | 2804 } |
| 2769 | 2805 |
| 2770 test_perform_typedef_errors() { | 2806 test_perform_typedef_errors() { |
| 2771 Source source = newSource( | 2807 Source source = newSource( |
| 2772 '/test.dart', | 2808 '/test.dart', |
| 2773 ''' | 2809 ''' |
| 2774 typedef int F(NoSuchType p); | 2810 typedef int F(NoSuchType p); |
| 2775 '''); | 2811 '''); |
| 2776 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2812 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2777 computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); | 2813 computeResult(target, RESOLVE_TYPE_NAMES_ERRORS, |
| 2778 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); | 2814 matcher: isResolveUnitTypeNamesTask); |
| 2779 // validate | 2815 // validate |
| 2780 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); | 2816 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); |
| 2781 errorListener | 2817 errorListener |
| 2782 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 2818 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 2783 } | 2819 } |
| 2784 } | 2820 } |
| 2785 | 2821 |
| 2786 @reflectiveTest | 2822 @reflectiveTest |
| 2787 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { | 2823 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { |
| 2788 /** | 2824 /** |
| 2789 * Verify that the mutated states of the given [variable] correspond to the | 2825 * Verify that the mutated states of the given [variable] correspond to the |
| 2790 * [mutatedInClosure] and [mutatedInScope] matchers. | 2826 * [mutatedInClosure] and [mutatedInScope] matchers. |
| 2791 */ | 2827 */ |
| 2792 void expectMutated(VariableElement variable, Matcher mutatedInClosure, | 2828 void expectMutated(VariableElement variable, Matcher mutatedInClosure, |
| 2793 Matcher mutatedInScope) { | 2829 Matcher mutatedInScope) { |
| 2794 expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure); | 2830 expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure); |
| 2795 expect(variable.isPotentiallyMutatedInScope, mutatedInScope); | 2831 expect(variable.isPotentiallyMutatedInScope, mutatedInScope); |
| 2796 } | 2832 } |
| 2797 | 2833 |
| 2798 test_perform_buildClosureLibraryElements() { | 2834 test_perform_buildClosureLibraryElements() { |
| 2799 Source source = newSource( | 2835 Source source = newSource( |
| 2800 '/test.dart', | 2836 '/test.dart', |
| 2801 ''' | 2837 ''' |
| 2802 main() { | 2838 main() { |
| 2803 } | 2839 } |
| 2804 '''); | 2840 '''); |
| 2805 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2841 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2806 computeResult(target, RESOLVED_UNIT4); | 2842 computeResult(target, RESOLVED_UNIT4, |
| 2807 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); | 2843 matcher: isResolveVariableReferencesTask); |
| 2808 } | 2844 } |
| 2809 | 2845 |
| 2810 test_perform_local() { | 2846 test_perform_local() { |
| 2811 Source source = newSource( | 2847 Source source = newSource( |
| 2812 '/test.dart', | 2848 '/test.dart', |
| 2813 ''' | 2849 ''' |
| 2814 main() { | 2850 main() { |
| 2815 var v1 = 1; | 2851 var v1 = 1; |
| 2816 var v2 = 1; | 2852 var v2 = 1; |
| 2817 var v3 = 1; | 2853 var v3 = 1; |
| 2818 var v4 = 1; | 2854 var v4 = 1; |
| 2819 v2 = 2; | 2855 v2 = 2; |
| 2820 v4 = 2; | 2856 v4 = 2; |
| 2821 localFunction() { | 2857 localFunction() { |
| 2822 v3 = 3; | 2858 v3 = 3; |
| 2823 v4 = 3; | 2859 v4 = 3; |
| 2824 } | 2860 } |
| 2825 } | 2861 } |
| 2826 '''); | 2862 '''); |
| 2827 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2863 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2828 computeResult(target, RESOLVED_UNIT4); | 2864 computeResult(target, RESOLVED_UNIT4, |
| 2829 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); | 2865 matcher: isResolveVariableReferencesTask); |
| 2830 // validate | 2866 // validate |
| 2831 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 2867 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 2832 FunctionElement main = unit.element.functions[0]; | 2868 FunctionElement main = unit.element.functions[0]; |
| 2833 expectMutated(main.localVariables[0], isFalse, isFalse); | 2869 expectMutated(main.localVariables[0], isFalse, isFalse); |
| 2834 expectMutated(main.localVariables[1], isFalse, isTrue); | 2870 expectMutated(main.localVariables[1], isFalse, isTrue); |
| 2835 expectMutated(main.localVariables[2], isTrue, isTrue); | 2871 expectMutated(main.localVariables[2], isTrue, isTrue); |
| 2836 expectMutated(main.localVariables[3], isTrue, isTrue); | 2872 expectMutated(main.localVariables[3], isTrue, isTrue); |
| 2837 } | 2873 } |
| 2838 | 2874 |
| 2839 test_perform_parameter() { | 2875 test_perform_parameter() { |
| 2840 Source source = newSource( | 2876 Source source = newSource( |
| 2841 '/test.dart', | 2877 '/test.dart', |
| 2842 ''' | 2878 ''' |
| 2843 main(p1, p2, p3, p4) { | 2879 main(p1, p2, p3, p4) { |
| 2844 p2 = 2; | 2880 p2 = 2; |
| 2845 p4 = 2; | 2881 p4 = 2; |
| 2846 localFunction() { | 2882 localFunction() { |
| 2847 p3 = 3; | 2883 p3 = 3; |
| 2848 p4 = 3; | 2884 p4 = 3; |
| 2849 } | 2885 } |
| 2850 } | 2886 } |
| 2851 '''); | 2887 '''); |
| 2852 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2888 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2853 computeResult(target, RESOLVED_UNIT4); | 2889 computeResult(target, RESOLVED_UNIT4, |
| 2854 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); | 2890 matcher: isResolveVariableReferencesTask); |
| 2855 // validate | 2891 // validate |
| 2856 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 2892 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 2857 FunctionElement main = unit.element.functions[0]; | 2893 FunctionElement main = unit.element.functions[0]; |
| 2858 expectMutated(main.parameters[0], isFalse, isFalse); | 2894 expectMutated(main.parameters[0], isFalse, isFalse); |
| 2859 expectMutated(main.parameters[1], isFalse, isTrue); | 2895 expectMutated(main.parameters[1], isFalse, isTrue); |
| 2860 expectMutated(main.parameters[2], isTrue, isTrue); | 2896 expectMutated(main.parameters[2], isTrue, isTrue); |
| 2861 expectMutated(main.parameters[3], isTrue, isTrue); | 2897 expectMutated(main.parameters[3], isTrue, isTrue); |
| 2862 } | 2898 } |
| 2863 } | 2899 } |
| 2864 | 2900 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2921 <title>test page</title> | 2957 <title>test page</title> |
| 2922 <script type='application/dart'>$scriptContent</script> | 2958 <script type='application/dart'>$scriptContent</script> |
| 2923 </head> | 2959 </head> |
| 2924 <body>Test</body> | 2960 <body>Test</body> |
| 2925 </html> | 2961 </html> |
| 2926 '''; | 2962 '''; |
| 2927 Source source = newSource('/test.html', htmlContent); | 2963 Source source = newSource('/test.html', htmlContent); |
| 2928 DartScript script = | 2964 DartScript script = |
| 2929 new DartScript(source, [new ScriptFragment(97, 5, 36, scriptContent)]); | 2965 new DartScript(source, [new ScriptFragment(97, 5, 36, scriptContent)]); |
| 2930 | 2966 |
| 2931 computeResult(script, TOKEN_STREAM); | 2967 computeResult(script, TOKEN_STREAM, matcher: isScanDartTask); |
| 2932 expect(task, new isInstanceOf<ScanDartTask>()); | |
| 2933 expect(outputs[LINE_INFO], isNotNull); | 2968 expect(outputs[LINE_INFO], isNotNull); |
| 2934 expect(outputs[SCAN_ERRORS], isEmpty); | 2969 expect(outputs[SCAN_ERRORS], isEmpty); |
| 2935 Token tokenStream = outputs[TOKEN_STREAM]; | 2970 Token tokenStream = outputs[TOKEN_STREAM]; |
| 2936 expect(tokenStream, isNotNull); | 2971 expect(tokenStream, isNotNull); |
| 2937 expect(tokenStream.lexeme, 'void'); | 2972 expect(tokenStream.lexeme, 'void'); |
| 2938 } | 2973 } |
| 2939 | 2974 |
| 2940 void _performScanTask(String content) { | 2975 void _performScanTask(String content) { |
| 2941 AnalysisTarget target = newSource('/test.dart', content); | 2976 AnalysisTarget target = newSource('/test.dart', content); |
| 2942 computeResult(target, TOKEN_STREAM); | 2977 computeResult(target, TOKEN_STREAM, matcher: isScanDartTask); |
| 2943 expect(task, new isInstanceOf<ScanDartTask>()); | |
| 2944 } | 2978 } |
| 2945 } | 2979 } |
| 2946 | 2980 |
| 2947 @reflectiveTest | 2981 @reflectiveTest |
| 2948 class VerifyUnitTaskTest extends _AbstractDartTaskTest { | 2982 class VerifyUnitTaskTest extends _AbstractDartTaskTest { |
| 2949 test_perform_constantError() { | 2983 test_perform_constantError() { |
| 2950 Source source = newSource( | 2984 Source source = newSource( |
| 2951 '/test.dart', | 2985 '/test.dart', |
| 2952 ''' | 2986 ''' |
| 2953 main(int p) { | 2987 main(int p) { |
| 2954 const v = p; | 2988 const v = p; |
| 2955 } | 2989 } |
| 2956 '''); | 2990 '''); |
| 2957 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2991 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2958 computeResult(target, VERIFY_ERRORS); | 2992 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 2959 expect(task, new isInstanceOf<VerifyUnitTask>()); | |
| 2960 // validate | 2993 // validate |
| 2961 _fillErrorListener(VERIFY_ERRORS); | 2994 _fillErrorListener(VERIFY_ERRORS); |
| 2962 errorListener.assertErrorsWithCodes(<ErrorCode>[ | 2995 errorListener.assertErrorsWithCodes(<ErrorCode>[ |
| 2963 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 2996 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 2964 ]); | 2997 ]); |
| 2965 } | 2998 } |
| 2966 | 2999 |
| 2967 test_perform_directiveError() { | 3000 test_perform_directiveError() { |
| 2968 Source source = newSource( | 3001 Source source = newSource( |
| 2969 '/test.dart', | 3002 '/test.dart', |
| 2970 ''' | 3003 ''' |
| 2971 import 'no-such-file.dart'; | 3004 import 'no-such-file.dart'; |
| 2972 '''); | 3005 '''); |
| 2973 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3006 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2974 computeResult(target, VERIFY_ERRORS); | 3007 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 2975 expect(task, new isInstanceOf<VerifyUnitTask>()); | |
| 2976 // validate | 3008 // validate |
| 2977 _fillErrorListener(VERIFY_ERRORS); | 3009 _fillErrorListener(VERIFY_ERRORS); |
| 2978 errorListener.assertErrorsWithCodes( | 3010 errorListener.assertErrorsWithCodes( |
| 2979 <ErrorCode>[CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 3011 <ErrorCode>[CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 2980 } | 3012 } |
| 2981 | 3013 |
| 2982 test_perform_verifyError() { | 3014 test_perform_verifyError() { |
| 2983 Source source = newSource( | 3015 Source source = newSource( |
| 2984 '/test.dart', | 3016 '/test.dart', |
| 2985 ''' | 3017 ''' |
| 2986 main() { | 3018 main() { |
| 2987 if (42) { | 3019 if (42) { |
| 2988 print('Not bool!'); | 3020 print('Not bool!'); |
| 2989 } | 3021 } |
| 2990 } | 3022 } |
| 2991 '''); | 3023 '''); |
| 2992 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3024 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2993 computeResult(target, VERIFY_ERRORS); | 3025 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 2994 expect(task, new isInstanceOf<VerifyUnitTask>()); | |
| 2995 // validate | 3026 // validate |
| 2996 _fillErrorListener(VERIFY_ERRORS); | 3027 _fillErrorListener(VERIFY_ERRORS); |
| 2997 errorListener.assertErrorsWithCodes( | 3028 errorListener.assertErrorsWithCodes( |
| 2998 <ErrorCode>[StaticTypeWarningCode.NON_BOOL_CONDITION]); | 3029 <ErrorCode>[StaticTypeWarningCode.NON_BOOL_CONDITION]); |
| 2999 } | 3030 } |
| 3000 } | 3031 } |
| 3001 | 3032 |
| 3002 class _AbstractDartTaskTest extends AbstractContextTest { | 3033 class _AbstractDartTaskTest extends AbstractContextTest { |
| 3003 Source emptySource; | 3034 Source emptySource; |
| 3004 | 3035 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3136 /** | 3167 /** |
| 3137 * Fill [errorListener] with [result] errors in the current [task]. | 3168 * Fill [errorListener] with [result] errors in the current [task]. |
| 3138 */ | 3169 */ |
| 3139 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 3170 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 3140 List<AnalysisError> errors = task.outputs[result]; | 3171 List<AnalysisError> errors = task.outputs[result]; |
| 3141 expect(errors, isNotNull, reason: result.name); | 3172 expect(errors, isNotNull, reason: result.name); |
| 3142 errorListener = new GatheringErrorListener(); | 3173 errorListener = new GatheringErrorListener(); |
| 3143 errorListener.addAll(errors); | 3174 errorListener.addAll(errors); |
| 3144 } | 3175 } |
| 3145 } | 3176 } |
| OLD | NEW |