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

Side by Side Diff: pkg/analyzer/lib/src/generated/testing/element_factory.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.testing.element_factory; 5 library engine.testing.element_factory;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/constant.dart'; 10 import 'package:analyzer/src/generated/constant.dart';
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 String typeName, InterfaceType superclassType, 42 String typeName, InterfaceType superclassType,
43 [List<String> parameterNames]) { 43 [List<String> parameterNames]) {
44 ClassElementImpl element = new ClassElementImpl(typeName, 0); 44 ClassElementImpl element = new ClassElementImpl(typeName, 0);
45 element.constructors = const <ConstructorElement>[]; 45 element.constructors = const <ConstructorElement>[];
46 element.supertype = superclassType; 46 element.supertype = superclassType;
47 InterfaceTypeImpl type = new InterfaceTypeImpl(element); 47 InterfaceTypeImpl type = new InterfaceTypeImpl(element);
48 element.type = type; 48 element.type = type;
49 if (parameterNames != null) { 49 if (parameterNames != null) {
50 int count = parameterNames.length; 50 int count = parameterNames.length;
51 if (count > 0) { 51 if (count > 0) {
52 List<TypeParameterElementImpl> typeParameters = 52 element.typeParameters = typeParameters(parameterNames);
53 new List<TypeParameterElementImpl>(count); 53 type.typeArguments = new List<DartType>.from(
54 List<TypeParameterTypeImpl> typeParameterTypes = 54 element.typeParameters.map((p) => p.type),
55 new List<TypeParameterTypeImpl>(count); 55 growable: false);
56 for (int i = 0; i < count; i++) {
57 TypeParameterElementImpl typeParameter =
58 typeParameterElement(parameterNames[i]);
59 typeParameters[i] = typeParameter;
60 typeParameterTypes[i] = new TypeParameterTypeImpl(typeParameter);
61 typeParameter.type = typeParameterTypes[i];
62 }
63 element.typeParameters = typeParameters;
64 type.typeArguments = typeParameterTypes;
65 } 56 }
66 } 57 }
67 return element; 58 return element;
68 } 59 }
69 60
70 static ClassElementImpl classElement2(String typeName, 61 static ClassElementImpl classElement2(String typeName,
71 [List<String> parameterNames]) => 62 [List<String> parameterNames]) =>
72 classElement(typeName, objectType, parameterNames); 63 classElement(typeName, objectType, parameterNames);
73 64
74 static classTypeAlias(String typeName, InterfaceType superclassType, 65 static classTypeAlias(String typeName, InterfaceType superclassType,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 227 }
237 228
238 static FieldFormalParameterElementImpl fieldFormalParameter( 229 static FieldFormalParameterElementImpl fieldFormalParameter(
239 Identifier name) => 230 Identifier name) =>
240 new FieldFormalParameterElementImpl(name); 231 new FieldFormalParameterElementImpl(name);
241 232
242 static FunctionElementImpl functionElement(String functionName) => 233 static FunctionElementImpl functionElement(String functionName) =>
243 functionElement4(functionName, null, null, null, null); 234 functionElement4(functionName, null, null, null, null);
244 235
245 static FunctionElementImpl functionElement2( 236 static FunctionElementImpl functionElement2(
246 String functionName, ClassElement returnElement) => 237 String functionName, TypeDefiningElement returnElement) =>
247 functionElement3(functionName, returnElement, null, null); 238 functionElement3(functionName, returnElement, null, null);
248 239
249 static FunctionElementImpl functionElement3( 240 static FunctionElementImpl functionElement3(
250 String functionName, 241 String functionName,
251 ClassElement returnElement, 242 TypeDefiningElement returnElement,
252 List<TypeDefiningElement> normalParameters, 243 List<TypeDefiningElement> normalParameters,
253 List<TypeDefiningElement> optionalParameters) { 244 List<TypeDefiningElement> optionalParameters) {
254 // We don't create parameter elements because we don't have parameter names 245 // We don't create parameter elements because we don't have parameter names
255 FunctionElementImpl functionElement = 246 FunctionElementImpl functionElement =
256 new FunctionElementImpl(functionName, 0); 247 new FunctionElementImpl(functionName, 0);
257 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement); 248 FunctionTypeImpl functionType = new FunctionTypeImpl(functionElement);
258 functionElement.type = functionType; 249 functionElement.type = functionType;
259 // return type 250 // return type
260 if (returnElement == null) { 251 if (returnElement == null) {
261 functionElement.returnType = VoidTypeImpl.instance; 252 functionElement.returnType = VoidTypeImpl.instance;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 variable.setter = setter; 595 variable.setter = setter;
605 } 596 }
606 return variable; 597 return variable;
607 } 598 }
608 599
609 static TypeParameterElementImpl typeParameterElement(String name) { 600 static TypeParameterElementImpl typeParameterElement(String name) {
610 TypeParameterElementImpl element = new TypeParameterElementImpl(name, 0); 601 TypeParameterElementImpl element = new TypeParameterElementImpl(name, 0);
611 element.type = new TypeParameterTypeImpl(element); 602 element.type = new TypeParameterTypeImpl(element);
612 return element; 603 return element;
613 } 604 }
605
606 static List<TypeParameterElement> typeParameters(List<String> names) {
607 int count = names.length;
608 if (count == 0) {
609 return TypeParameterElement.EMPTY_LIST;
610 }
611 List<TypeParameterElementImpl> typeParameters =
612 new List<TypeParameterElementImpl>(count);
613 for (int i = 0; i < count; i++) {
614 typeParameters[i] = typeParameterWithType(names[i]);
615 }
616 return typeParameters;
617 }
618
619 static TypeParameterElementImpl typeParameterWithType(String name,
620 [DartType bound]) {
621 TypeParameterElementImpl typeParameter = typeParameterElement(name);
622 typeParameter.type = new TypeParameterTypeImpl(typeParameter);
623 typeParameter.bound = bound;
624 return typeParameter;
625 }
614 } 626 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698