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

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1150863007: Remove many explicit references to AnalysisContextImpl and enable testing of the new task model (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 engine.resolver_test; 5 library engine.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/context/context.dart' as newContext;
9 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 11 import 'package:analyzer/src/generated/element.dart';
11 import 'package:analyzer/src/generated/element_resolver.dart'; 12 import 'package:analyzer/src/generated/element_resolver.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/error.dart'; 14 import 'package:analyzer/src/generated/error.dart';
14 import 'package:analyzer/src/generated/java_core.dart'; 15 import 'package:analyzer/src/generated/java_core.dart';
15 import 'package:analyzer/src/generated/java_engine.dart'; 16 import 'package:analyzer/src/generated/java_engine.dart';
16 import 'package:analyzer/src/generated/java_engine_io.dart'; 17 import 'package:analyzer/src/generated/java_engine_io.dart';
17 import 'package:analyzer/src/generated/java_io.dart'; 18 import 'package:analyzer/src/generated/java_io.dart';
18 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; 19 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 */ 69 */
69 class AnalysisContextFactory { 70 class AnalysisContextFactory {
70 static String _DART_MATH = "dart:math"; 71 static String _DART_MATH = "dart:math";
71 72
72 static String _DART_INTERCEPTORS = "dart:_interceptors"; 73 static String _DART_INTERCEPTORS = "dart:_interceptors";
73 74
74 static String _DART_JS_HELPER = "dart:_js_helper"; 75 static String _DART_JS_HELPER = "dart:_js_helper";
75 76
76 /** 77 /**
77 * Create an analysis context that has a fake core library already resolved. 78 * Create an analysis context that has a fake core library already resolved.
78 * 79 * Return the context that was created.
79 * @return the analysis context that was created
80 */ 80 */
81 static AnalysisContextImpl contextWithCore() { 81 static InternalAnalysisContext contextWithCore() {
82 if (AnalysisEngine.instance.useTaskModel) {
83 NewAnalysisContextForTests context = new NewAnalysisContextForTests();
84 return initContextWithCore(context);
85 }
82 AnalysisContextForTests context = new AnalysisContextForTests(); 86 AnalysisContextForTests context = new AnalysisContextForTests();
83 return initContextWithCore(context); 87 return initContextWithCore(context);
84 } 88 }
85 89
86 /** 90 /**
87 * Create an analysis context that uses the given options and has a fake core library already 91 * Create an analysis context that uses the given [options] and has a fake
88 * resolved. 92 * core library already resolved. Return the context that was created.
89 *
90 * @param options the options to be applied to the context
91 * @return the analysis context that was created
92 */ 93 */
93 static AnalysisContextImpl contextWithCoreAndOptions( 94 static InternalAnalysisContext contextWithCoreAndOptions(
94 AnalysisOptions options) { 95 AnalysisOptions options) {
96 if (AnalysisEngine.instance.useTaskModel) {
97 NewAnalysisContextForTests context = new NewAnalysisContextForTests();
98 context._internalSetAnalysisOptions(options);
99 return initContextWithCore(context);
100 }
95 AnalysisContextForTests context = new AnalysisContextForTests(); 101 AnalysisContextForTests context = new AnalysisContextForTests();
96 context._internalSetAnalysisOptions(options); 102 context._internalSetAnalysisOptions(options);
97 return initContextWithCore(context); 103 return initContextWithCore(context);
98 } 104 }
99 105
100 /** 106 /**
101 * Initialize the given analysis context with a fake core library already reso lved. 107 * Initialize the given analysis context with a fake core library already reso lved.
102 * 108 *
103 * @param context the context to be initialized (not `null`) 109 * @param context the context to be initialized (not `null`)
104 * @return the analysis context that was created 110 * @return the analysis context that was created
105 */ 111 */
106 static AnalysisContextImpl initContextWithCore(AnalysisContextImpl context) { 112 static InternalAnalysisContext initContextWithCore(
113 InternalAnalysisContext context) {
107 DirectoryBasedDartSdk sdk = new _AnalysisContextFactory_initContextWithCore( 114 DirectoryBasedDartSdk sdk = new _AnalysisContextFactory_initContextWithCore(
108 new JavaFile("/fake/sdk")); 115 new JavaFile("/fake/sdk"));
109 SourceFactory sourceFactory = 116 SourceFactory sourceFactory =
110 new SourceFactory([new DartUriResolver(sdk), new FileUriResolver()]); 117 new SourceFactory([new DartUriResolver(sdk), new FileUriResolver()]);
111 context.sourceFactory = sourceFactory; 118 context.sourceFactory = sourceFactory;
112 AnalysisContext coreContext = sdk.context; 119 AnalysisContext coreContext = sdk.context;
113 // 120 //
114 // dart:core 121 // dart:core
115 // 122 //
116 TestTypeProvider provider = new TestTypeProvider(); 123 TestTypeProvider provider = new TestTypeProvider();
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // 346 //
340 HashMap<Source, LibraryElement> elementMap = 347 HashMap<Source, LibraryElement> elementMap =
341 new HashMap<Source, LibraryElement>(); 348 new HashMap<Source, LibraryElement>();
342 elementMap[coreSource] = coreLibrary; 349 elementMap[coreSource] = coreLibrary;
343 elementMap[asyncSource] = asyncLibrary; 350 elementMap[asyncSource] = asyncLibrary;
344 elementMap[htmlSource] = htmlLibrary; 351 elementMap[htmlSource] = htmlLibrary;
345 elementMap[mathSource] = mathLibrary; 352 elementMap[mathSource] = mathLibrary;
346 context.recordLibraryElements(elementMap); 353 context.recordLibraryElements(elementMap);
347 return context; 354 return context;
348 } 355 }
356
357 /**
358 * Create an analysis context that has a fake core library already resolved.
359 * Return the context that was created.
360 */
361 static AnalysisContextImpl oldContextWithCore() {
362 AnalysisContextForTests context = new AnalysisContextForTests();
363 return initContextWithCore(context);
364 }
365
366 /**
367 * Create an analysis context that uses the given [options] and has a fake
368 * core library already resolved. Return the context that was created.
369 */
370 static AnalysisContextImpl oldContextWithCoreAndOptions(
371 AnalysisOptions options) {
372 AnalysisContextForTests context = new AnalysisContextForTests();
373 context._internalSetAnalysisOptions(options);
374 return initContextWithCore(context);
375 }
349 } 376 }
350 377
351 /** 378 /**
352 * Instances of the class `AnalysisContextForTests` implement an analysis contex t that has a 379 * Instances of the class `AnalysisContextForTests` implement an analysis contex t that has a
353 * fake SDK that is much smaller and faster for testing purposes. 380 * fake SDK that is much smaller and faster for testing purposes.
354 */ 381 */
355 class AnalysisContextForTests extends AnalysisContextImpl { 382 class AnalysisContextForTests extends AnalysisContextImpl {
356 @override 383 @override
357 void set analysisOptions(AnalysisOptions options) { 384 void set analysisOptions(AnalysisOptions options) {
358 AnalysisOptions currentOptions = analysisOptions; 385 AnalysisOptions currentOptions = analysisOptions;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } 432 }
406 } 433 }
407 434
408 /** 435 /**
409 * Helper for creating and managing single [AnalysisContext]. 436 * Helper for creating and managing single [AnalysisContext].
410 */ 437 */
411 class AnalysisContextHelper { 438 class AnalysisContextHelper {
412 AnalysisContext context; 439 AnalysisContext context;
413 440
414 /** 441 /**
415 * Creates new [AnalysisContext] using [AnalysisContextFactory.contextWithCore ]. 442 * Creates new [AnalysisContext] using [AnalysisContextFactory].
416 */ 443 */
417 AnalysisContextHelper([AnalysisOptionsImpl options]) { 444 AnalysisContextHelper([AnalysisOptionsImpl options]) {
418 if (options == null) { 445 if (options == null) {
419 options = new AnalysisOptionsImpl(); 446 options = new AnalysisOptionsImpl();
420 } 447 }
421 options.cacheSize = 256; 448 options.cacheSize = 256;
422 context = AnalysisContextFactory.contextWithCoreAndOptions(options); 449 context = AnalysisContextFactory.contextWithCoreAndOptions(options);
423 } 450 }
424 451
425 Source addSource(String path, String code) { 452 Source addSource(String path, String code) {
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 0] as NamedExpression).name.label.staticElement, same(parameter)); 1908 0] as NamedExpression).name.label.staticElement, same(parameter));
1882 _listener.assertNoErrors(); 1909 _listener.assertNoErrors();
1883 } 1910 }
1884 1911
1885 /** 1912 /**
1886 * Create the resolver used by the tests. 1913 * Create the resolver used by the tests.
1887 * 1914 *
1888 * @return the resolver that was created 1915 * @return the resolver that was created
1889 */ 1916 */
1890 ElementResolver _createResolver() { 1917 ElementResolver _createResolver() {
1891 AnalysisContextImpl context = new AnalysisContextImpl(); 1918 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore();
1892 SourceFactory sourceFactory = new SourceFactory(
1893 [new DartUriResolver(DirectoryBasedDartSdk.defaultSdk)]);
1894 context.sourceFactory = sourceFactory;
1895 FileBasedSource source = 1919 FileBasedSource source =
1896 new FileBasedSource(FileUtilities2.createFile("/test.dart")); 1920 new FileBasedSource(FileUtilities2.createFile("/test.dart"));
1897 CompilationUnitElementImpl definingCompilationUnit = 1921 CompilationUnitElementImpl definingCompilationUnit =
1898 new CompilationUnitElementImpl("test.dart"); 1922 new CompilationUnitElementImpl("test.dart");
1899 definingCompilationUnit.librarySource = 1923 definingCompilationUnit.librarySource =
1900 definingCompilationUnit.source = source; 1924 definingCompilationUnit.source = source;
1901 _definingLibrary = ElementFactory.library(context, "test"); 1925 _definingLibrary = ElementFactory.library(context, "test");
1902 _definingLibrary.definingCompilationUnit = definingCompilationUnit; 1926 _definingLibrary.definingCompilationUnit = definingCompilationUnit;
1903 Library library = new Library(context, _listener, source); 1927 Library library = new Library(context, _listener, source);
1904 library.libraryElement = _definingLibrary; 1928 library.libraryElement = _definingLibrary;
(...skipping 3797 matching lines...) Expand 10 before | Expand all | Expand 10 after
5702 void _assertNoErrors(ClassElement classElt) { 5726 void _assertNoErrors(ClassElement classElt) {
5703 _assertErrors(classElt); 5727 _assertErrors(classElt);
5704 } 5728 }
5705 5729
5706 /** 5730 /**
5707 * Create the inheritance manager used by the tests. 5731 * Create the inheritance manager used by the tests.
5708 * 5732 *
5709 * @return the inheritance manager that was created 5733 * @return the inheritance manager that was created
5710 */ 5734 */
5711 InheritanceManager _createInheritanceManager() { 5735 InheritanceManager _createInheritanceManager() {
5712 AnalysisContextImpl context = AnalysisContextFactory.contextWithCore(); 5736 AnalysisContext context = AnalysisContextFactory.contextWithCore();
5713 FileBasedSource source = 5737 FileBasedSource source =
5714 new FileBasedSource(FileUtilities2.createFile("/test.dart")); 5738 new FileBasedSource(FileUtilities2.createFile("/test.dart"));
5715 CompilationUnitElementImpl definingCompilationUnit = 5739 CompilationUnitElementImpl definingCompilationUnit =
5716 new CompilationUnitElementImpl("test.dart"); 5740 new CompilationUnitElementImpl("test.dart");
5717 definingCompilationUnit.librarySource = 5741 definingCompilationUnit.librarySource =
5718 definingCompilationUnit.source = source; 5742 definingCompilationUnit.source = source;
5719 _definingLibrary = ElementFactory.library(context, "test"); 5743 _definingLibrary = ElementFactory.library(context, "test");
5720 _definingLibrary.definingCompilationUnit = definingCompilationUnit; 5744 _definingLibrary.definingCompilationUnit = definingCompilationUnit;
5721 return new InheritanceManager(_definingLibrary); 5745 return new InheritanceManager(_definingLibrary);
5722 } 5746 }
5723 } 5747 }
5724 5748
5725 @reflectiveTest 5749 @reflectiveTest
5726 class LibraryElementBuilderTest extends EngineTestCase { 5750 class LibraryElementBuilderTest extends EngineTestCase {
5727 /** 5751 /**
5728 * The analysis context used to analyze sources. 5752 * The analysis context used to analyze sources.
5729 */ 5753 */
5730 AnalysisContextImpl _context; 5754 InternalAnalysisContext _context;
5731 5755
5732 /** 5756 /**
5733 * Add a source file to the content provider. The file path should be absolute . 5757 * Add a source file to the content provider. The file path should be absolute .
5734 * 5758 *
5735 * @param filePath the path of the file being added 5759 * @param filePath the path of the file being added
5736 * @param contents the contents to be returned by the content provider for the specified file 5760 * @param contents the contents to be returned by the content provider for the specified file
5737 * @return the source object representing the added file 5761 * @return the source object representing the added file
5738 */ 5762 */
5739 Source addSource(String filePath, String contents) { 5763 Source addSource(String filePath, String contents) {
5740 Source source = new FileBasedSource(FileUtilities2.createFile(filePath)); 5764 Source source = new FileBasedSource(FileUtilities2.createFile(filePath));
5741 _context.setContents(source, contents); 5765 _context.setContents(source, contents);
5742 return source; 5766 return source;
5743 } 5767 }
5744 5768
5745 @override 5769 @override
5746 void setUp() { 5770 void setUp() {
5747 SourceFactory sourceFactory = new SourceFactory([ 5771 _context = AnalysisContextFactory.contextWithCore();
5748 new DartUriResolver(DirectoryBasedDartSdk.defaultSdk),
5749 new FileUriResolver()
5750 ]);
5751 _context = new AnalysisContextImpl();
5752 _context.sourceFactory = sourceFactory;
5753 } 5772 }
5754 5773
5755 @override 5774 @override
5756 void tearDown() { 5775 void tearDown() {
5757 _context = null; 5776 _context = null;
5758 super.tearDown(); 5777 super.tearDown();
5759 } 5778 }
5760 5779
5761 void test_accessorsAcrossFiles() { 5780 void test_accessorsAcrossFiles() {
5762 Source librarySource = addSource("/lib.dart", r''' 5781 Source librarySource = addSource("/lib.dart", r'''
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
5902 GatheringErrorListener listener = new GatheringErrorListener(); 5921 GatheringErrorListener listener = new GatheringErrorListener();
5903 listener.addAll2(resolver.errorListener); 5922 listener.addAll2(resolver.errorListener);
5904 listener.assertErrorsWithCodes(expectedErrorCodes); 5923 listener.assertErrorsWithCodes(expectedErrorCodes);
5905 return element; 5924 return element;
5906 } 5925 }
5907 } 5926 }
5908 5927
5909 @reflectiveTest 5928 @reflectiveTest
5910 class LibraryImportScopeTest extends ResolverTestCase { 5929 class LibraryImportScopeTest extends ResolverTestCase {
5911 void test_conflictingImports() { 5930 void test_conflictingImports() {
5912 AnalysisContext context = new AnalysisContextImpl(); 5931 AnalysisContext context = AnalysisContextFactory.contextWithCore();
5913 context.sourceFactory = new SourceFactory([]);
5914 String typeNameA = "A"; 5932 String typeNameA = "A";
5915 String typeNameB = "B"; 5933 String typeNameB = "B";
5916 String typeNameC = "C"; 5934 String typeNameC = "C";
5917 ClassElement typeA = ElementFactory.classElement2(typeNameA); 5935 ClassElement typeA = ElementFactory.classElement2(typeNameA);
5918 ClassElement typeB1 = ElementFactory.classElement2(typeNameB); 5936 ClassElement typeB1 = ElementFactory.classElement2(typeNameB);
5919 ClassElement typeB2 = ElementFactory.classElement2(typeNameB); 5937 ClassElement typeB2 = ElementFactory.classElement2(typeNameB);
5920 ClassElement typeC = ElementFactory.classElement2(typeNameC); 5938 ClassElement typeC = ElementFactory.classElement2(typeNameC);
5921 LibraryElement importedLibrary1 = createTestLibrary(context, "imported1"); 5939 LibraryElement importedLibrary1 = createTestLibrary(context, "imported1");
5922 (importedLibrary1.definingCompilationUnit as CompilationUnitElementImpl).typ es = 5940 (importedLibrary1.definingCompilationUnit as CompilationUnitElementImpl).typ es =
5923 <ClassElement>[typeA, typeB1]; 5941 <ClassElement>[typeA, typeB1];
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
5969 } 5987 }
5970 } 5988 }
5971 5989
5972 void test_creation_empty() { 5990 void test_creation_empty() {
5973 LibraryElement definingLibrary = createDefaultTestLibrary(); 5991 LibraryElement definingLibrary = createDefaultTestLibrary();
5974 GatheringErrorListener errorListener = new GatheringErrorListener(); 5992 GatheringErrorListener errorListener = new GatheringErrorListener();
5975 new LibraryImportScope(definingLibrary, errorListener); 5993 new LibraryImportScope(definingLibrary, errorListener);
5976 } 5994 }
5977 5995
5978 void test_creation_nonEmpty() { 5996 void test_creation_nonEmpty() {
5979 AnalysisContext context = new AnalysisContextImpl(); 5997 AnalysisContext context = AnalysisContextFactory.contextWithCore();
5980 context.sourceFactory = new SourceFactory([]);
5981 String importedTypeName = "A"; 5998 String importedTypeName = "A";
5982 ClassElement importedType = 5999 ClassElement importedType =
5983 new ClassElementImpl.forNode(AstFactory.identifier3(importedTypeName)); 6000 new ClassElementImpl.forNode(AstFactory.identifier3(importedTypeName));
5984 LibraryElement importedLibrary = createTestLibrary(context, "imported"); 6001 LibraryElement importedLibrary = createTestLibrary(context, "imported");
5985 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = 6002 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s =
5986 <ClassElement>[importedType]; 6003 <ClassElement>[importedType];
5987 LibraryElementImpl definingLibrary = 6004 LibraryElementImpl definingLibrary =
5988 createTestLibrary(context, "importing"); 6005 createTestLibrary(context, "importing");
5989 ImportElementImpl importElement = new ImportElementImpl(0); 6006 ImportElementImpl importElement = new ImportElementImpl(0);
5990 importElement.importedLibrary = importedLibrary; 6007 importElement.importedLibrary = importedLibrary;
(...skipping 30 matching lines...) Expand all
6021 importingLibrary.imports = <ImportElement>[importCore, importLib]; 6038 importingLibrary.imports = <ImportElement>[importCore, importLib];
6022 GatheringErrorListener errorListener = new GatheringErrorListener(); 6039 GatheringErrorListener errorListener = new GatheringErrorListener();
6023 Scope scope = new LibraryImportScope(importingLibrary, errorListener); 6040 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
6024 expect( 6041 expect(
6025 scope.lookup(AstFactory.identifier3(typeName), importingLibrary), type); 6042 scope.lookup(AstFactory.identifier3(typeName), importingLibrary), type);
6026 errorListener 6043 errorListener
6027 .assertErrorsWithCodes([StaticWarningCode.CONFLICTING_DART_IMPORT]); 6044 .assertErrorsWithCodes([StaticWarningCode.CONFLICTING_DART_IMPORT]);
6028 } 6045 }
6029 6046
6030 void test_nonConflictingImports_sameElement() { 6047 void test_nonConflictingImports_sameElement() {
6031 AnalysisContext context = new AnalysisContextImpl(); 6048 AnalysisContext context = AnalysisContextFactory.contextWithCore();
6032 context.sourceFactory = new SourceFactory([]);
6033 String typeNameA = "A"; 6049 String typeNameA = "A";
6034 String typeNameB = "B"; 6050 String typeNameB = "B";
6035 ClassElement typeA = ElementFactory.classElement2(typeNameA); 6051 ClassElement typeA = ElementFactory.classElement2(typeNameA);
6036 ClassElement typeB = ElementFactory.classElement2(typeNameB); 6052 ClassElement typeB = ElementFactory.classElement2(typeNameB);
6037 LibraryElement importedLibrary = createTestLibrary(context, "imported"); 6053 LibraryElement importedLibrary = createTestLibrary(context, "imported");
6038 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = 6054 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s =
6039 <ClassElement>[typeA, typeB]; 6055 <ClassElement>[typeA, typeB];
6040 ImportElementImpl import1 = ElementFactory.importFor(importedLibrary, null); 6056 ImportElementImpl import1 = ElementFactory.importFor(importedLibrary, null);
6041 ImportElementImpl import2 = ElementFactory.importFor(importedLibrary, null); 6057 ImportElementImpl import2 = ElementFactory.importFor(importedLibrary, null);
6042 LibraryElementImpl importingLibrary = 6058 LibraryElementImpl importingLibrary =
6043 createTestLibrary(context, "importing"); 6059 createTestLibrary(context, "importing");
6044 importingLibrary.imports = <ImportElement>[import1, import2]; 6060 importingLibrary.imports = <ImportElement>[import1, import2];
6045 GatheringErrorListener errorListener = new GatheringErrorListener(); 6061 GatheringErrorListener errorListener = new GatheringErrorListener();
6046 Scope scope = new LibraryImportScope(importingLibrary, errorListener); 6062 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
6047 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary), 6063 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary),
6048 typeA); 6064 typeA);
6049 errorListener.assertNoErrors(); 6065 errorListener.assertNoErrors();
6050 expect(scope.lookup(AstFactory.identifier3(typeNameB), importingLibrary), 6066 expect(scope.lookup(AstFactory.identifier3(typeNameB), importingLibrary),
6051 typeB); 6067 typeB);
6052 errorListener.assertNoErrors(); 6068 errorListener.assertNoErrors();
6053 } 6069 }
6054 6070
6055 void test_prefixedAndNonPrefixed() { 6071 void test_prefixedAndNonPrefixed() {
6056 AnalysisContext context = new AnalysisContextImpl(); 6072 AnalysisContext context = AnalysisContextFactory.contextWithCore();
6057 context.sourceFactory = new SourceFactory([]);
6058 String typeName = "C"; 6073 String typeName = "C";
6059 String prefixName = "p"; 6074 String prefixName = "p";
6060 ClassElement prefixedType = ElementFactory.classElement2(typeName); 6075 ClassElement prefixedType = ElementFactory.classElement2(typeName);
6061 ClassElement nonPrefixedType = ElementFactory.classElement2(typeName); 6076 ClassElement nonPrefixedType = ElementFactory.classElement2(typeName);
6062 LibraryElement prefixedLibrary = 6077 LibraryElement prefixedLibrary =
6063 createTestLibrary(context, "import.prefixed"); 6078 createTestLibrary(context, "import.prefixed");
6064 (prefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = 6079 (prefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s =
6065 <ClassElement>[prefixedType]; 6080 <ClassElement>[prefixedType];
6066 ImportElementImpl prefixedImport = ElementFactory.importFor( 6081 ImportElementImpl prefixedImport = ElementFactory.importFor(
6067 prefixedLibrary, ElementFactory.prefix(prefixName)); 6082 prefixedLibrary, ElementFactory.prefix(prefixName));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
6188 6203
6189 @reflectiveTest 6204 @reflectiveTest
6190 class LibraryScopeTest extends ResolverTestCase { 6205 class LibraryScopeTest extends ResolverTestCase {
6191 void test_creation_empty() { 6206 void test_creation_empty() {
6192 LibraryElement definingLibrary = createDefaultTestLibrary(); 6207 LibraryElement definingLibrary = createDefaultTestLibrary();
6193 GatheringErrorListener errorListener = new GatheringErrorListener(); 6208 GatheringErrorListener errorListener = new GatheringErrorListener();
6194 new LibraryScope(definingLibrary, errorListener); 6209 new LibraryScope(definingLibrary, errorListener);
6195 } 6210 }
6196 6211
6197 void test_creation_nonEmpty() { 6212 void test_creation_nonEmpty() {
6198 AnalysisContext context = new AnalysisContextImpl(); 6213 AnalysisContext context = AnalysisContextFactory.contextWithCore();
6199 context.sourceFactory = new SourceFactory([]);
6200 String importedTypeName = "A"; 6214 String importedTypeName = "A";
6201 ClassElement importedType = 6215 ClassElement importedType =
6202 new ClassElementImpl.forNode(AstFactory.identifier3(importedTypeName)); 6216 new ClassElementImpl.forNode(AstFactory.identifier3(importedTypeName));
6203 LibraryElement importedLibrary = createTestLibrary(context, "imported"); 6217 LibraryElement importedLibrary = createTestLibrary(context, "imported");
6204 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s = 6218 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type s =
6205 <ClassElement>[importedType]; 6219 <ClassElement>[importedType];
6206 LibraryElementImpl definingLibrary = 6220 LibraryElementImpl definingLibrary =
6207 createTestLibrary(context, "importing"); 6221 createTestLibrary(context, "importing");
6208 ImportElementImpl importElement = new ImportElementImpl(0); 6222 ImportElementImpl importElement = new ImportElementImpl(0);
6209 importElement.importedLibrary = importedLibrary; 6223 importElement.importedLibrary = importedLibrary;
(...skipping 14 matching lines...) Expand all
6224 } 6238 }
6225 6239
6226 @reflectiveTest 6240 @reflectiveTest
6227 class LibraryTest extends EngineTestCase { 6241 class LibraryTest extends EngineTestCase {
6228 /** 6242 /**
6229 * The error listener to which all errors will be reported. 6243 * The error listener to which all errors will be reported.
6230 */ 6244 */
6231 GatheringErrorListener _errorListener; 6245 GatheringErrorListener _errorListener;
6232 6246
6233 /** 6247 /**
6234 * The source factory used to create libraries.
6235 */
6236 SourceFactory _sourceFactory;
6237
6238 /**
6239 * The analysis context to pass in to all libraries created by the tests. 6248 * The analysis context to pass in to all libraries created by the tests.
6240 */ 6249 */
6241 AnalysisContextImpl _analysisContext; 6250 InternalAnalysisContext _analysisContext;
6242 6251
6243 /** 6252 /**
6244 * The library used by the tests. 6253 * The library used by the tests.
6245 */ 6254 */
6246 Library _library; 6255 Library _library;
6247 6256
6248 @override 6257 @override
6249 void setUp() { 6258 void setUp() {
6250 _sourceFactory = new SourceFactory([new FileUriResolver()]); 6259 _analysisContext = AnalysisContextFactory.contextWithCore();
6251 _analysisContext = new AnalysisContextImpl();
6252 _analysisContext.sourceFactory = _sourceFactory;
6253 _errorListener = new GatheringErrorListener(); 6260 _errorListener = new GatheringErrorListener();
6254 _library = _createLibrary("/lib.dart"); 6261 _library = _createLibrary("/lib.dart");
6255 } 6262 }
6256 6263
6257 @override 6264 @override
6258 void tearDown() { 6265 void tearDown() {
6259 _errorListener = null; 6266 _errorListener = null;
6260 _sourceFactory = null;
6261 _analysisContext = null; 6267 _analysisContext = null;
6262 _library = null; 6268 _library = null;
6263 super.tearDown(); 6269 super.tearDown();
6264 } 6270 }
6265 6271
6266 void test_getExplicitlyImportsCore() { 6272 void test_getExplicitlyImportsCore() {
6267 expect(_library.explicitlyImportsCore, isFalse); 6273 expect(_library.explicitlyImportsCore, isFalse);
6268 _errorListener.assertNoErrors(); 6274 _errorListener.assertNoErrors();
6269 } 6275 }
6270 6276
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
6374 void test_MemberMap_put() { 6380 void test_MemberMap_put() {
6375 MethodElement m1 = ElementFactory.methodElement("m1", _nullType); 6381 MethodElement m1 = ElementFactory.methodElement("m1", _nullType);
6376 MemberMap map = new MemberMap(); 6382 MemberMap map = new MemberMap();
6377 expect(map.size, 0); 6383 expect(map.size, 0);
6378 map.put(m1.name, m1); 6384 map.put(m1.name, m1);
6379 expect(map.size, 1); 6385 expect(map.size, 1);
6380 expect(map.get("m1"), m1); 6386 expect(map.get("m1"), m1);
6381 } 6387 }
6382 } 6388 }
6383 6389
6390 /**
6391 * An analysis context that has a fake SDK that is much smaller and faster for
6392 * testing purposes.
6393 */
6394 class NewAnalysisContextForTests extends newContext.AnalysisContextImpl {
6395 @override
6396 void set analysisOptions(AnalysisOptions options) {
6397 AnalysisOptions currentOptions = analysisOptions;
6398 bool needsRecompute = currentOptions.analyzeFunctionBodiesPredicate !=
6399 options.analyzeFunctionBodiesPredicate ||
6400 currentOptions.generateImplicitErrors !=
6401 options.generateImplicitErrors ||
6402 currentOptions.generateSdkErrors != options.generateSdkErrors ||
6403 currentOptions.dart2jsHint != options.dart2jsHint ||
6404 (currentOptions.hint && !options.hint) ||
6405 currentOptions.preserveComments != options.preserveComments ||
6406 currentOptions.enableNullAwareOperators !=
6407 options.enableNullAwareOperators ||
6408 currentOptions.enableStrictCallChecks != options.enableStrictCallChecks;
6409 if (needsRecompute) {
6410 fail(
6411 "Cannot set options that cause the sources to be reanalyzed in a test context");
6412 }
6413 super.analysisOptions = options;
6414 }
6415
6416 @override
6417 bool exists(Source source) =>
6418 super.exists(source) || sourceFactory.dartSdk.context.exists(source);
6419
6420 @override
6421 TimestampedData<String> getContents(Source source) {
6422 if (source.isInSystemLibrary) {
6423 return sourceFactory.dartSdk.context.getContents(source);
6424 }
6425 return super.getContents(source);
6426 }
6427
6428 @override
6429 int getModificationStamp(Source source) {
6430 if (source.isInSystemLibrary) {
6431 return sourceFactory.dartSdk.context.getModificationStamp(source);
6432 }
6433 return super.getModificationStamp(source);
6434 }
6435
6436 /**
6437 * Set the analysis options, even if they would force re-analysis. This method should only be
6438 * invoked before the fake SDK is initialized.
6439 *
6440 * @param options the analysis options to be set
6441 */
6442 void _internalSetAnalysisOptions(AnalysisOptions options) {
6443 super.analysisOptions = options;
6444 }
6445 }
6446
6384 @reflectiveTest 6447 @reflectiveTest
6385 class NonHintCodeTest extends ResolverTestCase { 6448 class NonHintCodeTest extends ResolverTestCase {
6386 void test_deadCode_deadBlock_conditionalElse_debugConst() { 6449 void test_deadCode_deadBlock_conditionalElse_debugConst() {
6387 Source source = addSource(r''' 6450 Source source = addSource(r'''
6388 const bool DEBUG = true; 6451 const bool DEBUG = true;
6389 f() { 6452 f() {
6390 DEBUG ? 1 : 2; 6453 DEBUG ? 1 : 2;
6391 }'''); 6454 }''');
6392 resolve(source); 6455 resolve(source);
6393 assertNoErrors(source); 6456 assertNoErrors(source);
(...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after
7654 buffer.write(identifier.offset); 7717 buffer.write(identifier.offset);
7655 buffer.writeln(")"); 7718 buffer.writeln(")");
7656 } 7719 }
7657 } 7720 }
7658 } 7721 }
7659 7722
7660 class ResolverTestCase extends EngineTestCase { 7723 class ResolverTestCase extends EngineTestCase {
7661 /** 7724 /**
7662 * The analysis context used to parse the compilation units being resolved. 7725 * The analysis context used to parse the compilation units being resolved.
7663 */ 7726 */
7664 AnalysisContextImpl analysisContext2; 7727 InternalAnalysisContext analysisContext2;
7665 7728
7666 /** 7729 /**
7667 * Specifies if [assertErrors] should check for [HintCode.UNUSED_ELEMENT] and 7730 * Specifies if [assertErrors] should check for [HintCode.UNUSED_ELEMENT] and
7668 * [HintCode.UNUSED_FIELD]. 7731 * [HintCode.UNUSED_FIELD].
7669 */ 7732 */
7670 bool enableUnusedElement = false; 7733 bool enableUnusedElement = false;
7671 7734
7672 /** 7735 /**
7673 * Specifies if [assertErrors] should check for [HintCode.UNUSED_LOCAL_VARIABL E]. 7736 * Specifies if [assertErrors] should check for [HintCode.UNUSED_LOCAL_VARIABL E].
7674 */ 7737 */
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
7764 return source; 7827 return source;
7765 } 7828 }
7766 7829
7767 /** 7830 /**
7768 * Create a library element that represents a library named `"test"` containin g a single 7831 * Create a library element that represents a library named `"test"` containin g a single
7769 * empty compilation unit. 7832 * empty compilation unit.
7770 * 7833 *
7771 * @return the library element that was created 7834 * @return the library element that was created
7772 */ 7835 */
7773 LibraryElementImpl createDefaultTestLibrary() => 7836 LibraryElementImpl createDefaultTestLibrary() =>
7774 createTestLibrary(new AnalysisContextImpl(), "test"); 7837 createTestLibrary(AnalysisContextFactory.contextWithCore(), "test");
7775 7838
7776 /** 7839 /**
7777 * Create a library element that represents a library with the given name cont aining a single 7840 * Create a library element that represents a library with the given name cont aining a single
7778 * empty compilation unit. 7841 * empty compilation unit.
7779 * 7842 *
7780 * @param libraryName the name of the library to be created 7843 * @param libraryName the name of the library to be created
7781 * @return the library element that was created 7844 * @return the library element that was created
7782 */ 7845 */
7783 LibraryElementImpl createTestLibrary( 7846 LibraryElementImpl createTestLibrary(
7784 AnalysisContext context, String libraryName, [List<String> typeNames]) { 7847 AnalysisContext context, String libraryName, [List<String> typeNames]) {
(...skipping 3202 matching lines...) Expand 10 before | Expand all | Expand 10 after
10987 // TODO(brianwilkerson) Compare other kinds of types then make this a shared 11050 // TODO(brianwilkerson) Compare other kinds of types then make this a shared
10988 // utility method. 11051 // utility method.
10989 } 11052 }
10990 11053
10991 /** 11054 /**
10992 * Create the analyzer used by the tests. 11055 * Create the analyzer used by the tests.
10993 * 11056 *
10994 * @return the analyzer to be used by the tests 11057 * @return the analyzer to be used by the tests
10995 */ 11058 */
10996 StaticTypeAnalyzer _createAnalyzer() { 11059 StaticTypeAnalyzer _createAnalyzer() {
10997 AnalysisContextImpl context = new AnalysisContextImpl(); 11060 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore();
10998 SourceFactory sourceFactory = new SourceFactory(
10999 [new DartUriResolver(DirectoryBasedDartSdk.defaultSdk)]);
11000 context.sourceFactory = sourceFactory;
11001 FileBasedSource source = 11061 FileBasedSource source =
11002 new FileBasedSource(FileUtilities2.createFile("/lib.dart")); 11062 new FileBasedSource(FileUtilities2.createFile("/lib.dart"));
11003 CompilationUnitElementImpl definingCompilationUnit = 11063 CompilationUnitElementImpl definingCompilationUnit =
11004 new CompilationUnitElementImpl("lib.dart"); 11064 new CompilationUnitElementImpl("lib.dart");
11005 definingCompilationUnit.librarySource = 11065 definingCompilationUnit.librarySource =
11006 definingCompilationUnit.source = source; 11066 definingCompilationUnit.source = source;
11007 LibraryElementImpl definingLibrary = 11067 LibraryElementImpl definingLibrary =
11008 new LibraryElementImpl.forNode(context, null); 11068 new LibraryElementImpl.forNode(context, null);
11009 definingLibrary.definingCompilationUnit = definingCompilationUnit; 11069 definingLibrary.definingCompilationUnit = definingCompilationUnit;
11010 Library library = new Library(context, _listener, source); 11070 Library library = new Library(context, _listener, source);
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
11495 SubtypeManager _subtypeManager; 11555 SubtypeManager _subtypeManager;
11496 11556
11497 /** 11557 /**
11498 * The compilation unit element containing all of the types setup in each test . 11558 * The compilation unit element containing all of the types setup in each test .
11499 */ 11559 */
11500 CompilationUnitElementImpl _definingCompilationUnit; 11560 CompilationUnitElementImpl _definingCompilationUnit;
11501 11561
11502 @override 11562 @override
11503 void setUp() { 11563 void setUp() {
11504 super.setUp(); 11564 super.setUp();
11505 AnalysisContextImpl context = AnalysisContextFactory.contextWithCore(); 11565 AnalysisContext context = AnalysisContextFactory.contextWithCore();
11506 FileBasedSource source = 11566 FileBasedSource source =
11507 new FileBasedSource(FileUtilities2.createFile("/test.dart")); 11567 new FileBasedSource(FileUtilities2.createFile("/test.dart"));
11508 _definingCompilationUnit = new CompilationUnitElementImpl("test.dart"); 11568 _definingCompilationUnit = new CompilationUnitElementImpl("test.dart");
11509 _definingCompilationUnit.librarySource = 11569 _definingCompilationUnit.librarySource =
11510 _definingCompilationUnit.source = source; 11570 _definingCompilationUnit.source = source;
11511 LibraryElementImpl definingLibrary = 11571 LibraryElementImpl definingLibrary =
11512 ElementFactory.library(context, "test"); 11572 ElementFactory.library(context, "test");
11513 definingLibrary.definingCompilationUnit = _definingCompilationUnit; 11573 definingLibrary.definingCompilationUnit = _definingCompilationUnit;
11514 _subtypeManager = new SubtypeManager(); 11574 _subtypeManager = new SubtypeManager();
11515 } 11575 }
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after
13203 mapType.element, 13263 mapType.element,
13204 objectType.element, 13264 objectType.element,
13205 stackTraceType.element, 13265 stackTraceType.element,
13206 stringType.element, 13266 stringType.element,
13207 symbolType.element, 13267 symbolType.element,
13208 typeType.element 13268 typeType.element
13209 ]; 13269 ];
13210 CompilationUnitElementImpl asyncUnit = 13270 CompilationUnitElementImpl asyncUnit =
13211 new CompilationUnitElementImpl("async.dart"); 13271 new CompilationUnitElementImpl("async.dart");
13212 asyncUnit.types = <ClassElement>[futureType.element, streamType.element]; 13272 asyncUnit.types = <ClassElement>[futureType.element, streamType.element];
13213 AnalysisContextImpl context = new AnalysisContextImpl(); 13273 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
13214 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( 13274 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode(
13215 context, AstFactory.libraryIdentifier2(["dart.core"])); 13275 context, AstFactory.libraryIdentifier2(["dart.core"]));
13216 coreLibrary.definingCompilationUnit = coreUnit; 13276 coreLibrary.definingCompilationUnit = coreUnit;
13217 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( 13277 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode(
13218 context, AstFactory.libraryIdentifier2(["dart.async"])); 13278 context, AstFactory.libraryIdentifier2(["dart.async"]));
13219 asyncLibrary.definingCompilationUnit = asyncUnit; 13279 asyncLibrary.definingCompilationUnit = asyncUnit;
13220 // 13280 //
13221 // Create a type provider and ensure that it can return the expected types. 13281 // Create a type provider and ensure that it can return the expected types.
13222 // 13282 //
13223 TypeProviderImpl provider = new TypeProviderImpl(coreLibrary, asyncLibrary); 13283 TypeProviderImpl provider = new TypeProviderImpl(coreLibrary, asyncLibrary);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
13326 VariableDeclaration node = AstFactory.variableDeclaration("a"); 13386 VariableDeclaration node = AstFactory.variableDeclaration("a");
13327 AstFactory.variableDeclarationList(null, AstFactory.typeName(type), [node]); 13387 AstFactory.variableDeclarationList(null, AstFactory.typeName(type), [node]);
13328 //resolve(node); 13388 //resolve(node);
13329 expect(node.name.staticType, same(type.type)); 13389 expect(node.name.staticType, same(type.type));
13330 _listener.assertNoErrors(); 13390 _listener.assertNoErrors();
13331 } 13391 }
13332 13392
13333 @override 13393 @override
13334 void setUp() { 13394 void setUp() {
13335 _listener = new GatheringErrorListener(); 13395 _listener = new GatheringErrorListener();
13336 SourceFactory factory = new SourceFactory([new FileUriResolver()]); 13396 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore();
13337 AnalysisContextImpl context = new AnalysisContextImpl();
13338 context.sourceFactory = factory;
13339 Source librarySource = 13397 Source librarySource =
13340 new FileBasedSource(FileUtilities2.createFile("/lib.dart")); 13398 new FileBasedSource(FileUtilities2.createFile("/lib.dart"));
13341 _library = new Library(context, _listener, librarySource); 13399 _library = new Library(context, _listener, librarySource);
13342 LibraryElementImpl element = new LibraryElementImpl.forNode( 13400 LibraryElementImpl element = new LibraryElementImpl.forNode(
13343 context, AstFactory.libraryIdentifier2(["lib"])); 13401 context, AstFactory.libraryIdentifier2(["lib"]));
13344 element.definingCompilationUnit = 13402 element.definingCompilationUnit =
13345 new CompilationUnitElementImpl("lib.dart"); 13403 new CompilationUnitElementImpl("lib.dart");
13346 _library.libraryElement = element; 13404 _library.libraryElement = element;
13347 _typeProvider = new TestTypeProvider(); 13405 _typeProvider = new TestTypeProvider();
13348 _visitor = 13406 _visitor =
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
13811 // check propagated type 13869 // check propagated type
13812 FunctionType propagatedType = node.propagatedType as FunctionType; 13870 FunctionType propagatedType = node.propagatedType as FunctionType;
13813 expect(propagatedType.returnType, test.typeProvider.stringType); 13871 expect(propagatedType.returnType, test.typeProvider.stringType);
13814 } on AnalysisException catch (e, stackTrace) { 13872 } on AnalysisException catch (e, stackTrace) {
13815 thrownException[0] = new CaughtException(e, stackTrace); 13873 thrownException[0] = new CaughtException(e, stackTrace);
13816 } 13874 }
13817 } 13875 }
13818 return null; 13876 return null;
13819 } 13877 }
13820 } 13878 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/incremental_resolver_test.dart ('k') | pkg/analyzer/test/generated/test_support.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698