| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 analyzer.test.generated.resolver_test_case; | 5 library analyzer.test.generated.resolver_test_case; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 11 import 'package:analyzer/dart/ast/visitor.dart'; | 11 import 'package:analyzer/dart/ast/visitor.dart'; |
| 12 import 'package:analyzer/dart/element/element.dart'; | 12 import 'package:analyzer/dart/element/element.dart'; |
| 13 import 'package:analyzer/dart/element/type.dart'; | 13 import 'package:analyzer/dart/element/type.dart'; |
| 14 import 'package:analyzer/error/error.dart'; | 14 import 'package:analyzer/error/error.dart'; |
| 15 import 'package:analyzer/file_system/file_system.dart'; | 15 import 'package:analyzer/file_system/file_system.dart'; |
| 16 import 'package:analyzer/file_system/memory_file_system.dart'; | 16 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 17 import 'package:analyzer/source/package_map_resolver.dart'; | 17 import 'package:analyzer/source/package_map_resolver.dart'; |
| 18 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 18 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 19 import 'package:analyzer/src/dart/analysis/driver.dart'; | 19 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 20 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 20 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 21 import 'package:analyzer/src/dart/element/element.dart'; | 21 import 'package:analyzer/src/dart/element/element.dart'; |
| 22 import 'package:analyzer/src/dart/element/type.dart'; | 22 import 'package:analyzer/src/dart/element/type.dart'; |
| 23 import 'package:analyzer/src/error/codes.dart'; | 23 import 'package:analyzer/src/error/codes.dart'; |
| 24 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult; | 24 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult; |
| 25 import 'package:analyzer/src/generated/java_engine.dart'; | 25 import 'package:analyzer/src/generated/java_engine.dart'; |
| 26 import 'package:analyzer/src/generated/resolver.dart'; | 26 import 'package:analyzer/src/generated/resolver.dart'; |
| 27 import 'package:analyzer/src/generated/sdk.dart'; |
| 27 import 'package:analyzer/src/generated/source_io.dart'; | 28 import 'package:analyzer/src/generated/source_io.dart'; |
| 28 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; | 29 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; |
| 29 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 30 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 30 import 'package:test/test.dart'; | 31 import 'package:test/test.dart'; |
| 31 | 32 |
| 32 import '../src/dart/analysis/physical_sdk.dart' as physical_sdk; | 33 import '../src/dart/analysis/physical_sdk.dart' as physical_sdk; |
| 33 import 'analysis_context_factory.dart'; | 34 import 'analysis_context_factory.dart'; |
| 34 import 'test_support.dart'; | 35 import 'test_support.dart'; |
| 35 | 36 |
| 36 /** | 37 /** |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 } | 639 } |
| 639 } | 640 } |
| 640 } | 641 } |
| 641 return null; | 642 return null; |
| 642 // Not found | 643 // Not found |
| 643 } | 644 } |
| 644 | 645 |
| 645 /** | 646 /** |
| 646 * Re-create the analysis context being used by the test case. | 647 * Re-create the analysis context being used by the test case. |
| 647 */ | 648 */ |
| 648 void reset({List<List<String>> packages}) { | 649 void reset() { |
| 650 resetWith(); |
| 651 } |
| 652 |
| 653 /** |
| 654 * Re-create the analysis context being used by the test with the either given |
| 655 * [options] or [packages]. |
| 656 */ |
| 657 void resetWith({AnalysisOptions options, List<List<String>> packages}) { |
| 658 if (options != null && packages != null) { |
| 659 fail('Only packages or options can be specified.'); |
| 660 } |
| 649 if (enableNewAnalysisDriver) { | 661 if (enableNewAnalysisDriver) { |
| 650 PerformanceLog log = new PerformanceLog(_logBuffer); | 662 options ??= new AnalysisOptionsImpl(); |
| 651 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(log); | 663 DartSdk sdk = |
| 664 options.strongMode ? physical_sdk.strongSdk : physical_sdk.sdk; |
| 652 | 665 |
| 653 List<UriResolver> resolvers = <UriResolver>[ | 666 List<UriResolver> resolvers = <UriResolver>[ |
| 654 new DartUriResolver(physical_sdk.sdk), | 667 new DartUriResolver(sdk), |
| 655 new ResourceUriResolver(resourceProvider) | 668 new ResourceUriResolver(resourceProvider) |
| 656 ]; | 669 ]; |
| 657 if (packages != null) { | 670 if (packages != null) { |
| 658 var packageMap = <String, List<Folder>>{}; | 671 var packageMap = <String, List<Folder>>{}; |
| 659 packages.forEach((args) { | 672 packages.forEach((args) { |
| 660 String name = args[0]; | 673 String name = args[0]; |
| 661 String path = | 674 String path = |
| 662 resourceProvider.convertPath('/packages/$name/$name.dart'); | 675 resourceProvider.convertPath('/packages/$name/$name.dart'); |
| 663 String content = args[1]; | 676 String content = args[1]; |
| 664 File file = resourceProvider.newFile(path, content); | 677 File file = resourceProvider.newFile(path, content); |
| 665 packageMap[name] = <Folder>[file.parent]; | 678 packageMap[name] = <Folder>[file.parent]; |
| 666 }); | 679 }); |
| 667 resolvers.add(new PackageMapUriResolver(resourceProvider, packageMap)); | 680 resolvers.add(new PackageMapUriResolver(resourceProvider, packageMap)); |
| 668 } | 681 } |
| 669 SourceFactory sourceFactory = new SourceFactory(resolvers); | 682 SourceFactory sourceFactory = new SourceFactory(resolvers); |
| 670 | 683 |
| 671 driver = new AnalysisDriver( | 684 PerformanceLog log = new PerformanceLog(_logBuffer); |
| 672 scheduler, | 685 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(log); |
| 673 log, | 686 driver = new AnalysisDriver(scheduler, log, resourceProvider, |
| 674 resourceProvider, | 687 new MemoryByteStore(), _fileContentOverlay, sourceFactory, options); |
| 675 new MemoryByteStore(), | |
| 676 _fileContentOverlay, | |
| 677 sourceFactory, | |
| 678 new AnalysisOptionsImpl()); | |
| 679 scheduler.start(); | 688 scheduler.start(); |
| 680 } else { | 689 } else { |
| 681 if (packages != null) { | 690 if (packages != null) { |
| 682 var packageMap = <String, String>{}; | 691 var packageMap = <String, String>{}; |
| 683 packages.forEach((args) { | 692 packages.forEach((args) { |
| 684 String name = args[0]; | 693 String name = args[0]; |
| 685 String content = args[1]; | 694 String content = args[1]; |
| 686 packageMap['package:$name/$name.dart'] = content; | 695 packageMap['package:$name/$name.dart'] = content; |
| 687 }); | 696 }); |
| 688 analysisContext2 = AnalysisContextFactory.contextWithCoreAndPackages( | 697 analysisContext2 = AnalysisContextFactory.contextWithCoreAndPackages( |
| 689 packageMap, | 698 packageMap, |
| 690 resourceProvider: resourceProvider); | 699 resourceProvider: resourceProvider); |
| 700 } else if (options != null) { |
| 701 analysisContext2 = AnalysisContextFactory.contextWithCoreAndOptions( |
| 702 options, |
| 703 resourceProvider: resourceProvider); |
| 691 } else { | 704 } else { |
| 692 analysisContext2 = AnalysisContextFactory.contextWithCore( | 705 analysisContext2 = AnalysisContextFactory.contextWithCore( |
| 693 resourceProvider: resourceProvider); | 706 resourceProvider: resourceProvider); |
| 694 } | 707 } |
| 695 } | 708 } |
| 696 } | 709 } |
| 697 | 710 |
| 698 /** | 711 /** |
| 699 * Re-create the analysis context being used by the test case and set the | |
| 700 * [options] in the newly created context to the given [options]. | |
| 701 */ | |
| 702 void resetWithOptions(AnalysisOptions options) { | |
| 703 // TODO(scheglov) remove duplication | |
| 704 if (enableNewAnalysisDriver) { | |
| 705 PerformanceLog log = new PerformanceLog(_logBuffer); | |
| 706 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(log); | |
| 707 | |
| 708 List<UriResolver> resolvers = <UriResolver>[ | |
| 709 new DartUriResolver( | |
| 710 options.strongMode ? physical_sdk.strongSdk : physical_sdk.sdk), | |
| 711 new ResourceUriResolver(resourceProvider) | |
| 712 ]; | |
| 713 SourceFactory sourceFactory = new SourceFactory(resolvers); | |
| 714 driver = new AnalysisDriver(scheduler, log, resourceProvider, | |
| 715 new MemoryByteStore(), _fileContentOverlay, sourceFactory, options); | |
| 716 scheduler.start(); | |
| 717 } else { | |
| 718 analysisContext2 = AnalysisContextFactory.contextWithCoreAndOptions( | |
| 719 options, | |
| 720 resourceProvider: resourceProvider); | |
| 721 } | |
| 722 } | |
| 723 | |
| 724 /** | |
| 725 * Given a library and all of its parts, resolve the contents of the library a
nd the contents of | 712 * Given a library and all of its parts, resolve the contents of the library a
nd the contents of |
| 726 * the parts. This assumes that the sources for the library and its parts have
already been added | 713 * the parts. This assumes that the sources for the library and its parts have
already been added |
| 727 * to the content provider using the method [addNamedSource]. | 714 * to the content provider using the method [addNamedSource]. |
| 728 * | 715 * |
| 729 * @param librarySource the source for the compilation unit that defines the l
ibrary | 716 * @param librarySource the source for the compilation unit that defines the l
ibrary |
| 730 * @return the element representing the resolved library | 717 * @return the element representing the resolved library |
| 731 * @throws AnalysisException if the analysis could not be performed | 718 * @throws AnalysisException if the analysis could not be performed |
| 732 */ | 719 */ |
| 733 LibraryElement resolve2(Source librarySource) => | 720 LibraryElement resolve2(Source librarySource) => |
| 734 analysisContext2.computeLibraryElement(librarySource); | 721 analysisContext2.computeLibraryElement(librarySource); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 return null; | 753 return null; |
| 767 } | 754 } |
| 768 | 755 |
| 769 Future<Null> resolveWithAndWithoutExperimental( | 756 Future<Null> resolveWithAndWithoutExperimental( |
| 770 List<String> strSources, | 757 List<String> strSources, |
| 771 List<ErrorCode> codesWithoutExperimental, | 758 List<ErrorCode> codesWithoutExperimental, |
| 772 List<ErrorCode> codesWithExperimental) async { | 759 List<ErrorCode> codesWithExperimental) async { |
| 773 // Setup analysis context as non-experimental | 760 // Setup analysis context as non-experimental |
| 774 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 761 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 775 // options.enableDeferredLoading = false; | 762 // options.enableDeferredLoading = false; |
| 776 resetWithOptions(options); | 763 resetWith(options: options); |
| 777 // Analysis and assertions | 764 // Analysis and assertions |
| 778 Source source = await resolveSources(strSources); | 765 Source source = await resolveSources(strSources); |
| 779 await computeAnalysisResult(source); | 766 await computeAnalysisResult(source); |
| 780 assertErrors(source, codesWithoutExperimental); | 767 assertErrors(source, codesWithoutExperimental); |
| 781 verify([source]); | 768 verify([source]); |
| 782 // Setup analysis context as experimental | 769 // Setup analysis context as experimental |
| 783 reset(); | 770 reset(); |
| 784 // Analysis and assertions | 771 // Analysis and assertions |
| 785 source = await resolveSources(strSources); | 772 source = await resolveSources(strSources); |
| 786 await computeAnalysisResult(source); | 773 await computeAnalysisResult(source); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 } | 924 } |
| 938 } | 925 } |
| 939 } | 926 } |
| 940 | 927 |
| 941 class TestAnalysisResult { | 928 class TestAnalysisResult { |
| 942 final Source source; | 929 final Source source; |
| 943 final CompilationUnit unit; | 930 final CompilationUnit unit; |
| 944 final List<AnalysisError> errors; | 931 final List<AnalysisError> errors; |
| 945 TestAnalysisResult(this.source, this.unit, this.errors); | 932 TestAnalysisResult(this.source, this.unit, this.errors); |
| 946 } | 933 } |
| OLD | NEW |