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

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

Issue 1490233007: Remove the old task model (Closed) Base URL: https://github.com/dart-lang/sdk.git@analyzer-breaking-0.27
Patch Set: Created 5 years 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/context/context.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
11 import 'package:analyzer/src/generated/element.dart'; 11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/element_resolver.dart'; 12 import 'package:analyzer/src/generated/element_resolver.dart';
13 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/error.dart'; 14 import 'package:analyzer/src/generated/error.dart';
15 import 'package:analyzer/src/generated/java_core.dart'; 15 import 'package:analyzer/src/generated/java_core.dart';
16 import 'package:analyzer/src/generated/java_engine.dart'; 16 import 'package:analyzer/src/generated/java_engine.dart';
17 import 'package:analyzer/src/generated/java_engine_io.dart'; 17 import 'package:analyzer/src/generated/java_engine_io.dart';
18 import 'package:analyzer/src/generated/java_io.dart'; 18 import 'package:analyzer/src/generated/java_io.dart';
19 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; 19 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
(...skipping 17 matching lines...) Expand all
37 main() { 37 main() {
38 initializeTestEnvironment(); 38 initializeTestEnvironment();
39 runReflectiveTests(AnalysisDeltaTest); 39 runReflectiveTests(AnalysisDeltaTest);
40 runReflectiveTests(ChangeSetTest); 40 runReflectiveTests(ChangeSetTest);
41 runReflectiveTests(EnclosedScopeTest); 41 runReflectiveTests(EnclosedScopeTest);
42 runReflectiveTests(LibraryImportScopeTest); 42 runReflectiveTests(LibraryImportScopeTest);
43 runReflectiveTests(LibraryScopeTest); 43 runReflectiveTests(LibraryScopeTest);
44 runReflectiveTests(ScopeTest); 44 runReflectiveTests(ScopeTest);
45 runReflectiveTests(ElementResolverTest); 45 runReflectiveTests(ElementResolverTest);
46 runReflectiveTests(InheritanceManagerTest); 46 runReflectiveTests(InheritanceManagerTest);
47 if (!AnalysisEngine.instance.useTaskModel) {
48 runReflectiveTests(LibraryElementBuilderTest);
49 }
50 if (!AnalysisEngine.instance.useTaskModel) {
51 runReflectiveTests(LibraryResolver2Test);
52 }
53 if (!AnalysisEngine.instance.useTaskModel) {
54 runReflectiveTests(LibraryResolverTest);
55 }
56 runReflectiveTests(LibraryTest); 47 runReflectiveTests(LibraryTest);
57 runReflectiveTests(StaticTypeAnalyzerTest); 48 runReflectiveTests(StaticTypeAnalyzerTest);
58 runReflectiveTests(StaticTypeAnalyzer2Test); 49 runReflectiveTests(StaticTypeAnalyzer2Test);
59 runReflectiveTests(SubtypeManagerTest); 50 runReflectiveTests(SubtypeManagerTest);
60 runReflectiveTests(TypeOverrideManagerTest); 51 runReflectiveTests(TypeOverrideManagerTest);
61 runReflectiveTests(TypeProviderImplTest); 52 runReflectiveTests(TypeProviderImplTest);
62 runReflectiveTests(TypeResolverVisitorTest); 53 runReflectiveTests(TypeResolverVisitorTest);
63 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); 54 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest);
64 runReflectiveTests(ErrorResolverTest); 55 runReflectiveTests(ErrorResolverTest);
65 runReflectiveTests(HintCodeTest); 56 runReflectiveTests(HintCodeTest);
(...skipping 16 matching lines...) Expand all
82 73
83 static String _DART_INTERCEPTORS = "dart:_interceptors"; 74 static String _DART_INTERCEPTORS = "dart:_interceptors";
84 75
85 static String _DART_JS_HELPER = "dart:_js_helper"; 76 static String _DART_JS_HELPER = "dart:_js_helper";
86 77
87 /** 78 /**
88 * Create an analysis context that has a fake core library already resolved. 79 * Create an analysis context that has a fake core library already resolved.
89 * Return the context that was created. 80 * Return the context that was created.
90 */ 81 */
91 static InternalAnalysisContext contextWithCore() { 82 static InternalAnalysisContext contextWithCore() {
92 if (AnalysisEngine.instance.useTaskModel) {
93 NewAnalysisContextForTests context = new NewAnalysisContextForTests();
94 return initContextWithCore(context);
95 }
96 AnalysisContextForTests context = new AnalysisContextForTests(); 83 AnalysisContextForTests context = new AnalysisContextForTests();
97 return initContextWithCore(context); 84 return initContextWithCore(context);
98 } 85 }
99 86
100 /** 87 /**
101 * Create an analysis context that uses the given [options] and has a fake 88 * Create an analysis context that uses the given [options] and has a fake
102 * core library already resolved. Return the context that was created. 89 * core library already resolved. Return the context that was created.
103 */ 90 */
104 static InternalAnalysisContext contextWithCoreAndOptions( 91 static InternalAnalysisContext contextWithCoreAndOptions(
105 AnalysisOptions options) { 92 AnalysisOptions options) {
106 if (AnalysisEngine.instance.useTaskModel) {
107 NewAnalysisContextForTests context = new NewAnalysisContextForTests();
108 context._internalSetAnalysisOptions(options);
109 return initContextWithCore(context);
110 }
111 AnalysisContextForTests context = new AnalysisContextForTests(); 93 AnalysisContextForTests context = new AnalysisContextForTests();
112 context._internalSetAnalysisOptions(options); 94 context._internalSetAnalysisOptions(options);
113 return initContextWithCore(context); 95 return initContextWithCore(context);
114 } 96 }
115 97
116 /** 98 /**
117 * Initialize the given analysis context with a fake core library already reso lved. 99 * Initialize the given analysis context with a fake core library already reso lved.
118 * 100 *
119 * @param context the context to be initialized (not `null`) 101 * @param context the context to be initialized (not `null`)
120 * @return the analysis context that was created 102 * @return the analysis context that was created
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 // 385 //
404 HashMap<Source, LibraryElement> elementMap = 386 HashMap<Source, LibraryElement> elementMap =
405 new HashMap<Source, LibraryElement>(); 387 new HashMap<Source, LibraryElement>();
406 elementMap[coreSource] = coreLibrary; 388 elementMap[coreSource] = coreLibrary;
407 elementMap[asyncSource] = asyncLibrary; 389 elementMap[asyncSource] = asyncLibrary;
408 elementMap[htmlSource] = htmlLibrary; 390 elementMap[htmlSource] = htmlLibrary;
409 elementMap[mathSource] = mathLibrary; 391 elementMap[mathSource] = mathLibrary;
410 context.recordLibraryElements(elementMap); 392 context.recordLibraryElements(elementMap);
411 return context; 393 return context;
412 } 394 }
413
414 /**
415 * Create an analysis context that has a fake core library already resolved.
416 * Return the context that was created.
417 */
418 static AnalysisContextImpl oldContextWithCore() {
419 AnalysisContextForTests context = new AnalysisContextForTests();
420 return initContextWithCore(context);
421 }
422
423 /**
424 * Create an analysis context that uses the given [options] and has a fake
425 * core library already resolved. Return the context that was created.
426 */
427 static AnalysisContextImpl oldContextWithCoreAndOptions(
428 AnalysisOptions options) {
429 AnalysisContextForTests context = new AnalysisContextForTests();
430 context._internalSetAnalysisOptions(options);
431 return initContextWithCore(context);
432 }
433 } 395 }
434 396
435 /** 397 /**
436 * Instances of the class `AnalysisContextForTests` implement an analysis contex t that has a 398 * An analysis context that has a fake SDK that is much smaller and faster for
437 * fake SDK that is much smaller and faster for testing purposes. 399 * testing purposes.
438 */ 400 */
439 class AnalysisContextForTests extends AnalysisContextImpl { 401 class AnalysisContextForTests extends AnalysisContextImpl {
440 @override 402 @override
441 void set analysisOptions(AnalysisOptions options) { 403 void set analysisOptions(AnalysisOptions options) {
442 AnalysisOptions currentOptions = analysisOptions; 404 AnalysisOptions currentOptions = analysisOptions;
443 bool needsRecompute = currentOptions.analyzeFunctionBodiesPredicate != 405 bool needsRecompute = currentOptions.analyzeFunctionBodiesPredicate !=
444 options.analyzeFunctionBodiesPredicate || 406 options.analyzeFunctionBodiesPredicate ||
445 currentOptions.generateImplicitErrors != 407 currentOptions.generateImplicitErrors !=
446 options.generateImplicitErrors || 408 options.generateImplicitErrors ||
447 currentOptions.generateSdkErrors != options.generateSdkErrors || 409 currentOptions.generateSdkErrors != options.generateSdkErrors ||
(...skipping 5611 matching lines...) Expand 10 before | Expand all | Expand 10 after
6059 new CompilationUnitElementImpl("test.dart"); 6021 new CompilationUnitElementImpl("test.dart");
6060 definingCompilationUnit.librarySource = 6022 definingCompilationUnit.librarySource =
6061 definingCompilationUnit.source = source; 6023 definingCompilationUnit.source = source;
6062 _definingLibrary = ElementFactory.library(context, "test"); 6024 _definingLibrary = ElementFactory.library(context, "test");
6063 _definingLibrary.definingCompilationUnit = definingCompilationUnit; 6025 _definingLibrary.definingCompilationUnit = definingCompilationUnit;
6064 return new InheritanceManager(_definingLibrary); 6026 return new InheritanceManager(_definingLibrary);
6065 } 6027 }
6066 } 6028 }
6067 6029
6068 @reflectiveTest 6030 @reflectiveTest
6069 class LibraryElementBuilderTest {
6070 /**
6071 * The analysis context used to analyze sources.
6072 */
6073 InternalAnalysisContext _context;
6074
6075 /**
6076 * Add a source file to the content provider. The file path should be absolute .
6077 *
6078 * @param filePath the path of the file being added
6079 * @param contents the contents to be returned by the content provider for the specified file
6080 * @return the source object representing the added file
6081 */
6082 Source addSource(String filePath, String contents) {
6083 Source source = new FileBasedSource(FileUtilities2.createFile(filePath));
6084 _context.setContents(source, contents);
6085 return source;
6086 }
6087
6088 void setUp() {
6089 _context = AnalysisContextFactory.contextWithCore();
6090 }
6091
6092 void tearDown() {
6093 _context = null;
6094 }
6095
6096 void test_accessorsAcrossFiles() {
6097 Source librarySource = addSource(
6098 "/lib.dart",
6099 r'''
6100 library lib;
6101 part 'first.dart';
6102 part 'second.dart';''');
6103 addSource(
6104 "/first.dart",
6105 r'''
6106 part of lib;
6107 int get V => 0;''');
6108 addSource(
6109 "/second.dart",
6110 r'''
6111 part of lib;
6112 void set V(int v) {}''');
6113 LibraryElement element = _buildLibrary(librarySource);
6114 expect(element, isNotNull);
6115 List<CompilationUnitElement> sourcedUnits = element.parts;
6116 expect(sourcedUnits, hasLength(2));
6117 List<PropertyAccessorElement> firstAccessors = sourcedUnits[0].accessors;
6118 expect(firstAccessors, hasLength(1));
6119 List<PropertyAccessorElement> secondAccessors = sourcedUnits[1].accessors;
6120 expect(secondAccessors, hasLength(1));
6121 expect(secondAccessors[0].variable, same(firstAccessors[0].variable));
6122 }
6123
6124 void test_empty() {
6125 Source librarySource = addSource("/lib.dart", "library lib;");
6126 LibraryElement element = _buildLibrary(librarySource);
6127 expect(element, isNotNull);
6128 expect(element.name, "lib");
6129 expect(element.entryPoint, isNull);
6130 expect(element.importedLibraries, hasLength(0));
6131 expect(element.imports, hasLength(0));
6132 expect(element.library, same(element));
6133 expect(element.prefixes, hasLength(0));
6134 expect(element.parts, hasLength(0));
6135 CompilationUnitElement unit = element.definingCompilationUnit;
6136 expect(unit, isNotNull);
6137 expect(unit.name, "lib.dart");
6138 expect(unit.library, element);
6139 expect(unit.accessors, hasLength(0));
6140 expect(unit.functions, hasLength(0));
6141 expect(unit.functionTypeAliases, hasLength(0));
6142 expect(unit.types, hasLength(0));
6143 expect(unit.topLevelVariables, hasLength(0));
6144 }
6145
6146 void test_libraryElement_docRange() {
6147 String code = r'''
6148 /// My dart doc.
6149 library lib;
6150
6151 class A {}''';
6152 Source librarySource = addSource("/lib.dart", code);
6153 LibraryElement element = _buildLibrary(librarySource);
6154 expect(element, isNotNull);
6155 SourceRange docRange = element.docRange;
6156 expect(docRange, isNotNull);
6157 expect(docRange.offset, code.indexOf('/// My dart doc.'));
6158 expect(docRange.length, '/// My dart doc.'.length);
6159 }
6160
6161 void test_missingLibraryDirectiveWithPart() {
6162 addSource("/a.dart", "part of lib;");
6163 Source librarySource = addSource("/lib.dart", "part 'a.dart';");
6164 LibraryElement element = _buildLibrary(
6165 librarySource, [ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART]);
6166 expect(element, isNotNull);
6167 }
6168
6169 void test_missingPartOfDirective() {
6170 addSource("/a.dart", "class A {}");
6171 Source librarySource = addSource(
6172 "/lib.dart",
6173 r'''
6174 library lib;
6175
6176 part 'a.dart';''');
6177 LibraryElement element =
6178 _buildLibrary(librarySource, [CompileTimeErrorCode.PART_OF_NON_PART]);
6179 expect(element, isNotNull);
6180 }
6181
6182 void test_multipleFiles() {
6183 Source librarySource = addSource(
6184 "/lib.dart",
6185 r'''
6186 library lib;
6187 part 'first.dart';
6188 part 'second.dart';
6189
6190 class A {}''');
6191 addSource(
6192 "/first.dart",
6193 r'''
6194 part of lib;
6195 class B {}''');
6196 addSource(
6197 "/second.dart",
6198 r'''
6199 part of lib;
6200 class C {}''');
6201 LibraryElement element = _buildLibrary(librarySource);
6202 expect(element, isNotNull);
6203 List<CompilationUnitElement> sourcedUnits = element.parts;
6204 expect(sourcedUnits, hasLength(2));
6205 _assertTypes(element.definingCompilationUnit, ["A"]);
6206 if (sourcedUnits[0].name == "first.dart") {
6207 _assertTypes(sourcedUnits[0], ["B"]);
6208 _assertTypes(sourcedUnits[1], ["C"]);
6209 } else {
6210 _assertTypes(sourcedUnits[0], ["C"]);
6211 _assertTypes(sourcedUnits[1], ["B"]);
6212 }
6213 }
6214
6215 void test_singleFile() {
6216 Source librarySource = addSource(
6217 "/lib.dart",
6218 r'''
6219 /// My dart doc.
6220 library lib;
6221
6222 class A {}''');
6223 LibraryElement element = _buildLibrary(librarySource);
6224 expect(element, isNotNull);
6225 _assertTypes(element.definingCompilationUnit, ["A"]);
6226 }
6227
6228 /**
6229 * Ensure that there are elements representing all of the types in the given a rray of type names.
6230 *
6231 * @param unit the compilation unit containing the types
6232 * @param typeNames the names of the types that should be found
6233 */
6234 void _assertTypes(CompilationUnitElement unit, List<String> typeNames) {
6235 expect(unit, isNotNull);
6236 List<ClassElement> types = unit.types;
6237 expect(types, hasLength(typeNames.length));
6238 for (ClassElement type in types) {
6239 expect(type, isNotNull);
6240 String actualTypeName = type.displayName;
6241 bool wasExpected = false;
6242 for (String expectedTypeName in typeNames) {
6243 if (expectedTypeName == actualTypeName) {
6244 wasExpected = true;
6245 }
6246 }
6247 if (!wasExpected) {
6248 fail("Found unexpected type $actualTypeName");
6249 }
6250 }
6251 }
6252
6253 /**
6254 * Build the element model for the library whose defining compilation unit has the given source.
6255 *
6256 * @param librarySource the source of the defining compilation unit for the li brary
6257 * @param expectedErrorCodes the errors that are expected to be found while bu ilding the element
6258 * model
6259 * @return the element model that was built for the library
6260 * @throws Exception if the element model could not be built
6261 */
6262 LibraryElement _buildLibrary(Source librarySource,
6263 [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) {
6264 LibraryResolver resolver = new LibraryResolver(_context);
6265 LibraryElementBuilder builder = new LibraryElementBuilder(
6266 resolver.analysisContext, resolver.errorListener);
6267 Library library = resolver.createLibrary(librarySource);
6268 LibraryElement element = builder.buildLibrary(library);
6269 GatheringErrorListener listener = new GatheringErrorListener();
6270 listener.addAll2(resolver.errorListener);
6271 listener.assertErrorsWithCodes(expectedErrorCodes);
6272 return element;
6273 }
6274 }
6275
6276 @reflectiveTest
6277 class LibraryImportScopeTest extends ResolverTestCase { 6031 class LibraryImportScopeTest extends ResolverTestCase {
6278 void test_conflictingImports() { 6032 void test_conflictingImports() {
6279 AnalysisContext context = AnalysisContextFactory.contextWithCore(); 6033 AnalysisContext context = AnalysisContextFactory.contextWithCore();
6280 String typeNameA = "A"; 6034 String typeNameA = "A";
6281 String typeNameB = "B"; 6035 String typeNameB = "B";
6282 String typeNameC = "C"; 6036 String typeNameC = "C";
6283 ClassElement typeA = ElementFactory.classElement2(typeNameA); 6037 ClassElement typeA = ElementFactory.classElement2(typeNameA);
6284 ClassElement typeB1 = ElementFactory.classElement2(typeNameB); 6038 ClassElement typeB1 = ElementFactory.classElement2(typeNameB);
6285 ClassElement typeB2 = ElementFactory.classElement2(typeNameB); 6039 ClassElement typeB2 = ElementFactory.classElement2(typeNameB);
6286 ClassElement typeC = ElementFactory.classElement2(typeNameC); 6040 ClassElement typeC = ElementFactory.classElement2(typeNameC);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
6447 errorListener.assertNoErrors(); 6201 errorListener.assertNoErrors();
6448 expect(prefixedElement, same(prefixedType)); 6202 expect(prefixedElement, same(prefixedType));
6449 Element nonPrefixedElement = 6203 Element nonPrefixedElement =
6450 scope.lookup(AstFactory.identifier3(typeName), importingLibrary); 6204 scope.lookup(AstFactory.identifier3(typeName), importingLibrary);
6451 errorListener.assertNoErrors(); 6205 errorListener.assertNoErrors();
6452 expect(nonPrefixedElement, same(nonPrefixedType)); 6206 expect(nonPrefixedElement, same(nonPrefixedType));
6453 } 6207 }
6454 } 6208 }
6455 6209
6456 @reflectiveTest 6210 @reflectiveTest
6457 class LibraryResolver2Test extends ResolverTestCase {
6458 LibraryResolver2 _resolver;
6459
6460 Source _coreLibrarySource;
6461
6462 Source _asyncLibrarySource;
6463
6464 @override
6465 void setUp() {
6466 super.setUp();
6467 _resolver = new LibraryResolver2(analysisContext2);
6468 _coreLibrarySource =
6469 analysisContext2.sourceFactory.forUri(DartSdk.DART_CORE);
6470 _asyncLibrarySource =
6471 analysisContext2.sourceFactory.forUri(DartSdk.DART_ASYNC);
6472 }
6473
6474 void test_imports_relative() {
6475 Source sourceA = addSource(r'''
6476 library libA;
6477 import 'libB.dart';
6478 class A {}''');
6479 Source sourceB = addNamedSource(
6480 "/libB.dart",
6481 r'''
6482 library libB;
6483 import 'test.dart
6484 class B {}''');
6485 List<ResolvableLibrary> cycle = new List<ResolvableLibrary>();
6486 ResolvableLibrary coreLib = _createResolvableLibrary(_coreLibrarySource);
6487 coreLib.libraryElement = analysisContext2
6488 .computeLibraryElement(_coreLibrarySource) as LibraryElementImpl;
6489 ResolvableLibrary asyncLib = _createResolvableLibrary(_asyncLibrarySource);
6490 asyncLib.libraryElement = analysisContext2
6491 .computeLibraryElement(_asyncLibrarySource) as LibraryElementImpl;
6492 ResolvableLibrary libA = _createResolvableLibrary(sourceA);
6493 ResolvableLibrary libB = _createResolvableLibrary(sourceB);
6494 libA.importedLibraries = <ResolvableLibrary>[coreLib, asyncLib, libB];
6495 libB.importedLibraries = <ResolvableLibrary>[coreLib, asyncLib, libA];
6496 cycle.add(libA);
6497 cycle.add(libB);
6498 LibraryElement library = _resolver.resolveLibrary(sourceA, cycle);
6499 List<LibraryElement> importedLibraries = library.importedLibraries;
6500 assertNamedElements(importedLibraries, ["dart.core", "libB"]);
6501 }
6502
6503 ResolvableLibrary _createResolvableLibrary(Source source) {
6504 CompilationUnit unit = analysisContext2.parseCompilationUnit(source);
6505 ResolvableLibrary resolvableLibrary = new ResolvableLibrary(source);
6506 resolvableLibrary.resolvableCompilationUnits = <ResolvableCompilationUnit>[
6507 new ResolvableCompilationUnit(source, unit)
6508 ];
6509 return resolvableLibrary;
6510 }
6511 }
6512
6513 @reflectiveTest
6514 class LibraryResolverTest extends ResolverTestCase {
6515 LibraryResolver _resolver;
6516
6517 @override
6518 void setUp() {
6519 super.setUp();
6520 _resolver = new LibraryResolver(analysisContext2);
6521 }
6522
6523 void test_imports_dart_html() {
6524 Source source = addSource(r'''
6525 library libA;
6526 import 'dart:html';
6527 class A {}''');
6528 LibraryElement library = _resolver.resolveLibrary(source, true);
6529 List<LibraryElement> importedLibraries = library.importedLibraries;
6530 assertNamedElements(importedLibraries, ["dart.core", "dart.dom.html"]);
6531 }
6532
6533 void test_imports_none() {
6534 Source source = addSource(r'''
6535 library libA;
6536 class A {}''');
6537 LibraryElement library = _resolver.resolveLibrary(source, true);
6538 List<LibraryElement> importedLibraries = library.importedLibraries;
6539 assertNamedElements(importedLibraries, ["dart.core"]);
6540 }
6541
6542 void test_imports_relative() {
6543 addNamedSource("/libB.dart", "library libB;");
6544 Source source = addSource(r'''
6545 library libA;
6546 import 'libB.dart';
6547 class A {}''');
6548 LibraryElement library = _resolver.resolveLibrary(source, true);
6549 List<LibraryElement> importedLibraries = library.importedLibraries;
6550 assertNamedElements(importedLibraries, ["dart.core", "libB"]);
6551 }
6552 }
6553
6554 @reflectiveTest
6555 class LibraryScopeTest extends ResolverTestCase { 6211 class LibraryScopeTest extends ResolverTestCase {
6556 void test_creation_empty() { 6212 void test_creation_empty() {
6557 LibraryElement definingLibrary = createDefaultTestLibrary(); 6213 LibraryElement definingLibrary = createDefaultTestLibrary();
6558 GatheringErrorListener errorListener = new GatheringErrorListener(); 6214 GatheringErrorListener errorListener = new GatheringErrorListener();
6559 new LibraryScope(definingLibrary, errorListener); 6215 new LibraryScope(definingLibrary, errorListener);
6560 } 6216 }
6561 6217
6562 void test_creation_nonEmpty() { 6218 void test_creation_nonEmpty() {
6563 AnalysisContext context = AnalysisContextFactory.contextWithCore(); 6219 AnalysisContext context = AnalysisContextFactory.contextWithCore();
6564 String importedTypeName = "A"; 6220 String importedTypeName = "A";
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
6729 void test_MemberMap_put() { 6385 void test_MemberMap_put() {
6730 MethodElement m1 = ElementFactory.methodElement("m1", _nullType); 6386 MethodElement m1 = ElementFactory.methodElement("m1", _nullType);
6731 MemberMap map = new MemberMap(); 6387 MemberMap map = new MemberMap();
6732 expect(map.size, 0); 6388 expect(map.size, 0);
6733 map.put(m1.name, m1); 6389 map.put(m1.name, m1);
6734 expect(map.size, 1); 6390 expect(map.size, 1);
6735 expect(map.get("m1"), m1); 6391 expect(map.get("m1"), m1);
6736 } 6392 }
6737 } 6393 }
6738 6394
6739 /**
6740 * An analysis context that has a fake SDK that is much smaller and faster for
6741 * testing purposes.
6742 */
6743 class NewAnalysisContextForTests extends newContext.AnalysisContextImpl {
6744 @override
6745 void set analysisOptions(AnalysisOptions options) {
6746 AnalysisOptions currentOptions = analysisOptions;
6747 bool needsRecompute = currentOptions.analyzeFunctionBodiesPredicate !=
6748 options.analyzeFunctionBodiesPredicate ||
6749 currentOptions.generateImplicitErrors !=
6750 options.generateImplicitErrors ||
6751 currentOptions.generateSdkErrors != options.generateSdkErrors ||
6752 currentOptions.dart2jsHint != options.dart2jsHint ||
6753 (currentOptions.hint && !options.hint) ||
6754 currentOptions.preserveComments != options.preserveComments ||
6755 currentOptions.enableStrictCallChecks != options.enableStrictCallChecks;
6756 if (needsRecompute) {
6757 fail(
6758 "Cannot set options that cause the sources to be reanalyzed in a test context");
6759 }
6760 super.analysisOptions = options;
6761 }
6762
6763 @override
6764 bool exists(Source source) =>
6765 super.exists(source) || sourceFactory.dartSdk.context.exists(source);
6766
6767 @override
6768 TimestampedData<String> getContents(Source source) {
6769 if (source.isInSystemLibrary) {
6770 return sourceFactory.dartSdk.context.getContents(source);
6771 }
6772 return super.getContents(source);
6773 }
6774
6775 @override
6776 int getModificationStamp(Source source) {
6777 if (source.isInSystemLibrary) {
6778 return sourceFactory.dartSdk.context.getModificationStamp(source);
6779 }
6780 return super.getModificationStamp(source);
6781 }
6782
6783 /**
6784 * Set the analysis options, even if they would force re-analysis. This method should only be
6785 * invoked before the fake SDK is initialized.
6786 *
6787 * @param options the analysis options to be set
6788 */
6789 void _internalSetAnalysisOptions(AnalysisOptions options) {
6790 super.analysisOptions = options;
6791 }
6792 }
6793
6794 @reflectiveTest 6395 @reflectiveTest
6795 class NonHintCodeTest extends ResolverTestCase { 6396 class NonHintCodeTest extends ResolverTestCase {
6796 void test_deadCode_deadBlock_conditionalElse_debugConst() { 6397 void test_deadCode_deadBlock_conditionalElse_debugConst() {
6797 Source source = addSource(r''' 6398 Source source = addSource(r'''
6798 const bool DEBUG = true; 6399 const bool DEBUG = true;
6799 f() { 6400 f() {
6800 DEBUG ? 1 : 2; 6401 DEBUG ? 1 : 2;
6801 }'''); 6402 }''');
6802 computeLibrarySourceErrors(source); 6403 computeLibrarySourceErrors(source);
6803 assertNoErrors(source); 6404 assertNoErrors(source);
(...skipping 6342 matching lines...) Expand 10 before | Expand all | Expand 10 after
13146 _resolveTestUnit(code); 12747 _resolveTestUnit(code);
13147 12748
13148 SimpleIdentifier identifier = _findIdentifier('foo'); 12749 SimpleIdentifier identifier = _findIdentifier('foo');
13149 VariableDeclaration declaration = 12750 VariableDeclaration declaration =
13150 identifier.getAncestor((node) => node is VariableDeclaration); 12751 identifier.getAncestor((node) => node is VariableDeclaration);
13151 expect(declaration.initializer.staticType.name, 'String'); 12752 expect(declaration.initializer.staticType.name, 'String');
13152 expect(declaration.initializer.propagatedType, isNull); 12753 expect(declaration.initializer.propagatedType, isNull);
13153 } 12754 }
13154 12755
13155 void test_genericFunction() { 12756 void test_genericFunction() {
13156 if (!AnalysisEngine.instance.useTaskModel) {
13157 return;
13158 }
13159 _resolveTestUnit(r'/*=T*/ f/*<T>*/(/*=T*/ x) => null;'); 12757 _resolveTestUnit(r'/*=T*/ f/*<T>*/(/*=T*/ x) => null;');
13160 SimpleIdentifier f = _findIdentifier('f'); 12758 SimpleIdentifier f = _findIdentifier('f');
13161 FunctionElementImpl e = f.staticElement; 12759 FunctionElementImpl e = f.staticElement;
13162 expect(e.typeParameters.toString(), '[T]'); 12760 expect(e.typeParameters.toString(), '[T]');
13163 expect(e.type.typeParameters.toString(), '[T]'); 12761 expect(e.type.typeParameters.toString(), '[T]');
13164 expect(e.type.typeParameters[0].type, e.type.typeArguments[0]); 12762 expect(e.type.typeParameters[0].type, e.type.typeArguments[0]);
13165 expect(e.type.toString(), '(T) → T'); 12763 expect(e.type.toString(), '(T) → T');
13166 12764
13167 // Substitute for T 12765 // Substitute for T
13168 DartType t = e.typeParameters[0].type; 12766 DartType t = e.typeParameters[0].type;
13169 FunctionType ft = e.type.substitute2([typeProvider.stringType], [t]); 12767 FunctionType ft = e.type.substitute2([typeProvider.stringType], [t]);
13170 expect(ft.toString(), '(String) → String'); 12768 expect(ft.toString(), '(String) → String');
13171 } 12769 }
13172 12770
13173 void test_genericMethod() { 12771 void test_genericMethod() {
13174 if (!AnalysisEngine.instance.useTaskModel) {
13175 return;
13176 }
13177 _resolveTestUnit(r''' 12772 _resolveTestUnit(r'''
13178 class C<E> { 12773 class C<E> {
13179 List/*<T>*/ f/*<T>*/(E e) => null; 12774 List/*<T>*/ f/*<T>*/(E e) => null;
13180 } 12775 }
13181 main() { 12776 main() {
13182 C<String> cOfString; 12777 C<String> cOfString;
13183 } 12778 }
13184 '''); 12779 ''');
13185 SimpleIdentifier f = _findIdentifier('f'); 12780 SimpleIdentifier f = _findIdentifier('f');
13186 MethodElementImpl e = f.staticElement; 12781 MethodElementImpl e = f.staticElement;
13187 expect(e.typeParameters.toString(), '[T]'); 12782 expect(e.typeParameters.toString(), '[T]');
13188 expect(e.type.typeParameters.toString(), '[T, E]'); 12783 expect(e.type.typeParameters.toString(), '[T, E]');
13189 expect(e.type.typeArguments.toString(), '[T, E]'); 12784 expect(e.type.typeArguments.toString(), '[T, E]');
13190 expect(e.type.toString(), '(E) → List<T>'); 12785 expect(e.type.toString(), '(E) → List<T>');
13191 12786
13192 SimpleIdentifier c = _findIdentifier('cOfString'); 12787 SimpleIdentifier c = _findIdentifier('cOfString');
13193 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; 12788 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type;
13194 expect(ft.toString(), '(String) → List<T>'); 12789 expect(ft.toString(), '(String) → List<T>');
13195 DartType t = e.typeParameters[0].type; 12790 DartType t = e.typeParameters[0].type;
13196 ft = ft.substitute2([typeProvider.intType], [t]); 12791 ft = ft.substitute2([typeProvider.intType], [t]);
13197 expect(ft.toString(), '(String) → List<int>'); 12792 expect(ft.toString(), '(String) → List<int>');
13198 } 12793 }
13199 12794
13200 void test_genericMethod_functionTypedParameter() { 12795 void test_genericMethod_functionTypedParameter() {
13201 if (!AnalysisEngine.instance.useTaskModel) {
13202 return;
13203 }
13204 _resolveTestUnit(r''' 12796 _resolveTestUnit(r'''
13205 class C<E> { 12797 class C<E> {
13206 List/*<T>*/ f/*<T>*/(/*=T*/ f(E e)) => null; 12798 List/*<T>*/ f/*<T>*/(/*=T*/ f(E e)) => null;
13207 } 12799 }
13208 main() { 12800 main() {
13209 C<String> cOfString; 12801 C<String> cOfString;
13210 } 12802 }
13211 '''); 12803 ''');
13212 SimpleIdentifier f = _findIdentifier('f'); 12804 SimpleIdentifier f = _findIdentifier('f');
13213 MethodElementImpl e = f.staticElement; 12805 MethodElementImpl e = f.staticElement;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
13487 v = 3; 13079 v = 3;
13488 v; // marker 13080 v; // marker
13489 }'''; 13081 }''';
13490 _assertPropagatedAssignedType( 13082 _assertPropagatedAssignedType(
13491 code, typeProvider.dynamicType, typeProvider.intType); 13083 code, typeProvider.dynamicType, typeProvider.intType);
13492 _assertTypeOfMarkedExpression( 13084 _assertTypeOfMarkedExpression(
13493 code, typeProvider.dynamicType, typeProvider.intType); 13085 code, typeProvider.dynamicType, typeProvider.intType);
13494 } 13086 }
13495 13087
13496 void test_localVariableInference_transitive_field_inferred_lexical() { 13088 void test_localVariableInference_transitive_field_inferred_lexical() {
13497 if (!AnalysisEngine.instance.useTaskModel) {
13498 return;
13499 }
13500 String code = r''' 13089 String code = r'''
13501 class A { 13090 class A {
13502 final x = 3; 13091 final x = 3;
13503 f() { 13092 f() {
13504 var v = x; 13093 var v = x;
13505 return v; // marker 13094 return v; // marker
13506 } 13095 }
13507 } 13096 }
13508 main() { 13097 main() {
13509 } 13098 }
13510 '''; 13099 ''';
13511 _assertPropagatedAssignedType(code, typeProvider.intType, null); 13100 _assertPropagatedAssignedType(code, typeProvider.intType, null);
13512 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 13101 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13513 } 13102 }
13514 13103
13515 void test_localVariableInference_transitive_field_inferred_reversed() { 13104 void test_localVariableInference_transitive_field_inferred_reversed() {
13516 if (!AnalysisEngine.instance.useTaskModel) {
13517 return;
13518 }
13519 String code = r''' 13105 String code = r'''
13520 class A { 13106 class A {
13521 f() { 13107 f() {
13522 var v = x; 13108 var v = x;
13523 return v; // marker 13109 return v; // marker
13524 } 13110 }
13525 final x = 3; 13111 final x = 3;
13526 } 13112 }
13527 main() { 13113 main() {
13528 } 13114 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
13579 main() { 13165 main() {
13580 var x = 3; 13166 var x = 3;
13581 var v = x; 13167 var v = x;
13582 v; // marker 13168 v; // marker
13583 }'''; 13169 }''';
13584 _assertPropagatedAssignedType(code, typeProvider.intType, null); 13170 _assertPropagatedAssignedType(code, typeProvider.intType, null);
13585 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 13171 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13586 } 13172 }
13587 13173
13588 void test_localVariableInference_transitive_toplevel_inferred_lexical() { 13174 void test_localVariableInference_transitive_toplevel_inferred_lexical() {
13589 if (!AnalysisEngine.instance.useTaskModel) {
13590 return;
13591 }
13592 String code = r''' 13175 String code = r'''
13593 final x = 3; 13176 final x = 3;
13594 main() { 13177 main() {
13595 var v = x; 13178 var v = x;
13596 v; // marker 13179 v; // marker
13597 } 13180 }
13598 '''; 13181 ''';
13599 _assertPropagatedAssignedType(code, typeProvider.intType, null); 13182 _assertPropagatedAssignedType(code, typeProvider.intType, null);
13600 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 13183 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13601 } 13184 }
13602 13185
13603 void test_localVariableInference_transitive_toplevel_inferred_reversed() { 13186 void test_localVariableInference_transitive_toplevel_inferred_reversed() {
13604 if (!AnalysisEngine.instance.useTaskModel) {
13605 return;
13606 }
13607 String code = r''' 13187 String code = r'''
13608 main() { 13188 main() {
13609 var v = x; 13189 var v = x;
13610 v; // marker 13190 v; // marker
13611 } 13191 }
13612 final x = 3; 13192 final x = 3;
13613 '''; 13193 ''';
13614 _assertPropagatedAssignedType(code, typeProvider.intType, null); 13194 _assertPropagatedAssignedType(code, typeProvider.intType, null);
13615 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 13195 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
13616 } 13196 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
13806 } 13386 }
13807 13387
13808 void test_getType_noScope() { 13388 void test_getType_noScope() {
13809 TypeOverrideManager manager = new TypeOverrideManager(); 13389 TypeOverrideManager manager = new TypeOverrideManager();
13810 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); 13390 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull);
13811 } 13391 }
13812 } 13392 }
13813 13393
13814 @reflectiveTest 13394 @reflectiveTest
13815 class TypePropagationTest extends ResolverTestCase { 13395 class TypePropagationTest extends ResolverTestCase {
13816 void test_invocation_target_prefixed() {
13817 addNamedSource(
13818 '/helper.dart',
13819 '''
13820 library helper;
13821 int max(int x, int y) => 0;
13822 ''');
13823 String code = '''
13824 import 'helper.dart' as helper;
13825 main() {
13826 helper.max(10, 10); // marker
13827 }''';
13828 SimpleIdentifier methodName =
13829 _findMarkedIdentifier(code, "(10, 10); // marker");
13830 MethodInvocation methodInvoke = methodName.parent;
13831 expect(methodInvoke.methodName.staticElement, isNotNull);
13832 expect(methodInvoke.methodName.propagatedElement, isNull);
13833 }
13834
13835 void fail_mergePropagatedTypesAtJoinPoint_1() { 13396 void fail_mergePropagatedTypesAtJoinPoint_1() {
13836 // https://code.google.com/p/dart/issues/detail?id=19929 13397 // https://code.google.com/p/dart/issues/detail?id=19929
13837 _assertTypeOfMarkedExpression( 13398 _assertTypeOfMarkedExpression(
13838 r''' 13399 r'''
13839 f1(x) { 13400 f1(x) {
13840 var y = []; 13401 var y = [];
13841 if (x) { 13402 if (x) {
13842 y = 0; 13403 y = 0;
13843 } else { 13404 } else {
13844 y = ''; 13405 y = '';
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
14110 LibraryElement library = resolve2(source); 13671 LibraryElement library = resolve2(source);
14111 assertNoErrors(source); 13672 assertNoErrors(source);
14112 verify([source]); 13673 verify([source]);
14113 CompilationUnit unit = resolveCompilationUnit(source, library); 13674 CompilationUnit unit = resolveCompilationUnit(source, library);
14114 SimpleIdentifier identifier = EngineTestCase.findNode( 13675 SimpleIdentifier identifier = EngineTestCase.findNode(
14115 unit, code, "context", (node) => node is SimpleIdentifier); 13676 unit, code, "context", (node) => node is SimpleIdentifier);
14116 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); 13677 expect(identifier.propagatedType.name, "CanvasRenderingContext2D");
14117 } 13678 }
14118 13679
14119 void test_finalPropertyInducingVariable_classMember_instance() { 13680 void test_finalPropertyInducingVariable_classMember_instance() {
14120 // TODO(scheglov) remove after switching to the task model
14121 if (!AnalysisEngine.instance.useTaskModel) return;
14122 addNamedSource( 13681 addNamedSource(
14123 "/lib.dart", 13682 "/lib.dart",
14124 r''' 13683 r'''
14125 class A { 13684 class A {
14126 final v = 0; 13685 final v = 0;
14127 }'''); 13686 }''');
14128 String code = r''' 13687 String code = r'''
14129 import 'lib.dart'; 13688 import 'lib.dart';
14130 f(A a) { 13689 f(A a) {
14131 return a.v; // marker 13690 return a.v; // marker
14132 }'''; 13691 }''';
14133 _assertTypeOfMarkedExpression( 13692 _assertTypeOfMarkedExpression(
14134 code, typeProvider.dynamicType, typeProvider.intType); 13693 code, typeProvider.dynamicType, typeProvider.intType);
14135 } 13694 }
14136 13695
14137 void test_finalPropertyInducingVariable_classMember_instance_inherited() { 13696 void test_finalPropertyInducingVariable_classMember_instance_inherited() {
14138 // TODO(scheglov) remove after switching to the task model
14139 if (!AnalysisEngine.instance.useTaskModel) return;
14140 addNamedSource( 13697 addNamedSource(
14141 "/lib.dart", 13698 "/lib.dart",
14142 r''' 13699 r'''
14143 class A { 13700 class A {
14144 final v = 0; 13701 final v = 0;
14145 }'''); 13702 }''');
14146 String code = r''' 13703 String code = r'''
14147 import 'lib.dart'; 13704 import 'lib.dart';
14148 class B extends A { 13705 class B extends A {
14149 m() { 13706 m() {
14150 return v; // marker 13707 return v; // marker
14151 } 13708 }
14152 }'''; 13709 }''';
14153 _assertTypeOfMarkedExpression( 13710 _assertTypeOfMarkedExpression(
14154 code, typeProvider.dynamicType, typeProvider.intType); 13711 code, typeProvider.dynamicType, typeProvider.intType);
14155 } 13712 }
14156 13713
14157 void test_finalPropertyInducingVariable_classMember_instance_propagatedTarget( ) { 13714 void test_finalPropertyInducingVariable_classMember_instance_propagatedTarget( ) {
14158 // TODO(scheglov) remove after switching to the task model
14159 if (!AnalysisEngine.instance.useTaskModel) return;
14160 addNamedSource( 13715 addNamedSource(
14161 "/lib.dart", 13716 "/lib.dart",
14162 r''' 13717 r'''
14163 class A { 13718 class A {
14164 final v = 0; 13719 final v = 0;
14165 }'''); 13720 }''');
14166 String code = r''' 13721 String code = r'''
14167 import 'lib.dart'; 13722 import 'lib.dart';
14168 f(p) { 13723 f(p) {
14169 if (p is A) { 13724 if (p is A) {
14170 return p.v; // marker 13725 return p.v; // marker
14171 } 13726 }
14172 }'''; 13727 }''';
14173 _assertTypeOfMarkedExpression( 13728 _assertTypeOfMarkedExpression(
14174 code, typeProvider.dynamicType, typeProvider.intType); 13729 code, typeProvider.dynamicType, typeProvider.intType);
14175 } 13730 }
14176 13731
14177 void test_finalPropertyInducingVariable_classMember_instance_unprefixed() { 13732 void test_finalPropertyInducingVariable_classMember_instance_unprefixed() {
14178 // TODO(scheglov) remove after switching to the task model
14179 if (!AnalysisEngine.instance.useTaskModel) return;
14180 String code = r''' 13733 String code = r'''
14181 class A { 13734 class A {
14182 final v = 0; 13735 final v = 0;
14183 m() { 13736 m() {
14184 v; // marker 13737 v; // marker
14185 } 13738 }
14186 }'''; 13739 }''';
14187 _assertTypeOfMarkedExpression( 13740 _assertTypeOfMarkedExpression(
14188 code, typeProvider.dynamicType, typeProvider.intType); 13741 code, typeProvider.dynamicType, typeProvider.intType);
14189 } 13742 }
14190 13743
14191 void test_finalPropertyInducingVariable_classMember_static() { 13744 void test_finalPropertyInducingVariable_classMember_static() {
14192 // TODO(scheglov) remove after switching to the task model
14193 if (!AnalysisEngine.instance.useTaskModel) return;
14194 addNamedSource( 13745 addNamedSource(
14195 "/lib.dart", 13746 "/lib.dart",
14196 r''' 13747 r'''
14197 class A { 13748 class A {
14198 static final V = 0; 13749 static final V = 0;
14199 }'''); 13750 }''');
14200 String code = r''' 13751 String code = r'''
14201 import 'lib.dart'; 13752 import 'lib.dart';
14202 f() { 13753 f() {
14203 return A.V; // marker 13754 return A.V; // marker
14204 }'''; 13755 }''';
14205 _assertTypeOfMarkedExpression( 13756 _assertTypeOfMarkedExpression(
14206 code, typeProvider.dynamicType, typeProvider.intType); 13757 code, typeProvider.dynamicType, typeProvider.intType);
14207 } 13758 }
14208 13759
14209 void test_finalPropertyInducingVariable_topLevelVariable_prefixed() { 13760 void test_finalPropertyInducingVariable_topLevelVariable_prefixed() {
14210 // TODO(scheglov) remove after switching to the task model
14211 if (!AnalysisEngine.instance.useTaskModel) return;
14212 addNamedSource("/lib.dart", "final V = 0;"); 13761 addNamedSource("/lib.dart", "final V = 0;");
14213 String code = r''' 13762 String code = r'''
14214 import 'lib.dart' as p; 13763 import 'lib.dart' as p;
14215 f() { 13764 f() {
14216 var v2 = p.V; // marker prefixed 13765 var v2 = p.V; // marker prefixed
14217 }'''; 13766 }''';
14218 _assertTypeOfMarkedExpression( 13767 _assertTypeOfMarkedExpression(
14219 code, typeProvider.dynamicType, typeProvider.intType); 13768 code, typeProvider.dynamicType, typeProvider.intType);
14220 } 13769 }
14221 13770
14222 void test_finalPropertyInducingVariable_topLevelVariable_simple() { 13771 void test_finalPropertyInducingVariable_topLevelVariable_simple() {
14223 // TODO(scheglov) remove after switching to the task model
14224 if (!AnalysisEngine.instance.useTaskModel) return;
14225 addNamedSource("/lib.dart", "final V = 0;"); 13772 addNamedSource("/lib.dart", "final V = 0;");
14226 String code = r''' 13773 String code = r'''
14227 import 'lib.dart'; 13774 import 'lib.dart';
14228 f() { 13775 f() {
14229 return V; // marker simple 13776 return V; // marker simple
14230 }'''; 13777 }''';
14231 _assertTypeOfMarkedExpression( 13778 _assertTypeOfMarkedExpression(
14232 code, typeProvider.dynamicType, typeProvider.intType); 13779 code, typeProvider.dynamicType, typeProvider.intType);
14233 } 13780 }
14234 13781
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
14644 expect(identifier.propagatedType, same(null)); 14191 expect(identifier.propagatedType, same(null));
14645 } 14192 }
14646 { 14193 {
14647 SimpleIdentifier identifier = EngineTestCase.findNode( 14194 SimpleIdentifier identifier = EngineTestCase.findNode(
14648 unit, code, "v; // marker", (node) => node is SimpleIdentifier); 14195 unit, code, "v; // marker", (node) => node is SimpleIdentifier);
14649 expect(identifier.staticType, same(typeProvider.intType)); 14196 expect(identifier.staticType, same(typeProvider.intType));
14650 expect(identifier.propagatedType, same(null)); 14197 expect(identifier.propagatedType, same(null));
14651 } 14198 }
14652 } 14199 }
14653 14200
14201 void test_invocation_target_prefixed() {
14202 addNamedSource(
14203 '/helper.dart',
14204 '''
14205 library helper;
14206 int max(int x, int y) => 0;
14207 ''');
14208 String code = '''
14209 import 'helper.dart' as helper;
14210 main() {
14211 helper.max(10, 10); // marker
14212 }''';
14213 SimpleIdentifier methodName =
14214 _findMarkedIdentifier(code, "(10, 10); // marker");
14215 MethodInvocation methodInvoke = methodName.parent;
14216 expect(methodInvoke.methodName.staticElement, isNotNull);
14217 expect(methodInvoke.methodName.propagatedElement, isNull);
14218 }
14219
14654 void test_is_conditional() { 14220 void test_is_conditional() {
14655 Source source = addSource(r''' 14221 Source source = addSource(r'''
14656 class A {} 14222 class A {}
14657 A f(var p) { 14223 A f(var p) {
14658 return (p is A) ? p : null; 14224 return (p is A) ? p : null;
14659 }'''); 14225 }''');
14660 LibraryElement library = resolve2(source); 14226 LibraryElement library = resolve2(source);
14661 assertNoErrors(source); 14227 assertNoErrors(source);
14662 verify([source]); 14228 verify([source]);
14663 CompilationUnit unit = resolveCompilationUnit(source, library); 14229 CompilationUnit unit = resolveCompilationUnit(source, library);
(...skipping 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after
16237 15803
16238 void _resolveTestUnit(String code) { 15804 void _resolveTestUnit(String code) {
16239 testCode = code; 15805 testCode = code;
16240 testSource = addSource(testCode); 15806 testSource = addSource(testCode);
16241 LibraryElement library = resolve2(testSource); 15807 LibraryElement library = resolve2(testSource);
16242 assertNoErrors(testSource); 15808 assertNoErrors(testSource);
16243 verify([testSource]); 15809 verify([testSource]);
16244 testUnit = resolveCompilationUnit(testSource, library); 15810 testUnit = resolveCompilationUnit(testSource, library);
16245 } 15811 }
16246 } 15812 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/incremental_resolver_test.dart ('k') | pkg/analyzer/test/src/context/abstract_context.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698