| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.src.task.dart_test; | 5 library test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 import '../../generated/test_support.dart'; | 30 import '../../generated/test_support.dart'; |
| 31 import '../../reflective_tests.dart'; | 31 import '../../reflective_tests.dart'; |
| 32 import '../mock_sdk.dart'; | 32 import '../mock_sdk.dart'; |
| 33 | 33 |
| 34 main() { | 34 main() { |
| 35 groupSep = ' | '; | 35 groupSep = ' | '; |
| 36 runReflectiveTests(BuildCompilationUnitElementTaskTest); | 36 runReflectiveTests(BuildCompilationUnitElementTaskTest); |
| 37 runReflectiveTests(BuildDirectiveElementsTaskTest); | 37 runReflectiveTests(BuildDirectiveElementsTaskTest); |
| 38 runReflectiveTests(BuildEnumMemberElementsTaskTest); | 38 runReflectiveTests(BuildEnumMemberElementsTaskTest); |
| 39 runReflectiveTests(BuildExportSourceClosureTaskTest); | 39 runReflectiveTests(BuildExportSourceClosureTaskTest); |
| 40 runReflectiveTests(BuildExportNamespaceTaskTest); |
| 40 runReflectiveTests(BuildLibraryElementTaskTest); | 41 runReflectiveTests(BuildLibraryElementTaskTest); |
| 41 runReflectiveTests(BuildPublicNamespaceTaskTest); | 42 runReflectiveTests(BuildPublicNamespaceTaskTest); |
| 42 runReflectiveTests(BuildTypeProviderTaskTest); | 43 runReflectiveTests(BuildTypeProviderTaskTest); |
| 43 runReflectiveTests(ParseDartTaskTest); | 44 runReflectiveTests(ParseDartTaskTest); |
| 44 runReflectiveTests(ScanDartTaskTest); | 45 runReflectiveTests(ScanDartTaskTest); |
| 45 } | 46 } |
| 46 | 47 |
| 47 @reflectiveTest | 48 @reflectiveTest |
| 48 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { | 49 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { |
| 49 test_buildInputs() { | 50 test_buildInputs() { |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 432 |
| 432 static void _assertGetter(FieldElement field) { | 433 static void _assertGetter(FieldElement field) { |
| 433 PropertyAccessorElement getter = field.getter; | 434 PropertyAccessorElement getter = field.getter; |
| 434 expect(getter, isNotNull); | 435 expect(getter, isNotNull); |
| 435 expect(getter.variable, same(field)); | 436 expect(getter.variable, same(field)); |
| 436 expect(getter.type, isNotNull); | 437 expect(getter.type, isNotNull); |
| 437 } | 438 } |
| 438 } | 439 } |
| 439 | 440 |
| 440 @reflectiveTest | 441 @reflectiveTest |
| 442 class BuildExportNamespaceTaskTest extends _AbstractDartTaskTest { |
| 443 test_perform_entyrPoint() { |
| 444 Source sourceA = _newSource('/a.dart', ''' |
| 445 library lib_a; |
| 446 export 'b.dart'; |
| 447 '''); |
| 448 Source sourceB = _newSource('/b.dart', ''' |
| 449 library lib_b; |
| 450 main() {} |
| 451 '''); |
| 452 _computeResult(sourceA, LIBRARY_ELEMENT3); |
| 453 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); |
| 454 // validate |
| 455 { |
| 456 LibraryElement library = outputs[LIBRARY_ELEMENT3]; |
| 457 FunctionElement entryPoint = library.entryPoint; |
| 458 expect(entryPoint, isNotNull); |
| 459 expect(entryPoint.source, sourceB); |
| 460 } |
| 461 } |
| 462 |
| 463 test_perform_hideCombinator() { |
| 464 Source sourceA = _newSource('/a.dart', ''' |
| 465 library lib_a; |
| 466 export 'b.dart' hide B1; |
| 467 class A1 {} |
| 468 class A2 {} |
| 469 class _A3 {} |
| 470 '''); |
| 471 _newSource('/b.dart', ''' |
| 472 library lib_b; |
| 473 class B1 {} |
| 474 class B2 {} |
| 475 class B3 {} |
| 476 class _B4 {} |
| 477 '''); |
| 478 _newSource('/c.dart', ''' |
| 479 library lib_c; |
| 480 class C1 {} |
| 481 class C2 {} |
| 482 class C3 {} |
| 483 '''); |
| 484 _computeResult(sourceA, EXPORT_NAMESPACE); |
| 485 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); |
| 486 // validate |
| 487 { |
| 488 Namespace namespace = outputs[EXPORT_NAMESPACE]; |
| 489 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 490 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B2', 'B3'])); |
| 491 } |
| 492 } |
| 493 |
| 494 test_perform_showCombinator() { |
| 495 Source sourceA = _newSource('/a.dart', ''' |
| 496 library lib_a; |
| 497 export 'b.dart' show B1; |
| 498 class A1 {} |
| 499 class A2 {} |
| 500 class _A3 {} |
| 501 '''); |
| 502 _newSource('/b.dart', ''' |
| 503 library lib_b; |
| 504 class B1 {} |
| 505 class B2 {} |
| 506 class _B3 {} |
| 507 '''); |
| 508 _computeResult(sourceA, EXPORT_NAMESPACE); |
| 509 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); |
| 510 // validate |
| 511 { |
| 512 Namespace namespace = outputs[EXPORT_NAMESPACE]; |
| 513 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 514 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B1'])); |
| 515 } |
| 516 } |
| 517 |
| 518 test_perform_showCombinator_setter() { |
| 519 Source sourceA = _newSource('/a.dart', ''' |
| 520 library lib_a; |
| 521 export 'b.dart' show topLevelB; |
| 522 class A {} |
| 523 '''); |
| 524 _newSource('/b.dart', ''' |
| 525 library lib_b; |
| 526 int topLevelB; |
| 527 '''); |
| 528 _computeResult(sourceA, EXPORT_NAMESPACE); |
| 529 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); |
| 530 // validate |
| 531 { |
| 532 Namespace namespace = outputs[EXPORT_NAMESPACE]; |
| 533 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 534 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); |
| 535 } |
| 536 } |
| 537 } |
| 538 |
| 539 @reflectiveTest |
| 441 class BuildExportSourceClosureTaskTest extends _AbstractDartTaskTest { | 540 class BuildExportSourceClosureTaskTest extends _AbstractDartTaskTest { |
| 442 test_perform() { | 541 test_perform() { |
| 443 Source sourceA = _newSource('/a.dart', ''' | 542 Source sourceA = _newSource('/a.dart', ''' |
| 444 library lib_a; | 543 library lib_a; |
| 445 export 'b.dart'; | 544 export 'b.dart'; |
| 446 '''); | 545 '''); |
| 447 Source sourceB = _newSource('/b.dart', ''' | 546 Source sourceB = _newSource('/b.dart', ''' |
| 448 library lib_b; | 547 library lib_b; |
| 449 export 'b.dart'; | 548 export 'b.dart'; |
| 450 '''); | 549 '''); |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 ]); | 1070 ]); |
| 972 // prepare TaskManager | 1071 // prepare TaskManager |
| 973 taskManager.addTaskDescriptor(GetContentTask.DESCRIPTOR); | 1072 taskManager.addTaskDescriptor(GetContentTask.DESCRIPTOR); |
| 974 taskManager.addTaskDescriptor(ScanDartTask.DESCRIPTOR); | 1073 taskManager.addTaskDescriptor(ScanDartTask.DESCRIPTOR); |
| 975 taskManager.addTaskDescriptor(ParseDartTask.DESCRIPTOR); | 1074 taskManager.addTaskDescriptor(ParseDartTask.DESCRIPTOR); |
| 976 taskManager.addTaskDescriptor(BuildCompilationUnitElementTask.DESCRIPTOR); | 1075 taskManager.addTaskDescriptor(BuildCompilationUnitElementTask.DESCRIPTOR); |
| 977 taskManager.addTaskDescriptor(BuildLibraryElementTask.DESCRIPTOR); | 1076 taskManager.addTaskDescriptor(BuildLibraryElementTask.DESCRIPTOR); |
| 978 taskManager.addTaskDescriptor(BuildPublicNamespaceTask.DESCRIPTOR); | 1077 taskManager.addTaskDescriptor(BuildPublicNamespaceTask.DESCRIPTOR); |
| 979 taskManager.addTaskDescriptor(BuildDirectiveElementsTask.DESCRIPTOR); | 1078 taskManager.addTaskDescriptor(BuildDirectiveElementsTask.DESCRIPTOR); |
| 980 taskManager.addTaskDescriptor(BuildExportSourceClosureTask.DESCRIPTOR); | 1079 taskManager.addTaskDescriptor(BuildExportSourceClosureTask.DESCRIPTOR); |
| 1080 taskManager.addTaskDescriptor(BuildExportNamespaceTask.DESCRIPTOR); |
| 981 taskManager.addTaskDescriptor(BuildTypeProviderTask.DESCRIPTOR); | 1081 taskManager.addTaskDescriptor(BuildTypeProviderTask.DESCRIPTOR); |
| 982 taskManager.addTaskDescriptor(BuildEnumMemberElementsTask.DESCRIPTOR); | 1082 taskManager.addTaskDescriptor(BuildEnumMemberElementsTask.DESCRIPTOR); |
| 983 // prepare AnalysisDriver | 1083 // prepare AnalysisDriver |
| 984 analysisDriver = new AnalysisDriver(taskManager, context); | 1084 analysisDriver = new AnalysisDriver(taskManager, context); |
| 985 } | 1085 } |
| 986 | 1086 |
| 987 void _computeResult(AnalysisTarget target, ResultDescriptor result) { | 1087 void _computeResult(AnalysisTarget target, ResultDescriptor result) { |
| 988 task = analysisDriver.computeResult(target, result); | 1088 task = analysisDriver.computeResult(target, result); |
| 989 expect(task.caughtException, isNull); | 1089 expect(task.caughtException, isNull); |
| 990 outputs = task.outputs; | 1090 outputs = task.outputs; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 | 1127 |
| 1028 bool exists(Source source) => source.exists(); | 1128 bool exists(Source source) => source.exists(); |
| 1029 | 1129 |
| 1030 @override | 1130 @override |
| 1031 CacheEntry getCacheEntry(AnalysisTarget target) { | 1131 CacheEntry getCacheEntry(AnalysisTarget target) { |
| 1032 return entryMap.putIfAbsent(target, () => new CacheEntry()); | 1132 return entryMap.putIfAbsent(target, () => new CacheEntry()); |
| 1033 } | 1133 } |
| 1034 | 1134 |
| 1035 TimestampedData<String> getContents(Source source) => source.contents; | 1135 TimestampedData<String> getContents(Source source) => source.contents; |
| 1036 | 1136 |
| 1037 @override | |
| 1038 Namespace getPublicNamespace(LibraryElement library) { | |
| 1039 // TODO(scheglov) Should be be replaced with an explicit input? | |
| 1040 // TODO(scheglov) Based on... LibraryElement's closure? | |
| 1041 var cacheEntry = getCacheEntry(library.source); | |
| 1042 return cacheEntry.getValue(PUBLIC_NAMESPACE); | |
| 1043 } | |
| 1044 | |
| 1045 noSuchMethod(Invocation invocation) { | 1137 noSuchMethod(Invocation invocation) { |
| 1046 print('noSuchMethod: ${invocation.memberName}'); | 1138 print('noSuchMethod: ${invocation.memberName}'); |
| 1047 return super.noSuchMethod(invocation); | 1139 return super.noSuchMethod(invocation); |
| 1048 } | 1140 } |
| 1049 } | 1141 } |
| OLD | NEW |