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 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' as newContext; |
10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 futureConstructor.parameters = <ParameterElement>[ | 200 futureConstructor.parameters = <ParameterElement>[ |
201 ElementFactory.positionalParameter2("value", provider.dynamicType) | 201 ElementFactory.positionalParameter2("value", provider.dynamicType) |
202 ]; | 202 ]; |
203 futureConstructor.factory = true; | 203 futureConstructor.factory = true; |
204 futureElement.constructors = <ConstructorElement>[futureConstructor]; | 204 futureElement.constructors = <ConstructorElement>[futureConstructor]; |
205 // Future then(onValue(T value), { Function onError }); | 205 // Future then(onValue(T value), { Function onError }); |
206 List<ParameterElement> parameters = <ParameterElement>[ | 206 List<ParameterElement> parameters = <ParameterElement>[ |
207 ElementFactory.requiredParameter2( | 207 ElementFactory.requiredParameter2( |
208 "value", futureElement.typeParameters[0].type) | 208 "value", futureElement.typeParameters[0].type) |
209 ]; | 209 ]; |
210 FunctionElementImpl onValueFunction = new FunctionElementImpl.forNode(null); | 210 FunctionTypeAliasElementImpl aliasElement = |
211 onValueFunction.synthetic = true; | 211 new FunctionTypeAliasElementImpl.forNode(null); |
212 onValueFunction.parameters = parameters; | 212 aliasElement.synthetic = true; |
213 onValueFunction.returnType = provider.dynamicType; | 213 aliasElement.parameters = parameters; |
214 onValueFunction.enclosingElement = futureElement; | 214 aliasElement.returnType = provider.dynamicType; |
215 onValueFunction.type = new FunctionTypeImpl(onValueFunction); | 215 aliasElement.enclosingElement = asyncUnit; |
| 216 aliasElement.shareTypeParameters(futureElement.typeParameters); |
| 217 FunctionTypeImpl aliasType = new FunctionTypeImpl.forTypedef(aliasElement); |
| 218 aliasElement.type = aliasType; |
216 DartType futureDynamicType = | 219 DartType futureDynamicType = |
217 futureElement.type.substitute4([provider.dynamicType]); | 220 futureElement.type.substitute4([provider.dynamicType]); |
218 MethodElement thenMethod = ElementFactory.methodElementWithParameters( | 221 MethodElement thenMethod = ElementFactory.methodElementWithParameters( |
219 futureElement, "then", futureDynamicType, [ | 222 futureElement, "then", futureDynamicType, [ |
220 ElementFactory.requiredParameter2("onValue", onValueFunction.type), | 223 ElementFactory.requiredParameter2("onValue", aliasType), |
221 ElementFactory.namedParameter2("onError", provider.functionType) | 224 ElementFactory.namedParameter2("onError", provider.functionType) |
222 ]); | 225 ]); |
223 futureElement.methods = <MethodElement>[thenMethod]; | 226 futureElement.methods = <MethodElement>[thenMethod]; |
224 // Completer | 227 // Completer |
225 ClassElementImpl completerElement = | 228 ClassElementImpl completerElement = |
226 ElementFactory.classElement2("Completer", ["T"]); | 229 ElementFactory.classElement2("Completer", ["T"]); |
227 ConstructorElementImpl completerConstructor = | 230 ConstructorElementImpl completerConstructor = |
228 ElementFactory.constructorElement2(completerElement, null); | 231 ElementFactory.constructorElement2(completerElement, null); |
229 completerElement.constructors = <ConstructorElement>[completerConstructor]; | 232 completerElement.constructors = <ConstructorElement>[completerConstructor]; |
230 // StreamSubscription | 233 // StreamSubscription |
(...skipping 11974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12205 expect(e.type.toString(), '(E) → List<T>'); | 12208 expect(e.type.toString(), '(E) → List<T>'); |
12206 | 12209 |
12207 SimpleIdentifier c = _findIdentifier('cOfString'); | 12210 SimpleIdentifier c = _findIdentifier('cOfString'); |
12208 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; | 12211 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; |
12209 expect(ft.toString(), '(String) → List<T>'); | 12212 expect(ft.toString(), '(String) → List<T>'); |
12210 DartType t = e.typeParameters[0].type; | 12213 DartType t = e.typeParameters[0].type; |
12211 ft = ft.substitute2([typeProvider.intType], [t]); | 12214 ft = ft.substitute2([typeProvider.intType], [t]); |
12212 expect(ft.toString(), '(String) → List<int>'); | 12215 expect(ft.toString(), '(String) → List<int>'); |
12213 } | 12216 } |
12214 | 12217 |
12215 void test_genericMethod_functionTypedParameter() { | |
12216 _resolveTestUnit(r''' | |
12217 class C<E> { | |
12218 List/*<T>*/ f/*<T>*/(/*=T*/ f(E e)) => null; | |
12219 } | |
12220 main() { | |
12221 C<String> cOfString; | |
12222 } | |
12223 '''); | |
12224 SimpleIdentifier f = _findIdentifier('f'); | |
12225 MethodElementImpl e = f.staticElement; | |
12226 expect(e.typeParameters.toString(), '[T]'); | |
12227 expect(e.type.typeParameters.toString(), '[T, E]'); | |
12228 expect(e.type.typeArguments.toString(), '[T, E]'); | |
12229 expect(e.type.toString(), '((E) → T) → List<T>'); | |
12230 | |
12231 SimpleIdentifier c = _findIdentifier('cOfString'); | |
12232 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; | |
12233 expect(ft.toString(), '((String) → T) → List<T>'); | |
12234 DartType t = e.typeParameters[0].type; | |
12235 ft = ft.substitute2([typeProvider.intType], [t]); | |
12236 expect(ft.toString(), '((String) → int) → List<int>'); | |
12237 } | |
12238 | |
12239 void test_pseudoGeneric_max_doubleDouble() { | 12218 void test_pseudoGeneric_max_doubleDouble() { |
12240 String code = r''' | 12219 String code = r''' |
12241 import 'dart:math'; | 12220 import 'dart:math'; |
12242 main() { | 12221 main() { |
12243 var foo = max(1.0, 2.0); | 12222 var foo = max(1.0, 2.0); |
12244 } | 12223 } |
12245 '''; | 12224 '''; |
12246 _resolveTestUnit(code); | 12225 _resolveTestUnit(code); |
12247 | 12226 |
12248 SimpleIdentifier identifier = _findIdentifier('foo'); | 12227 SimpleIdentifier identifier = _findIdentifier('foo'); |
(...skipping 2935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15184 | 15163 |
15185 void _resolveTestUnit(String code) { | 15164 void _resolveTestUnit(String code) { |
15186 testCode = code; | 15165 testCode = code; |
15187 testSource = addSource(testCode); | 15166 testSource = addSource(testCode); |
15188 LibraryElement library = resolve2(testSource); | 15167 LibraryElement library = resolve2(testSource); |
15189 assertNoErrors(testSource); | 15168 assertNoErrors(testSource); |
15190 verify([testSource]); | 15169 verify([testSource]); |
15191 testUnit = resolveCompilationUnit(testSource, library); | 15170 testUnit = resolveCompilationUnit(testSource, library); |
15192 } | 15171 } |
15193 } | 15172 } |
OLD | NEW |