| OLD | NEW |
| 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 analyzer.test.generated.resolver_test; | 5 library analyzer.test.generated.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 import 'package:unittest/unittest.dart'; | 36 import 'package:unittest/unittest.dart'; |
| 37 | 37 |
| 38 import '../reflective_tests.dart'; | 38 import '../reflective_tests.dart'; |
| 39 import '../utils.dart'; | 39 import '../utils.dart'; |
| 40 import 'test_support.dart'; | 40 import 'test_support.dart'; |
| 41 | 41 |
| 42 main() { | 42 main() { |
| 43 initializeTestEnvironment(); | 43 initializeTestEnvironment(); |
| 44 runReflectiveTests(AnalysisDeltaTest); | 44 runReflectiveTests(AnalysisDeltaTest); |
| 45 runReflectiveTests(ChangeSetTest); | 45 runReflectiveTests(ChangeSetTest); |
| 46 runReflectiveTests(DisableAsyncTestCase); |
| 46 runReflectiveTests(EnclosedScopeTest); | 47 runReflectiveTests(EnclosedScopeTest); |
| 47 runReflectiveTests(LibraryImportScopeTest); | 48 runReflectiveTests(LibraryImportScopeTest); |
| 48 runReflectiveTests(LibraryScopeTest); | 49 runReflectiveTests(LibraryScopeTest); |
| 49 runReflectiveTests(ScopeTest); | 50 runReflectiveTests(ScopeTest); |
| 50 runReflectiveTests(ElementResolverTest); | 51 runReflectiveTests(ElementResolverTest); |
| 51 runReflectiveTests(InheritanceManagerTest); | 52 runReflectiveTests(InheritanceManagerTest); |
| 52 runReflectiveTests(StaticTypeAnalyzerTest); | 53 runReflectiveTests(StaticTypeAnalyzerTest); |
| 53 runReflectiveTests(StaticTypeAnalyzer2Test); | 54 runReflectiveTests(StaticTypeAnalyzer2Test); |
| 54 runReflectiveTests(SubtypeManagerTest); | 55 runReflectiveTests(SubtypeManagerTest); |
| 55 runReflectiveTests(TypeOverrideManagerTest); | 56 runReflectiveTests(TypeOverrideManagerTest); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 102 |
| 102 /** | 103 /** |
| 103 * Initialize the given analysis context with a fake core library already reso
lved. | 104 * Initialize the given analysis context with a fake core library already reso
lved. |
| 104 * | 105 * |
| 105 * @param context the context to be initialized (not `null`) | 106 * @param context the context to be initialized (not `null`) |
| 106 * @return the analysis context that was created | 107 * @return the analysis context that was created |
| 107 */ | 108 */ |
| 108 static InternalAnalysisContext initContextWithCore( | 109 static InternalAnalysisContext initContextWithCore( |
| 109 InternalAnalysisContext context) { | 110 InternalAnalysisContext context) { |
| 110 DirectoryBasedDartSdk sdk = new _AnalysisContextFactory_initContextWithCore( | 111 DirectoryBasedDartSdk sdk = new _AnalysisContextFactory_initContextWithCore( |
| 111 new JavaFile("/fake/sdk")); | 112 new JavaFile("/fake/sdk"), |
| 113 enableAsync: context.analysisOptions.enableAsync); |
| 112 SourceFactory sourceFactory = | 114 SourceFactory sourceFactory = |
| 113 new SourceFactory([new DartUriResolver(sdk), new FileUriResolver()]); | 115 new SourceFactory([new DartUriResolver(sdk), new FileUriResolver()]); |
| 114 context.sourceFactory = sourceFactory; | 116 context.sourceFactory = sourceFactory; |
| 115 AnalysisContext coreContext = sdk.context; | 117 AnalysisContext coreContext = sdk.context; |
| 116 // | 118 // |
| 117 // dart:core | 119 // dart:core |
| 118 // | 120 // |
| 119 TestTypeProvider provider = new TestTypeProvider(); | 121 TestTypeProvider provider = new TestTypeProvider(); |
| 120 CompilationUnitElementImpl coreUnit = | 122 CompilationUnitElementImpl coreUnit = |
| 121 new CompilationUnitElementImpl("core.dart"); | 123 new CompilationUnitElementImpl("core.dart"); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 coreUnit.topLevelVariables = <TopLevelVariableElement>[ | 172 coreUnit.topLevelVariables = <TopLevelVariableElement>[ |
| 171 proxyTopLevelVariableElt, | 173 proxyTopLevelVariableElt, |
| 172 deprecatedTopLevelVariableElt | 174 deprecatedTopLevelVariableElt |
| 173 ]; | 175 ]; |
| 174 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( | 176 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( |
| 175 coreContext, AstFactory.libraryIdentifier2(["dart", "core"])); | 177 coreContext, AstFactory.libraryIdentifier2(["dart", "core"])); |
| 176 coreLibrary.definingCompilationUnit = coreUnit; | 178 coreLibrary.definingCompilationUnit = coreUnit; |
| 177 // | 179 // |
| 178 // dart:async | 180 // dart:async |
| 179 // | 181 // |
| 180 CompilationUnitElementImpl asyncUnit = | 182 Source asyncSource; |
| 181 new CompilationUnitElementImpl("async.dart"); | 183 LibraryElementImpl asyncLibrary; |
| 182 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); | 184 if (context.analysisOptions.enableAsync) { |
| 183 coreContext.setContents(asyncSource, ""); | 185 CompilationUnitElementImpl asyncUnit = |
| 184 asyncUnit.librarySource = asyncUnit.source = asyncSource; | 186 new CompilationUnitElementImpl("async.dart"); |
| 185 // Future | 187 asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); |
| 186 ClassElementImpl futureElement = | 188 coreContext.setContents(asyncSource, ""); |
| 187 ElementFactory.classElement2("Future", ["T"]); | 189 asyncUnit.librarySource = asyncUnit.source = asyncSource; |
| 188 // factory Future.value([value]) | 190 // Future |
| 189 ConstructorElementImpl futureConstructor = | 191 ClassElementImpl futureElement = |
| 190 ElementFactory.constructorElement2(futureElement, "value"); | 192 ElementFactory.classElement2("Future", ["T"]); |
| 191 futureConstructor.parameters = <ParameterElement>[ | 193 // factory Future.value([value]) |
| 192 ElementFactory.positionalParameter2("value", provider.dynamicType) | 194 ConstructorElementImpl futureConstructor = |
| 193 ]; | 195 ElementFactory.constructorElement2(futureElement, "value"); |
| 194 futureConstructor.factory = true; | 196 futureConstructor.parameters = <ParameterElement>[ |
| 195 futureElement.constructors = <ConstructorElement>[futureConstructor]; | 197 ElementFactory.positionalParameter2("value", provider.dynamicType) |
| 196 // Future then(onValue(T value), { Function onError }); | 198 ]; |
| 197 TypeDefiningElement futureThenR = DynamicElementImpl.instance; | 199 futureConstructor.factory = true; |
| 198 if (context.analysisOptions.strongMode) { | 200 futureElement.constructors = <ConstructorElement>[futureConstructor]; |
| 199 futureThenR = ElementFactory.typeParameterWithType('R'); | 201 // Future then(onValue(T value), { Function onError }); |
| 202 TypeDefiningElement futureThenR = DynamicElementImpl.instance; |
| 203 if (context.analysisOptions.strongMode) { |
| 204 futureThenR = ElementFactory.typeParameterWithType('R'); |
| 205 } |
| 206 FunctionElementImpl thenOnValue = ElementFactory.functionElement3( |
| 207 'onValue', futureThenR, [futureElement.typeParameters[0]], null); |
| 208 |
| 209 DartType futureRType = futureElement.type.substitute4([futureThenR.type]); |
| 210 MethodElementImpl thenMethod = ElementFactory |
| 211 .methodElementWithParameters(futureElement, "then", futureRType, [ |
| 212 ElementFactory.requiredParameter2("onValue", thenOnValue.type), |
| 213 ElementFactory.namedParameter2("onError", provider.functionType) |
| 214 ]); |
| 215 if (!futureThenR.type.isDynamic) { |
| 216 thenMethod.typeParameters = [futureThenR]; |
| 217 } |
| 218 thenOnValue.enclosingElement = thenMethod; |
| 219 thenOnValue.type = new FunctionTypeImpl(thenOnValue); |
| 220 (thenMethod.parameters[0] as ParameterElementImpl).type = |
| 221 thenOnValue.type; |
| 222 thenMethod.type = new FunctionTypeImpl(thenMethod); |
| 223 |
| 224 futureElement.methods = <MethodElement>[thenMethod]; |
| 225 // Completer |
| 226 ClassElementImpl completerElement = |
| 227 ElementFactory.classElement2("Completer", ["T"]); |
| 228 ConstructorElementImpl completerConstructor = |
| 229 ElementFactory.constructorElement2(completerElement, null); |
| 230 completerElement.constructors = <ConstructorElement>[ |
| 231 completerConstructor |
| 232 ]; |
| 233 // StreamSubscription |
| 234 ClassElementImpl streamSubscriptionElement = |
| 235 ElementFactory.classElement2("StreamSubscription", ["T"]); |
| 236 // Stream |
| 237 ClassElementImpl streamElement = |
| 238 ElementFactory.classElement2("Stream", ["T"]); |
| 239 streamElement.constructors = <ConstructorElement>[ |
| 240 ElementFactory.constructorElement2(streamElement, null) |
| 241 ]; |
| 242 DartType returnType = streamSubscriptionElement.type |
| 243 .substitute4(streamElement.type.typeArguments); |
| 244 List<DartType> parameterTypes = <DartType>[ |
| 245 ElementFactory |
| 246 .functionElement3('onData', VoidTypeImpl.instance.element, |
| 247 <TypeDefiningElement>[streamElement.typeParameters[0]], null) |
| 248 .type, |
| 249 ]; |
| 250 // TODO(brianwilkerson) This is missing the optional parameters. |
| 251 MethodElementImpl listenMethod = |
| 252 ElementFactory.methodElement('listen', returnType, parameterTypes); |
| 253 streamElement.methods = <MethodElement>[listenMethod]; |
| 254 listenMethod.type = new FunctionTypeImpl(listenMethod); |
| 255 |
| 256 FunctionElementImpl listenParamFunction = parameterTypes[0].element; |
| 257 listenParamFunction.enclosingElement = listenMethod; |
| 258 listenParamFunction.type = new FunctionTypeImpl(listenParamFunction); |
| 259 ParameterElementImpl listenParam = listenMethod.parameters[0]; |
| 260 listenParam.type = listenParamFunction.type; |
| 261 |
| 262 asyncUnit.types = <ClassElement>[ |
| 263 completerElement, |
| 264 futureElement, |
| 265 streamElement, |
| 266 streamSubscriptionElement |
| 267 ]; |
| 268 asyncLibrary = new LibraryElementImpl.forNode( |
| 269 coreContext, AstFactory.libraryIdentifier2(["dart", "async"])); |
| 270 asyncLibrary.definingCompilationUnit = asyncUnit; |
| 200 } | 271 } |
| 201 FunctionElementImpl thenOnValue = ElementFactory.functionElement3( | |
| 202 'onValue', futureThenR, [futureElement.typeParameters[0]], null); | |
| 203 | |
| 204 DartType futureRType = futureElement.type.substitute4([futureThenR.type]); | |
| 205 MethodElementImpl thenMethod = ElementFactory | |
| 206 .methodElementWithParameters(futureElement, "then", futureRType, [ | |
| 207 ElementFactory.requiredParameter2("onValue", thenOnValue.type), | |
| 208 ElementFactory.namedParameter2("onError", provider.functionType) | |
| 209 ]); | |
| 210 if (!futureThenR.type.isDynamic) { | |
| 211 thenMethod.typeParameters = [futureThenR]; | |
| 212 } | |
| 213 thenOnValue.enclosingElement = thenMethod; | |
| 214 thenOnValue.type = new FunctionTypeImpl(thenOnValue); | |
| 215 (thenMethod.parameters[0] as ParameterElementImpl).type = thenOnValue.type; | |
| 216 thenMethod.type = new FunctionTypeImpl(thenMethod); | |
| 217 | |
| 218 futureElement.methods = <MethodElement>[thenMethod]; | |
| 219 // Completer | |
| 220 ClassElementImpl completerElement = | |
| 221 ElementFactory.classElement2("Completer", ["T"]); | |
| 222 ConstructorElementImpl completerConstructor = | |
| 223 ElementFactory.constructorElement2(completerElement, null); | |
| 224 completerElement.constructors = <ConstructorElement>[completerConstructor]; | |
| 225 // StreamSubscription | |
| 226 ClassElementImpl streamSubscriptionElement = | |
| 227 ElementFactory.classElement2("StreamSubscription", ["T"]); | |
| 228 // Stream | |
| 229 ClassElementImpl streamElement = | |
| 230 ElementFactory.classElement2("Stream", ["T"]); | |
| 231 streamElement.constructors = <ConstructorElement>[ | |
| 232 ElementFactory.constructorElement2(streamElement, null) | |
| 233 ]; | |
| 234 DartType returnType = streamSubscriptionElement.type | |
| 235 .substitute4(streamElement.type.typeArguments); | |
| 236 List<DartType> parameterTypes = <DartType>[ | |
| 237 ElementFactory | |
| 238 .functionElement3('onData', VoidTypeImpl.instance.element, | |
| 239 <TypeDefiningElement>[streamElement.typeParameters[0]], null) | |
| 240 .type, | |
| 241 ]; | |
| 242 // TODO(brianwilkerson) This is missing the optional parameters. | |
| 243 MethodElementImpl listenMethod = | |
| 244 ElementFactory.methodElement('listen', returnType, parameterTypes); | |
| 245 streamElement.methods = <MethodElement>[listenMethod]; | |
| 246 listenMethod.type = new FunctionTypeImpl(listenMethod); | |
| 247 | |
| 248 FunctionElementImpl listenParamFunction = parameterTypes[0].element; | |
| 249 listenParamFunction.enclosingElement = listenMethod; | |
| 250 listenParamFunction.type = new FunctionTypeImpl(listenParamFunction); | |
| 251 ParameterElementImpl listenParam = listenMethod.parameters[0]; | |
| 252 listenParam.type = listenParamFunction.type; | |
| 253 | |
| 254 asyncUnit.types = <ClassElement>[ | |
| 255 completerElement, | |
| 256 futureElement, | |
| 257 streamElement, | |
| 258 streamSubscriptionElement | |
| 259 ]; | |
| 260 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( | |
| 261 coreContext, AstFactory.libraryIdentifier2(["dart", "async"])); | |
| 262 asyncLibrary.definingCompilationUnit = asyncUnit; | |
| 263 // | 272 // |
| 264 // dart:html | 273 // dart:html |
| 265 // | 274 // |
| 266 CompilationUnitElementImpl htmlUnit = | 275 CompilationUnitElementImpl htmlUnit = |
| 267 new CompilationUnitElementImpl("html_dartium.dart"); | 276 new CompilationUnitElementImpl("html_dartium.dart"); |
| 268 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); | 277 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); |
| 269 coreContext.setContents(htmlSource, ""); | 278 coreContext.setContents(htmlSource, ""); |
| 270 htmlUnit.librarySource = htmlUnit.source = htmlSource; | 279 htmlUnit.librarySource = htmlUnit.source = htmlSource; |
| 271 ClassElementImpl elementElement = ElementFactory.classElement2("Element"); | 280 ClassElementImpl elementElement = ElementFactory.classElement2("Element"); |
| 272 InterfaceType elementType = elementElement.type; | 281 InterfaceType elementType = elementElement.type; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 Source source = sourceFactory.forUri(_DART_INTERCEPTORS); | 397 Source source = sourceFactory.forUri(_DART_INTERCEPTORS); |
| 389 coreContext.setContents(source, ""); | 398 coreContext.setContents(source, ""); |
| 390 source = sourceFactory.forUri(_DART_JS_HELPER); | 399 source = sourceFactory.forUri(_DART_JS_HELPER); |
| 391 coreContext.setContents(source, ""); | 400 coreContext.setContents(source, ""); |
| 392 // | 401 // |
| 393 // Record the elements. | 402 // Record the elements. |
| 394 // | 403 // |
| 395 HashMap<Source, LibraryElement> elementMap = | 404 HashMap<Source, LibraryElement> elementMap = |
| 396 new HashMap<Source, LibraryElement>(); | 405 new HashMap<Source, LibraryElement>(); |
| 397 elementMap[coreSource] = coreLibrary; | 406 elementMap[coreSource] = coreLibrary; |
| 398 elementMap[asyncSource] = asyncLibrary; | 407 if (asyncSource != null) { |
| 408 elementMap[asyncSource] = asyncLibrary; |
| 409 } |
| 399 elementMap[htmlSource] = htmlLibrary; | 410 elementMap[htmlSource] = htmlLibrary; |
| 400 elementMap[mathSource] = mathLibrary; | 411 elementMap[mathSource] = mathLibrary; |
| 401 // | 412 // |
| 402 // Set the public and export namespaces. We don't use exports in the fake | 413 // Set the public and export namespaces. We don't use exports in the fake |
| 403 // core library so public and export namespaces are the same. | 414 // core library so public and export namespaces are the same. |
| 404 // | 415 // |
| 405 for (LibraryElementImpl library in elementMap.values) { | 416 for (LibraryElementImpl library in elementMap.values) { |
| 406 library.exportNamespace = | 417 library.exportNamespace = |
| 407 library.publicNamespace = new PublicNamespaceBuilder().build(library); | 418 library.publicNamespace = new PublicNamespaceBuilder().build(library); |
| 408 } | 419 } |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 computeLibrarySourceErrors(source); | 1214 computeLibrarySourceErrors(source); |
| 1204 assertErrors(source, [ | 1215 assertErrors(source, [ |
| 1205 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, | 1216 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, |
| 1206 StaticWarningCode.UNDEFINED_CLASS | 1217 StaticWarningCode.UNDEFINED_CLASS |
| 1207 ]); | 1218 ]); |
| 1208 verify([source]); | 1219 verify([source]); |
| 1209 } | 1220 } |
| 1210 } | 1221 } |
| 1211 | 1222 |
| 1212 @reflectiveTest | 1223 @reflectiveTest |
| 1224 class DisableAsyncTestCase extends ResolverTestCase { |
| 1225 @override |
| 1226 void setUp() { |
| 1227 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 1228 options.enableAsync = false; |
| 1229 resetWithOptions(options); |
| 1230 } |
| 1231 |
| 1232 void test_resolve() { |
| 1233 Source source = addSource(r''' |
| 1234 class C { |
| 1235 foo() { |
| 1236 bar(); |
| 1237 } |
| 1238 bar() { |
| 1239 // |
| 1240 } |
| 1241 }'''); |
| 1242 computeLibrarySourceErrors(source); |
| 1243 assertErrors(source, []); |
| 1244 } |
| 1245 |
| 1246 void test_resolve_async() { |
| 1247 Source source = addSource(r''' |
| 1248 class C { |
| 1249 Future foo() async { |
| 1250 await bar(); |
| 1251 return null; |
| 1252 } |
| 1253 Future bar() { |
| 1254 return new Future.delayed(new Duration(milliseconds: 10)); |
| 1255 } |
| 1256 }'''); |
| 1257 computeLibrarySourceErrors(source); |
| 1258 assertErrors(source, [ |
| 1259 StaticWarningCode.UNDEFINED_CLASS, |
| 1260 StaticWarningCode.UNDEFINED_CLASS, |
| 1261 StaticWarningCode.UNDEFINED_CLASS, |
| 1262 StaticWarningCode.UNDEFINED_CLASS, |
| 1263 ParserErrorCode.ASYNC_NOT_SUPPORTED |
| 1264 ]); |
| 1265 } |
| 1266 } |
| 1267 |
| 1268 @reflectiveTest |
| 1213 class ElementResolverTest extends EngineTestCase { | 1269 class ElementResolverTest extends EngineTestCase { |
| 1214 /** | 1270 /** |
| 1215 * The error listener to which errors will be reported. | 1271 * The error listener to which errors will be reported. |
| 1216 */ | 1272 */ |
| 1217 GatheringErrorListener _listener; | 1273 GatheringErrorListener _listener; |
| 1218 | 1274 |
| 1219 /** | 1275 /** |
| 1220 * The type provider used to access the types. | 1276 * The type provider used to access the types. |
| 1221 */ | 1277 */ |
| 1222 TestTypeProvider _typeProvider; | 1278 TestTypeProvider _typeProvider; |
| (...skipping 12376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13599 class B extends A {} | 13655 class B extends A {} |
| 13600 class C { | 13656 class C { |
| 13601 /*=T*/ f/*<T extends A>*/(/*=T*/ x) => null; | 13657 /*=T*/ f/*<T extends A>*/(/*=T*/ x) => null; |
| 13602 } | 13658 } |
| 13603 class D extends C { | 13659 class D extends C { |
| 13604 /*=T*/ f/*<T extends B>*/(/*=T*/ x) => null; | 13660 /*=T*/ f/*<T extends B>*/(/*=T*/ x) => null; |
| 13605 }'''); | 13661 }'''); |
| 13606 // TODO(jmesserly): this is modified code from assertErrors, which we can't | 13662 // TODO(jmesserly): this is modified code from assertErrors, which we can't |
| 13607 // use directly because STRONG_MODE_* errors don't have working equality. | 13663 // use directly because STRONG_MODE_* errors don't have working equality. |
| 13608 List<AnalysisError> errors = analysisContext2.computeErrors(source); | 13664 List<AnalysisError> errors = analysisContext2.computeErrors(source); |
| 13609 expect(errors.map((e) => e.errorCode.name), [ | 13665 List errorNames = errors.map((e) => e.errorCode.name).toList(); |
| 13610 'STRONG_MODE_INVALID_METHOD_OVERRIDE', | 13666 expect(errorNames, hasLength(2)); |
| 13611 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND' | 13667 expect(errorNames, contains('STRONG_MODE_INVALID_METHOD_OVERRIDE')); |
| 13612 ]); | 13668 expect( |
| 13669 errorNames, contains('INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND')); |
| 13613 verify([source]); | 13670 verify([source]); |
| 13614 } | 13671 } |
| 13615 | 13672 |
| 13616 void test_genericMethod_override_invalidTypeParamCount() { | 13673 void test_genericMethod_override_invalidTypeParamCount() { |
| 13617 Source source = addSource(r''' | 13674 Source source = addSource(r''' |
| 13618 class C { | 13675 class C { |
| 13619 /*=T*/ f/*<T>*/(/*=T*/ x) => null; | 13676 /*=T*/ f/*<T>*/(/*=T*/ x) => null; |
| 13620 } | 13677 } |
| 13621 class D extends C { | 13678 class D extends C { |
| 13622 /*=S*/ f/*<T, S>*/(/*=T*/ x) => null; | 13679 /*=S*/ f/*<T, S>*/(/*=T*/ x) => null; |
| (...skipping 2389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16012 expect(provider.bottomType, isNotNull); | 16069 expect(provider.bottomType, isNotNull); |
| 16013 expect(provider.doubleType, same(doubleType)); | 16070 expect(provider.doubleType, same(doubleType)); |
| 16014 expect(provider.dynamicType, isNotNull); | 16071 expect(provider.dynamicType, isNotNull); |
| 16015 expect(provider.functionType, same(functionType)); | 16072 expect(provider.functionType, same(functionType)); |
| 16016 expect(provider.futureType, same(futureType)); | 16073 expect(provider.futureType, same(futureType)); |
| 16017 expect(provider.intType, same(intType)); | 16074 expect(provider.intType, same(intType)); |
| 16018 expect(provider.listType, same(listType)); | 16075 expect(provider.listType, same(listType)); |
| 16019 expect(provider.mapType, same(mapType)); | 16076 expect(provider.mapType, same(mapType)); |
| 16020 expect(provider.objectType, same(objectType)); | 16077 expect(provider.objectType, same(objectType)); |
| 16021 expect(provider.stackTraceType, same(stackTraceType)); | 16078 expect(provider.stackTraceType, same(stackTraceType)); |
| 16079 expect(provider.streamType, same(streamType)); |
| 16080 expect(provider.stringType, same(stringType)); |
| 16081 expect(provider.symbolType, same(symbolType)); |
| 16082 expect(provider.typeType, same(typeType)); |
| 16083 } |
| 16084 |
| 16085 void test_creation_no_async() { |
| 16086 // |
| 16087 // Create a mock library element with the types expected to be in dart:core. |
| 16088 // We cannot use either ElementFactory or TestTypeProvider (which uses |
| 16089 // ElementFactory) because we side-effect the elements in ways that would |
| 16090 // break other tests. |
| 16091 // |
| 16092 InterfaceType objectType = _classElement("Object", null).type; |
| 16093 InterfaceType boolType = _classElement("bool", objectType).type; |
| 16094 InterfaceType numType = _classElement("num", objectType).type; |
| 16095 InterfaceType doubleType = _classElement("double", numType).type; |
| 16096 InterfaceType functionType = _classElement("Function", objectType).type; |
| 16097 InterfaceType intType = _classElement("int", numType).type; |
| 16098 InterfaceType iterableType = |
| 16099 _classElement("Iterable", objectType, ["T"]).type; |
| 16100 InterfaceType listType = _classElement("List", objectType, ["E"]).type; |
| 16101 InterfaceType mapType = _classElement("Map", objectType, ["K", "V"]).type; |
| 16102 InterfaceType stackTraceType = _classElement("StackTrace", objectType).type; |
| 16103 InterfaceType stringType = _classElement("String", objectType).type; |
| 16104 InterfaceType symbolType = _classElement("Symbol", objectType).type; |
| 16105 InterfaceType typeType = _classElement("Type", objectType).type; |
| 16106 CompilationUnitElementImpl coreUnit = |
| 16107 new CompilationUnitElementImpl("core.dart"); |
| 16108 coreUnit.types = <ClassElement>[ |
| 16109 boolType.element, |
| 16110 doubleType.element, |
| 16111 functionType.element, |
| 16112 intType.element, |
| 16113 iterableType.element, |
| 16114 listType.element, |
| 16115 mapType.element, |
| 16116 objectType.element, |
| 16117 stackTraceType.element, |
| 16118 stringType.element, |
| 16119 symbolType.element, |
| 16120 typeType.element |
| 16121 ]; |
| 16122 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
| 16123 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( |
| 16124 context, AstFactory.libraryIdentifier2(["dart.core"])); |
| 16125 coreLibrary.definingCompilationUnit = coreUnit; |
| 16126 |
| 16127 LibraryElementImpl mockAsyncLib = |
| 16128 (context as AnalysisContextImpl).createMockAsyncLib(coreLibrary); |
| 16129 expect(mockAsyncLib.publicNamespace, isNotNull); |
| 16130 |
| 16131 // |
| 16132 // Create a type provider and ensure that it can return the expected types. |
| 16133 // |
| 16134 TypeProviderImpl provider = new TypeProviderImpl(coreLibrary, mockAsyncLib); |
| 16135 expect(provider.boolType, same(boolType)); |
| 16136 expect(provider.bottomType, isNotNull); |
| 16137 expect(provider.doubleType, same(doubleType)); |
| 16138 expect(provider.dynamicType, isNotNull); |
| 16139 expect(provider.functionType, same(functionType)); |
| 16140 InterfaceType mockFutureType = mockAsyncLib.getType('Future').type; |
| 16141 expect(provider.futureType, same(mockFutureType)); |
| 16142 expect(provider.intType, same(intType)); |
| 16143 expect(provider.listType, same(listType)); |
| 16144 expect(provider.mapType, same(mapType)); |
| 16145 expect(provider.objectType, same(objectType)); |
| 16146 expect(provider.stackTraceType, same(stackTraceType)); |
| 16022 expect(provider.stringType, same(stringType)); | 16147 expect(provider.stringType, same(stringType)); |
| 16023 expect(provider.symbolType, same(symbolType)); | 16148 expect(provider.symbolType, same(symbolType)); |
| 16149 InterfaceType mockStreamType = mockAsyncLib.getType('Stream').type; |
| 16150 expect(provider.streamType, same(mockStreamType)); |
| 16024 expect(provider.typeType, same(typeType)); | 16151 expect(provider.typeType, same(typeType)); |
| 16025 } | 16152 } |
| 16026 | 16153 |
| 16027 ClassElement _classElement(String typeName, InterfaceType superclassType, | 16154 ClassElement _classElement(String typeName, InterfaceType superclassType, |
| 16028 [List<String> parameterNames]) { | 16155 [List<String> parameterNames]) { |
| 16029 ClassElementImpl element = | 16156 ClassElementImpl element = |
| 16030 new ClassElementImpl.forNode(AstFactory.identifier3(typeName)); | 16157 new ClassElementImpl.forNode(AstFactory.identifier3(typeName)); |
| 16031 element.supertype = superclassType; | 16158 element.supertype = superclassType; |
| 16032 InterfaceTypeImpl type = new InterfaceTypeImpl(element); | 16159 InterfaceTypeImpl type = new InterfaceTypeImpl(element); |
| 16033 element.type = type; | 16160 element.type = type; |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16671 for (Element element in definedElements) { | 16798 for (Element element in definedElements) { |
| 16672 libraryScope.define(element); | 16799 libraryScope.define(element); |
| 16673 } | 16800 } |
| 16674 } | 16801 } |
| 16675 node.accept(_visitor); | 16802 node.accept(_visitor); |
| 16676 } | 16803 } |
| 16677 } | 16804 } |
| 16678 | 16805 |
| 16679 class _AnalysisContextFactory_initContextWithCore | 16806 class _AnalysisContextFactory_initContextWithCore |
| 16680 extends DirectoryBasedDartSdk { | 16807 extends DirectoryBasedDartSdk { |
| 16681 _AnalysisContextFactory_initContextWithCore(JavaFile arg0) : super(arg0); | 16808 final bool enableAsync; |
| 16809 _AnalysisContextFactory_initContextWithCore(JavaFile arg0, |
| 16810 {this.enableAsync: true}) |
| 16811 : super(arg0); |
| 16682 | 16812 |
| 16683 @override | 16813 @override |
| 16684 LibraryMap initialLibraryMap(bool useDart2jsPaths) { | 16814 LibraryMap initialLibraryMap(bool useDart2jsPaths) { |
| 16685 LibraryMap map = new LibraryMap(); | 16815 LibraryMap map = new LibraryMap(); |
| 16686 _addLibrary(map, DartSdk.DART_ASYNC, false, "async.dart"); | 16816 if (enableAsync) { |
| 16817 _addLibrary(map, DartSdk.DART_ASYNC, false, "async.dart"); |
| 16818 } |
| 16687 _addLibrary(map, DartSdk.DART_CORE, false, "core.dart"); | 16819 _addLibrary(map, DartSdk.DART_CORE, false, "core.dart"); |
| 16688 _addLibrary(map, DartSdk.DART_HTML, false, "html_dartium.dart"); | 16820 _addLibrary(map, DartSdk.DART_HTML, false, "html_dartium.dart"); |
| 16689 _addLibrary(map, AnalysisContextFactory._DART_MATH, false, "math.dart"); | 16821 _addLibrary(map, AnalysisContextFactory._DART_MATH, false, "math.dart"); |
| 16690 _addLibrary(map, AnalysisContextFactory._DART_INTERCEPTORS, true, | 16822 _addLibrary(map, AnalysisContextFactory._DART_INTERCEPTORS, true, |
| 16691 "_interceptors.dart"); | 16823 "_interceptors.dart"); |
| 16692 _addLibrary( | 16824 _addLibrary( |
| 16693 map, AnalysisContextFactory._DART_JS_HELPER, true, "_js_helper.dart"); | 16825 map, AnalysisContextFactory._DART_JS_HELPER, true, "_js_helper.dart"); |
| 16694 return map; | 16826 return map; |
| 16695 } | 16827 } |
| 16696 | 16828 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16752 | 16884 |
| 16753 void _resolveTestUnit(String code) { | 16885 void _resolveTestUnit(String code) { |
| 16754 testCode = code; | 16886 testCode = code; |
| 16755 testSource = addSource(testCode); | 16887 testSource = addSource(testCode); |
| 16756 LibraryElement library = resolve2(testSource); | 16888 LibraryElement library = resolve2(testSource); |
| 16757 assertNoErrors(testSource); | 16889 assertNoErrors(testSource); |
| 16758 verify([testSource]); | 16890 verify([testSource]); |
| 16759 testUnit = resolveCompilationUnit(testSource, library); | 16891 testUnit = resolveCompilationUnit(testSource, library); |
| 16760 } | 16892 } |
| 16761 } | 16893 } |
| OLD | NEW |