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

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

Issue 1442883003: generic method type parameter inference (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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' as newContext;
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 ElementFactory.classElement2("Future", ["T"]); 196 ElementFactory.classElement2("Future", ["T"]);
197 // factory Future.value([value]) 197 // factory Future.value([value])
198 ConstructorElementImpl futureConstructor = 198 ConstructorElementImpl futureConstructor =
199 ElementFactory.constructorElement2(futureElement, "value"); 199 ElementFactory.constructorElement2(futureElement, "value");
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 TypeDefiningElement futureThenR = DynamicElementImpl.instance;
207 ElementFactory.requiredParameter2( 207 if (context.analysisOptions.strongMode) {
208 "value", futureElement.typeParameters[0].type) 208 futureThenR = ElementFactory.typeParameterWithType('R');
209 ]; 209 }
210 FunctionElementImpl onValueFunction = new FunctionElementImpl.forNode(null); 210 FunctionElementImpl thenOnValue = ElementFactory.functionElement3(
211 onValueFunction.synthetic = true; 211 'onValue', futureThenR, [futureElement.typeParameters[0]], null);
212 onValueFunction.parameters = parameters; 212
213 onValueFunction.returnType = provider.dynamicType; 213 DartType futureRType = futureElement.type.substitute4([futureThenR.type]);
214 onValueFunction.enclosingElement = futureElement; 214 MethodElementImpl thenMethod = ElementFactory.methodElementWithParameters(
215 onValueFunction.type = new FunctionTypeImpl(onValueFunction); 215 futureElement, "then", futureRType, [
216 DartType futureDynamicType = 216 ElementFactory.requiredParameter2("onValue", thenOnValue.type),
217 futureElement.type.substitute4([provider.dynamicType]);
218 MethodElement thenMethod = ElementFactory.methodElementWithParameters(
219 futureElement, "then", futureDynamicType, [
220 ElementFactory.requiredParameter2("onValue", onValueFunction.type),
221 ElementFactory.namedParameter2("onError", provider.functionType) 217 ElementFactory.namedParameter2("onError", provider.functionType)
222 ]); 218 ]);
219 if (!futureThenR.type.isDynamic) {
220 thenMethod.typeParameters = [futureThenR];
221 }
222 thenOnValue.enclosingElement = thenMethod;
223 thenOnValue.type = new FunctionTypeImpl(thenOnValue);
224 (thenMethod.parameters[0] as ParameterElementImpl).type = thenOnValue.type;
225 thenMethod.type = new FunctionTypeImpl(thenMethod);
226
223 futureElement.methods = <MethodElement>[thenMethod]; 227 futureElement.methods = <MethodElement>[thenMethod];
224 // Completer 228 // Completer
225 ClassElementImpl completerElement = 229 ClassElementImpl completerElement =
226 ElementFactory.classElement2("Completer", ["T"]); 230 ElementFactory.classElement2("Completer", ["T"]);
227 ConstructorElementImpl completerConstructor = 231 ConstructorElementImpl completerConstructor =
228 ElementFactory.constructorElement2(completerElement, null); 232 ElementFactory.constructorElement2(completerElement, null);
229 completerElement.constructors = <ConstructorElement>[completerConstructor]; 233 completerElement.constructors = <ConstructorElement>[completerConstructor];
230 // StreamSubscription 234 // StreamSubscription
231 ClassElementImpl streamSubscriptionElement = 235 ClassElementImpl streamSubscriptionElement =
232 ElementFactory.classElement2("StreamSubscription", ["T"]); 236 ElementFactory.classElement2("StreamSubscription", ["T"]);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 Source mathSource = sourceFactory.forUri(_DART_MATH); 337 Source mathSource = sourceFactory.forUri(_DART_MATH);
334 coreContext.setContents(mathSource, ""); 338 coreContext.setContents(mathSource, "");
335 mathUnit.librarySource = mathUnit.source = mathSource; 339 mathUnit.librarySource = mathUnit.source = mathSource;
336 FunctionElement cosElement = ElementFactory.functionElement3( 340 FunctionElement cosElement = ElementFactory.functionElement3(
337 "cos", 341 "cos",
338 provider.doubleType.element, 342 provider.doubleType.element,
339 <ClassElement>[provider.numType.element], 343 <ClassElement>[provider.numType.element],
340 ClassElement.EMPTY_LIST); 344 ClassElement.EMPTY_LIST);
341 TopLevelVariableElement ln10Element = ElementFactory 345 TopLevelVariableElement ln10Element = ElementFactory
342 .topLevelVariableElement3("LN10", true, false, provider.doubleType); 346 .topLevelVariableElement3("LN10", true, false, provider.doubleType);
343 FunctionElement maxElement = ElementFactory.functionElement3( 347 TypeParameterElement maxT =
344 "max", 348 ElementFactory.typeParameterWithType('T', provider.numType);
345 provider.numType.element, 349 FunctionElementImpl maxElement = ElementFactory.functionElement3(
346 <ClassElement>[provider.numType.element, provider.numType.element], 350 "max", maxT, [maxT, maxT], ClassElement.EMPTY_LIST);
347 ClassElement.EMPTY_LIST); 351 maxElement.typeParameters = [maxT];
352 maxElement.type = new FunctionTypeImpl(maxElement);
348 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( 353 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3(
349 "PI", true, false, provider.doubleType); 354 "PI", true, false, provider.doubleType);
350 ClassElementImpl randomElement = ElementFactory.classElement2("Random"); 355 ClassElementImpl randomElement = ElementFactory.classElement2("Random");
351 randomElement.abstract = true; 356 randomElement.abstract = true;
352 ConstructorElementImpl randomConstructor = 357 ConstructorElementImpl randomConstructor =
353 ElementFactory.constructorElement2(randomElement, null); 358 ElementFactory.constructorElement2(randomElement, null);
354 randomConstructor.factory = true; 359 randomConstructor.factory = true;
355 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0); 360 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0);
356 seedParam.parameterKind = ParameterKind.POSITIONAL; 361 seedParam.parameterKind = ParameterKind.POSITIONAL;
357 seedParam.type = provider.intType; 362 seedParam.type = provider.intType;
(...skipping 14835 matching lines...) Expand 10 before | Expand all | Expand 10 after
15193 15198
15194 void _resolveTestUnit(String code) { 15199 void _resolveTestUnit(String code) {
15195 testCode = code; 15200 testCode = code;
15196 testSource = addSource(testCode); 15201 testSource = addSource(testCode);
15197 LibraryElement library = resolve2(testSource); 15202 LibraryElement library = resolve2(testSource);
15198 assertNoErrors(testSource); 15203 assertNoErrors(testSource);
15199 verify([testSource]); 15204 verify([testSource]);
15200 testUnit = resolveCompilationUnit(testSource, library); 15205 testUnit = resolveCompilationUnit(testSource, library);
15201 } 15206 }
15202 } 15207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698