| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.generated.analysis_context_factory; | 5 library analyzer.test.generated.analysis_context_factory; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 new CompilationUnitElementImpl("async.dart"); | 188 new CompilationUnitElementImpl("async.dart"); |
| 189 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); | 189 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); |
| 190 coreContext.setContents(asyncSource, ""); | 190 coreContext.setContents(asyncSource, ""); |
| 191 asyncUnit.librarySource = asyncUnit.source = asyncSource; | 191 asyncUnit.librarySource = asyncUnit.source = asyncSource; |
| 192 asyncLibrary.definingCompilationUnit = asyncUnit; | 192 asyncLibrary.definingCompilationUnit = asyncUnit; |
| 193 // Future<T> | 193 // Future<T> |
| 194 ClassElementImpl futureElement = | 194 ClassElementImpl futureElement = |
| 195 ElementFactory.classElement2("Future", ["T"]); | 195 ElementFactory.classElement2("Future", ["T"]); |
| 196 // FutureOr<T> | 196 // FutureOr<T> |
| 197 ClassElementImpl futureOrElement = | 197 ClassElementImpl futureOrElement = |
| 198 ElementFactory.classElement2("FutureOr", ["T"]); | 198 ElementFactory.classElement2("FutureOr", ["T"]); |
| 199 futureElement.enclosingElement = asyncUnit; | 199 futureElement.enclosingElement = asyncUnit; |
| 200 // factory Future.value([value]) | 200 // factory Future.value([value]) |
| 201 ConstructorElementImpl futureConstructor = | 201 ConstructorElementImpl futureConstructor = |
| 202 ElementFactory.constructorElement2(futureElement, "value"); | 202 ElementFactory.constructorElement2(futureElement, "value"); |
| 203 futureConstructor.parameters = <ParameterElement>[ | 203 futureConstructor.parameters = <ParameterElement>[ |
| 204 ElementFactory.positionalParameter2("value", provider.dynamicType) | 204 ElementFactory.positionalParameter2("value", provider.dynamicType) |
| 205 ]; | 205 ]; |
| 206 futureConstructor.factory = true; | 206 futureConstructor.factory = true; |
| 207 futureElement.constructors = <ConstructorElement>[futureConstructor]; | 207 futureElement.constructors = <ConstructorElement>[futureConstructor]; |
| 208 // Future<R> then<R>(FutureOr<R> onValue(T value), { Function onError }); | 208 // Future<R> then<R>(FutureOr<R> onValue(T value), { Function onError }); |
| 209 TypeDefiningElement futureThenR = DynamicElementImpl.instance; | 209 TypeDefiningElement futureThenR = DynamicElementImpl.instance; |
| 210 DartType onValueReturnType = DynamicTypeImpl.instance; | 210 DartType onValueReturnType = DynamicTypeImpl.instance; |
| 211 if (context.analysisOptions.strongMode) { | 211 if (context.analysisOptions.strongMode) { |
| 212 futureThenR = ElementFactory.typeParameterWithType('R'); | 212 futureThenR = ElementFactory.typeParameterWithType('R'); |
| 213 onValueReturnType = futureOrElement.type.instantiate([futureThenR.type]); | 213 onValueReturnType = futureOrElement.type.instantiate([futureThenR.type]); |
| 214 } | 214 } |
| 215 FunctionElementImpl thenOnValue = ElementFactory.functionElement3('onValue', | 215 FunctionElementImpl thenOnValue = ElementFactory.functionElement3( |
| 216 onValueReturnType, [futureElement.typeParameters[0]], null); | 216 'onValue', onValueReturnType, [futureElement.typeParameters[0]], null); |
| 217 thenOnValue.isSynthetic = true; | 217 thenOnValue.isSynthetic = true; |
| 218 | 218 |
| 219 DartType futureRType = futureElement.type.instantiate([futureThenR.type]); | 219 DartType futureRType = futureElement.type.instantiate([futureThenR.type]); |
| 220 MethodElementImpl thenMethod = ElementFactory | 220 MethodElementImpl thenMethod = ElementFactory |
| 221 .methodElementWithParameters(futureElement, "then", futureRType, [ | 221 .methodElementWithParameters(futureElement, "then", futureRType, [ |
| 222 ElementFactory.requiredParameter2("onValue", thenOnValue.type), | 222 ElementFactory.requiredParameter2("onValue", thenOnValue.type), |
| 223 ElementFactory.namedParameter2("onError", provider.functionType) | 223 ElementFactory.namedParameter2("onError", provider.functionType) |
| 224 ]); | 224 ]); |
| 225 if (!futureThenR.type.isDynamic) { | 225 if (!futureThenR.type.isDynamic) { |
| 226 thenMethod.typeParameters = <TypeParameterElement>[futureThenR]; | 226 thenMethod.typeParameters = <TypeParameterElement>[futureThenR]; |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 | 578 |
| 579 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) { | 579 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) { |
| 580 SdkLibraryImpl library = new SdkLibraryImpl(uri); | 580 SdkLibraryImpl library = new SdkLibraryImpl(uri); |
| 581 if (isInternal) { | 581 if (isInternal) { |
| 582 library.category = "Internal"; | 582 library.category = "Internal"; |
| 583 } | 583 } |
| 584 library.path = path; | 584 library.path = path; |
| 585 map.setLibrary(uri, library); | 585 map.setLibrary(uri, library); |
| 586 } | 586 } |
| 587 } | 587 } |
| OLD | NEW |