Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1023443002: Add public and export namespaces to LibraryElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 context.getCacheEntry(sourceC).setValue(LIBRARY_ELEMENT1, libraryElementC); 130 context.getCacheEntry(sourceC).setValue(LIBRARY_ELEMENT1, libraryElementC);
131 context.getCacheEntry(sourceC).setValue(SOURCE_KIND, SourceKind.LIBRARY); 131 context.getCacheEntry(sourceC).setValue(SOURCE_KIND, SourceKind.LIBRARY);
132 // request inputs 132 // request inputs
133 WorkItem workItem = 133 WorkItem workItem =
134 new WorkItem(context, sourceA, BuildDirectiveElementsTask.DESCRIPTOR); 134 new WorkItem(context, sourceA, BuildDirectiveElementsTask.DESCRIPTOR);
135 workItem.gatherInputs(null); 135 workItem.gatherInputs(null);
136 Map<String, dynamic> inputs = workItem.inputs; 136 Map<String, dynamic> inputs = workItem.inputs;
137 expect(inputs, hasLength(5)); 137 expect(inputs, hasLength(5));
138 expect(inputs[BuildDirectiveElementsTask.RESOLVED_UNIT2_INPUT_NAME], unitA); 138 expect(inputs[BuildDirectiveElementsTask.RESOLVED_UNIT2_INPUT_NAME], unitA);
139 expect( 139 expect(
140 inputs[BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME], 140 inputs[BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT_INPUT_NAME],
141 containsPair(sourceB, libraryElementB)); 141 containsPair(sourceB, libraryElementB));
142 expect( 142 expect(
143 inputs[BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME], 143 inputs[BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT_INPUT_NAME],
144 containsPair(sourceC, libraryElementC)); 144 containsPair(sourceC, libraryElementC));
145 expect(inputs[BuildDirectiveElementsTask.IMPORTS_SOURCE_KIND_INPUT_NAME], 145 expect(inputs[BuildDirectiveElementsTask.IMPORTS_SOURCE_KIND_INPUT_NAME],
146 containsPair(sourceB, SourceKind.LIBRARY)); 146 containsPair(sourceB, SourceKind.LIBRARY));
147 expect(inputs[BuildDirectiveElementsTask.EXPORTS_SOURCE_KIND_INPUT_NAME], 147 expect(inputs[BuildDirectiveElementsTask.EXPORTS_SOURCE_KIND_INPUT_NAME],
148 containsPair(sourceC, SourceKind.LIBRARY)); 148 containsPair(sourceC, SourceKind.LIBRARY));
149 } 149 }
150 150
151 test_constructor() { 151 test_constructor() {
152 BuildDirectiveElementsTask task = 152 BuildDirectiveElementsTask task =
153 new BuildDirectiveElementsTask(context, emptySource); 153 new BuildDirectiveElementsTask(context, emptySource);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 expect(importElementC.prefix, prefixElement); 359 expect(importElementC.prefix, prefixElement);
360 } 360 }
361 } 361 }
362 362
363 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { 363 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) {
364 _fillErrorListener(BUILD_DIRECTIVES_ERRORS); 364 _fillErrorListener(BUILD_DIRECTIVES_ERRORS);
365 errorListener.assertErrorsWithCodes(expectedErrorCodes); 365 errorListener.assertErrorsWithCodes(expectedErrorCodes);
366 } 366 }
367 367
368 _getExportLibraryInput(Source source) { 368 _getExportLibraryInput(Source source) {
369 var key = BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME; 369 var key = BuildDirectiveElementsTask.EXPORTS_LIBRARY_ELEMENT_INPUT_NAME;
370 return task.inputs[key][source]; 370 return task.inputs[key][source];
371 } 371 }
372 372
373 _getImportLibraryInput(Source source) { 373 _getImportLibraryInput(Source source) {
374 var key = BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME; 374 var key = BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT_INPUT_NAME;
375 return task.inputs[key][source]; 375 return task.inputs[key][source];
376 } 376 }
377 } 377 }
378 378
379 @reflectiveTest 379 @reflectiveTest
380 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { 380 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest {
381 test_perform() { 381 test_perform() {
382 Source source = _newSource('/test.dart', ''' 382 Source source = _newSource('/test.dart', '''
383 enum MyEnum { 383 enum MyEnum {
384 A, B 384 A, B
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 class BuildExportNamespaceTaskTest extends _AbstractDartTaskTest { 442 class BuildExportNamespaceTaskTest extends _AbstractDartTaskTest {
443 test_perform_entyrPoint() { 443 test_perform_entyrPoint() {
444 Source sourceA = _newSource('/a.dart', ''' 444 Source sourceA = _newSource('/a.dart', '''
445 library lib_a; 445 library lib_a;
446 export 'b.dart'; 446 export 'b.dart';
447 '''); 447 ''');
448 Source sourceB = _newSource('/b.dart', ''' 448 Source sourceB = _newSource('/b.dart', '''
449 library lib_b; 449 library lib_b;
450 main() {} 450 main() {}
451 '''); 451 ''');
452 _computeResult(sourceA, LIBRARY_ELEMENT3); 452 _computeResult(sourceA, LIBRARY_ELEMENT4);
453 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); 453 expect(task, new isInstanceOf<BuildExportNamespaceTask>());
454 // validate 454 // validate
455 { 455 {
456 LibraryElement library = outputs[LIBRARY_ELEMENT3]; 456 LibraryElement library = outputs[LIBRARY_ELEMENT4];
457 FunctionElement entryPoint = library.entryPoint; 457 FunctionElement entryPoint = library.entryPoint;
458 expect(entryPoint, isNotNull); 458 expect(entryPoint, isNotNull);
459 expect(entryPoint.source, sourceB); 459 expect(entryPoint.source, sourceB);
460 } 460 }
461 } 461 }
462 462
463 test_perform_hideCombinator() { 463 test_perform_hideCombinator() {
464 Source sourceA = _newSource('/a.dart', ''' 464 Source sourceA = _newSource('/a.dart', '''
465 library lib_a; 465 library lib_a;
466 export 'b.dart' hide B1; 466 export 'b.dart' hide B1;
467 class A1 {} 467 class A1 {}
468 class A2 {} 468 class A2 {}
469 class _A3 {} 469 class _A3 {}
470 '''); 470 ''');
471 _newSource('/b.dart', ''' 471 _newSource('/b.dart', '''
472 library lib_b; 472 library lib_b;
473 class B1 {} 473 class B1 {}
474 class B2 {} 474 class B2 {}
475 class B3 {} 475 class B3 {}
476 class _B4 {} 476 class _B4 {}
477 '''); 477 ''');
478 _newSource('/c.dart', ''' 478 _newSource('/c.dart', '''
479 library lib_c; 479 library lib_c;
480 class C1 {} 480 class C1 {}
481 class C2 {} 481 class C2 {}
482 class C3 {} 482 class C3 {}
483 '''); 483 ''');
484 _computeResult(sourceA, EXPORT_NAMESPACE); 484 _computeResult(sourceA, LIBRARY_ELEMENT4);
485 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); 485 expect(task, new isInstanceOf<BuildExportNamespaceTask>());
486 // validate 486 // validate
487 { 487 {
488 Namespace namespace = outputs[EXPORT_NAMESPACE]; 488 LibraryElement library = outputs[LIBRARY_ELEMENT4];
489 Namespace namespace = library.exportNamespace;
489 Iterable<String> definedKeys = namespace.definedNames.keys; 490 Iterable<String> definedKeys = namespace.definedNames.keys;
490 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B2', 'B3'])); 491 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B2', 'B3']));
491 } 492 }
492 } 493 }
493 494
494 test_perform_showCombinator() { 495 test_perform_showCombinator() {
495 Source sourceA = _newSource('/a.dart', ''' 496 Source sourceA = _newSource('/a.dart', '''
496 library lib_a; 497 library lib_a;
497 export 'b.dart' show B1; 498 export 'b.dart' show B1;
498 class A1 {} 499 class A1 {}
499 class A2 {} 500 class A2 {}
500 class _A3 {} 501 class _A3 {}
501 '''); 502 ''');
502 _newSource('/b.dart', ''' 503 _newSource('/b.dart', '''
503 library lib_b; 504 library lib_b;
504 class B1 {} 505 class B1 {}
505 class B2 {} 506 class B2 {}
506 class _B3 {} 507 class _B3 {}
507 '''); 508 ''');
508 _computeResult(sourceA, EXPORT_NAMESPACE); 509 _computeResult(sourceA, LIBRARY_ELEMENT4);
509 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); 510 expect(task, new isInstanceOf<BuildExportNamespaceTask>());
510 // validate 511 // validate
511 { 512 {
512 Namespace namespace = outputs[EXPORT_NAMESPACE]; 513 LibraryElement library = outputs[LIBRARY_ELEMENT4];
514 Namespace namespace = library.exportNamespace;
513 Iterable<String> definedKeys = namespace.definedNames.keys; 515 Iterable<String> definedKeys = namespace.definedNames.keys;
514 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B1'])); 516 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B1']));
515 } 517 }
516 } 518 }
517 519
518 test_perform_showCombinator_setter() { 520 test_perform_showCombinator_setter() {
519 Source sourceA = _newSource('/a.dart', ''' 521 Source sourceA = _newSource('/a.dart', '''
520 library lib_a; 522 library lib_a;
521 export 'b.dart' show topLevelB; 523 export 'b.dart' show topLevelB;
522 class A {} 524 class A {}
523 '''); 525 ''');
524 _newSource('/b.dart', ''' 526 _newSource('/b.dart', '''
525 library lib_b; 527 library lib_b;
526 int topLevelB; 528 int topLevelB;
527 '''); 529 ''');
528 _computeResult(sourceA, EXPORT_NAMESPACE); 530 _computeResult(sourceA, LIBRARY_ELEMENT4);
529 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); 531 expect(task, new isInstanceOf<BuildExportNamespaceTask>());
530 // validate 532 // validate
531 { 533 {
532 Namespace namespace = outputs[EXPORT_NAMESPACE]; 534 LibraryElement library = outputs[LIBRARY_ELEMENT4];
535 Namespace namespace = library.exportNamespace;
533 Iterable<String> definedKeys = namespace.definedNames.keys; 536 Iterable<String> definedKeys = namespace.definedNames.keys;
534 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); 537 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB=']));
535 } 538 }
536 } 539 }
537 } 540 }
538 541
539 @reflectiveTest 542 @reflectiveTest
540 class BuildExportSourceClosureTaskTest extends _AbstractDartTaskTest { 543 class BuildExportSourceClosureTaskTest extends _AbstractDartTaskTest {
541 test_perform() { 544 test_perform() {
542 Source sourceA = _newSource('/a.dart', ''' 545 Source sourceA = _newSource('/a.dart', '''
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 task.inputs[BuildLibraryElementTask.PARTS_RESOLVED_UNIT1_INPUT_NAME]; 821 task.inputs[BuildLibraryElementTask.PARTS_RESOLVED_UNIT1_INPUT_NAME];
819 } 822 }
820 } 823 }
821 824
822 @reflectiveTest 825 @reflectiveTest
823 class BuildPublicNamespaceTaskTest extends _AbstractDartTaskTest { 826 class BuildPublicNamespaceTaskTest extends _AbstractDartTaskTest {
824 test_buildInputs() { 827 test_buildInputs() {
825 Map<String, TaskInput> inputs = 828 Map<String, TaskInput> inputs =
826 BuildPublicNamespaceTask.buildInputs(emptySource); 829 BuildPublicNamespaceTask.buildInputs(emptySource);
827 expect(inputs, isNotNull); 830 expect(inputs, isNotNull);
828 expect(inputs.keys, unorderedEquals( 831 expect(
829 [BuildPublicNamespaceTask.BUILT_LIBRARY_ELEMENT_INPUT_NAME])); 832 inputs.keys, unorderedEquals([BuildPublicNamespaceTask.LIBRARY_INPUT]));
830 } 833 }
831 834
832 test_constructor() { 835 test_constructor() {
833 BuildPublicNamespaceTask task = 836 BuildPublicNamespaceTask task =
834 new BuildPublicNamespaceTask(context, emptySource); 837 new BuildPublicNamespaceTask(context, emptySource);
835 expect(task, isNotNull); 838 expect(task, isNotNull);
836 expect(task.context, context); 839 expect(task.context, context);
837 expect(task.target, emptySource); 840 expect(task.target, emptySource);
838 } 841 }
839 842
(...skipping 23 matching lines...) Expand all
863 part 'part.dart'; 866 part 'part.dart';
864 a() {} 867 a() {}
865 _b() {} 868 _b() {}
866 ''', 869 ''',
867 '/part.dart': ''' 870 '/part.dart': '''
868 part of lib; 871 part of lib;
869 _c() {} 872 _c() {}
870 d() {} 873 d() {}
871 ''' 874 '''
872 }); 875 });
873 _computeResult(sources.first, PUBLIC_NAMESPACE); 876 _computeResult(sources.first, LIBRARY_ELEMENT3);
874 expect(task, new isInstanceOf<BuildPublicNamespaceTask>()); 877 expect(task, new isInstanceOf<BuildPublicNamespaceTask>());
875 // validate 878 // validate
876 Namespace namespace = outputs[PUBLIC_NAMESPACE]; 879 LibraryElement library = outputs[LIBRARY_ELEMENT3];
880 Namespace namespace = library.publicNamespace;
877 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd'])); 881 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd']));
878 } 882 }
879 } 883 }
880 884
881 @reflectiveTest 885 @reflectiveTest
882 class BuildTypeProviderTaskTest extends _AbstractDartTaskTest { 886 class BuildTypeProviderTaskTest extends _AbstractDartTaskTest {
883 test_perform() { 887 test_perform() {
884 _computeResult(AnalysisContextTarget.request, TYPE_PROVIDER); 888 _computeResult(AnalysisContextTarget.request, TYPE_PROVIDER);
885 expect(task, new isInstanceOf<BuildTypeProviderTask>()); 889 expect(task, new isInstanceOf<BuildTypeProviderTask>());
886 // validate 890 // validate
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 return entryMap.putIfAbsent(target, () => new CacheEntry()); 1136 return entryMap.putIfAbsent(target, () => new CacheEntry());
1133 } 1137 }
1134 1138
1135 TimestampedData<String> getContents(Source source) => source.contents; 1139 TimestampedData<String> getContents(Source source) => source.contents;
1136 1140
1137 noSuchMethod(Invocation invocation) { 1141 noSuchMethod(Invocation invocation) {
1138 print('noSuchMethod: ${invocation.memberName}'); 1142 print('noSuchMethod: ${invocation.memberName}');
1139 return super.noSuchMethod(invocation); 1143 return super.noSuchMethod(invocation);
1140 } 1144 }
1141 } 1145 }
OLDNEW
« pkg/analyzer/lib/src/task/dart.dart ('K') | « pkg/analyzer/lib/task/dart.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698