Chromium Code Reviews| 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.element; | 5 library engine.element; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/utilities_general.dart'; | 10 import 'package:analyzer/src/generated/utilities_general.dart'; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 buffer.write('...'); | 121 buffer.write('...'); |
| 122 } | 122 } |
| 123 | 123 |
| 124 @override | 124 @override |
| 125 TypeImpl pruned(List<FunctionTypeAliasElement> prune) => this; | 125 TypeImpl pruned(List<FunctionTypeAliasElement> prune) => this; |
| 126 } | 126 } |
| 127 | 127 |
| 128 /** | 128 /** |
| 129 * An element that represents a class. | 129 * An element that represents a class. |
| 130 */ | 130 */ |
| 131 abstract class ClassElement implements TypeDefiningElement { | 131 abstract class ClassElement |
| 132 implements TypeDefiningElement, TypeParameterizedElement { | |
| 132 /** | 133 /** |
| 133 * An empty list of class elements. | 134 * An empty list of class elements. |
| 134 */ | 135 */ |
| 135 static const List<ClassElement> EMPTY_LIST = const <ClassElement>[]; | 136 static const List<ClassElement> EMPTY_LIST = const <ClassElement>[]; |
| 136 | 137 |
| 137 /** | 138 /** |
| 138 * Return a list containing all of the accessors (getters and setters) | 139 * Return a list containing all of the accessors (getters and setters) |
| 139 * declared in this class. | 140 * declared in this class. |
| 140 */ | 141 */ |
| 141 List<PropertyAccessorElement> get accessors; | 142 List<PropertyAccessorElement> get accessors; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 * safe to assume that the inheritance structure of a class does not contain a | 263 * safe to assume that the inheritance structure of a class does not contain a |
| 263 * cycle. Clients that traverse the inheritance structure must explicitly | 264 * cycle. Clients that traverse the inheritance structure must explicitly |
| 264 * guard against infinite loops. | 265 * guard against infinite loops. |
| 265 */ | 266 */ |
| 266 InterfaceType get supertype; | 267 InterfaceType get supertype; |
| 267 | 268 |
| 268 @override | 269 @override |
| 269 InterfaceType get type; | 270 InterfaceType get type; |
| 270 | 271 |
| 271 /** | 272 /** |
| 272 * Return a list containing all of the type parameters declared for this | |
| 273 * class. | |
| 274 */ | |
| 275 List<TypeParameterElement> get typeParameters; | |
| 276 | |
| 277 /** | |
| 278 * Return the unnamed constructor declared in this class, or `null` if this | 273 * Return the unnamed constructor declared in this class, or `null` if this |
| 279 * class does not declare an unnamed constructor but does declare named | 274 * class does not declare an unnamed constructor but does declare named |
| 280 * constructors. The returned constructor will be synthetic if this class does | 275 * constructors. The returned constructor will be synthetic if this class does |
| 281 * not declare any constructors, in which case it will represent the default | 276 * not declare any constructors, in which case it will represent the default |
| 282 * constructor for the class. | 277 * constructor for the class. |
| 283 */ | 278 */ |
| 284 ConstructorElement get unnamedConstructor; | 279 ConstructorElement get unnamedConstructor; |
| 285 | 280 |
| 286 /** | 281 /** |
| 287 * Return the resolved [ClassDeclaration] or [EnumDeclaration] node that | 282 * Return the resolved [ClassDeclaration] or [EnumDeclaration] node that |
| (...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1135 implicitParameter.const3 = superParameter.isConst; | 1130 implicitParameter.const3 = superParameter.isConst; |
| 1136 implicitParameter.final2 = superParameter.isFinal; | 1131 implicitParameter.final2 = superParameter.isFinal; |
| 1137 implicitParameter.parameterKind = superParameter.parameterKind; | 1132 implicitParameter.parameterKind = superParameter.parameterKind; |
| 1138 implicitParameter.synthetic = true; | 1133 implicitParameter.synthetic = true; |
| 1139 implicitParameter.type = | 1134 implicitParameter.type = |
| 1140 superParameter.type.substitute2(argumentTypes, parameterTypes); | 1135 superParameter.type.substitute2(argumentTypes, parameterTypes); |
| 1141 implicitParameters[i] = implicitParameter; | 1136 implicitParameters[i] = implicitParameter; |
| 1142 } | 1137 } |
| 1143 implicitConstructor.parameters = implicitParameters; | 1138 implicitConstructor.parameters = implicitParameters; |
| 1144 } | 1139 } |
| 1145 FunctionTypeImpl constructorType = | |
| 1146 new FunctionTypeImpl(implicitConstructor); | |
| 1147 constructorType.typeArguments = type.typeArguments; | |
| 1148 implicitConstructor.type = constructorType; | |
| 1149 implicitConstructor.enclosingElement = this; | 1140 implicitConstructor.enclosingElement = this; |
| 1141 implicitConstructor.type = new FunctionTypeImpl(implicitConstructor); | |
| 1150 return implicitConstructor; | 1142 return implicitConstructor; |
| 1151 }).toList(); | 1143 }).toList(); |
| 1152 } | 1144 } |
| 1153 | 1145 |
| 1154 PropertyAccessorElement _internalLookUpConcreteGetter( | 1146 PropertyAccessorElement _internalLookUpConcreteGetter( |
| 1155 String getterName, LibraryElement library, bool includeThisClass) { | 1147 String getterName, LibraryElement library, bool includeThisClass) { |
| 1156 PropertyAccessorElement getter = | 1148 PropertyAccessorElement getter = |
| 1157 _internalLookUpGetter(getterName, library, includeThisClass); | 1149 _internalLookUpGetter(getterName, library, includeThisClass); |
| 1158 while (getter != null && getter.isAbstract) { | 1150 while (getter != null && getter.isAbstract) { |
| 1159 Element definingClass = getter.enclosingElement; | 1151 Element definingClass = getter.enclosingElement; |
| (...skipping 2415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3575 @override | 3567 @override |
| 3576 void visitChildren(ElementVisitor visitor) { | 3568 void visitChildren(ElementVisitor visitor) { |
| 3577 safelyVisitChild(_scriptLibrary, visitor); | 3569 safelyVisitChild(_scriptLibrary, visitor); |
| 3578 } | 3570 } |
| 3579 } | 3571 } |
| 3580 | 3572 |
| 3581 /** | 3573 /** |
| 3582 * An element representing an executable object, including functions, methods, | 3574 * An element representing an executable object, including functions, methods, |
| 3583 * constructors, getters, and setters. | 3575 * constructors, getters, and setters. |
| 3584 */ | 3576 */ |
| 3585 abstract class ExecutableElement implements Element { | 3577 abstract class ExecutableElement implements TypeParameterizedElement { |
| 3586 /** | 3578 /** |
| 3587 * An empty list of executable elements. | 3579 * An empty list of executable elements. |
| 3588 */ | 3580 */ |
| 3589 static const List<ExecutableElement> EMPTY_LIST = const <ExecutableElement>[]; | 3581 static const List<ExecutableElement> EMPTY_LIST = const <ExecutableElement>[]; |
| 3590 | 3582 |
| 3591 /** | 3583 /** |
| 3592 * Return a list containing all of the functions defined within this | 3584 * Return a list containing all of the functions defined within this |
| 3593 * executable element. | 3585 * executable element. |
| 3594 */ | 3586 */ |
| 3595 List<FunctionElement> get functions; | 3587 List<FunctionElement> get functions; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3669 * Return the return type defined by this executable element. If the element | 3661 * Return the return type defined by this executable element. If the element |
| 3670 * model is fully populated, then the [returnType] will not be `null`, even | 3662 * model is fully populated, then the [returnType] will not be `null`, even |
| 3671 * if no return type was explicitly specified. | 3663 * if no return type was explicitly specified. |
| 3672 */ | 3664 */ |
| 3673 DartType get returnType; | 3665 DartType get returnType; |
| 3674 | 3666 |
| 3675 /** | 3667 /** |
| 3676 * Return the type of function defined by this executable element. | 3668 * Return the type of function defined by this executable element. |
| 3677 */ | 3669 */ |
| 3678 FunctionType get type; | 3670 FunctionType get type; |
| 3679 | |
| 3680 /** | |
| 3681 * Return a list containing all of the type parameters defined for this | |
| 3682 * executable element. | |
| 3683 */ | |
| 3684 List<TypeParameterElement> get typeParameters; | |
| 3685 } | 3671 } |
| 3686 | 3672 |
| 3687 /** | 3673 /** |
| 3688 * A base class for concrete implementations of an [ExecutableElement]. | 3674 * A base class for concrete implementations of an [ExecutableElement]. |
| 3689 */ | 3675 */ |
| 3690 abstract class ExecutableElementImpl extends ElementImpl | 3676 abstract class ExecutableElementImpl extends ElementImpl |
| 3691 implements ExecutableElement { | 3677 implements ExecutableElement { |
| 3692 /** | 3678 /** |
| 3693 * An empty list of executable elements. | 3679 * An empty list of executable elements. |
| 3694 */ | 3680 */ |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4651 * Return the type resulting from substituting the given [argumentTypes] for | 4637 * Return the type resulting from substituting the given [argumentTypes] for |
| 4652 * this type's parameters. This is fully equivalent to | 4638 * this type's parameters. This is fully equivalent to |
| 4653 * `substitute(argumentTypes, getTypeArguments())`. | 4639 * `substitute(argumentTypes, getTypeArguments())`. |
| 4654 */ | 4640 */ |
| 4655 FunctionType substitute3(List<DartType> argumentTypes); | 4641 FunctionType substitute3(List<DartType> argumentTypes); |
| 4656 } | 4642 } |
| 4657 | 4643 |
| 4658 /** | 4644 /** |
| 4659 * A function type alias (`typedef`). | 4645 * A function type alias (`typedef`). |
| 4660 */ | 4646 */ |
| 4661 abstract class FunctionTypeAliasElement implements TypeDefiningElement { | 4647 abstract class FunctionTypeAliasElement |
| 4648 implements TypeDefiningElement, TypeParameterizedElement { | |
| 4662 /** | 4649 /** |
| 4663 * An empty array of type alias elements. | 4650 * An empty array of type alias elements. |
| 4664 */ | 4651 */ |
| 4665 static List<FunctionTypeAliasElement> EMPTY_LIST = | 4652 static List<FunctionTypeAliasElement> EMPTY_LIST = |
| 4666 new List<FunctionTypeAliasElement>(0); | 4653 new List<FunctionTypeAliasElement>(0); |
| 4667 | 4654 |
| 4668 /** | 4655 /** |
| 4669 * Return the compilation unit in which this type alias is defined. | 4656 * Return the compilation unit in which this type alias is defined. |
| 4670 */ | 4657 */ |
| 4671 @override | 4658 @override |
| 4672 CompilationUnitElement get enclosingElement; | 4659 CompilationUnitElement get enclosingElement; |
| 4673 | 4660 |
| 4674 /** | 4661 /** |
| 4675 * Return a list containing all of the parameters defined by this type alias. | 4662 * Return a list containing all of the parameters defined by this type alias. |
| 4676 */ | 4663 */ |
| 4677 List<ParameterElement> get parameters; | 4664 List<ParameterElement> get parameters; |
| 4678 | 4665 |
| 4679 /** | 4666 /** |
| 4680 * Return the return type defined by this type alias. | 4667 * Return the return type defined by this type alias. |
| 4681 */ | 4668 */ |
| 4682 DartType get returnType; | 4669 DartType get returnType; |
| 4683 | 4670 |
| 4684 @override | 4671 @override |
| 4685 FunctionType get type; | 4672 FunctionType get type; |
| 4686 | 4673 |
| 4687 /** | 4674 /** |
| 4688 * Return a list containing all of the type parameters defined for this type. | |
| 4689 */ | |
| 4690 List<TypeParameterElement> get typeParameters; | |
| 4691 | |
| 4692 /** | |
| 4693 * Return the resolved function type alias node that declares this element. | 4675 * Return the resolved function type alias node that declares this element. |
| 4694 * | 4676 * |
| 4695 * This method is expensive, because resolved AST might be evicted from cache, | 4677 * This method is expensive, because resolved AST might be evicted from cache, |
| 4696 * so parsing and resolving will be performed. | 4678 * so parsing and resolving will be performed. |
| 4697 */ | 4679 */ |
| 4698 @override | 4680 @override |
| 4699 FunctionTypeAlias computeNode(); | 4681 FunctionTypeAlias computeNode(); |
| 4700 } | 4682 } |
| 4701 | 4683 |
| 4702 /** | 4684 /** |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4861 super.visitChildren(visitor); | 4843 super.visitChildren(visitor); |
| 4862 safelyVisitChildren(_parameters, visitor); | 4844 safelyVisitChildren(_parameters, visitor); |
| 4863 safelyVisitChildren(_typeParameters, visitor); | 4845 safelyVisitChildren(_typeParameters, visitor); |
| 4864 } | 4846 } |
| 4865 } | 4847 } |
| 4866 | 4848 |
| 4867 /** | 4849 /** |
| 4868 * The type of a function, method, constructor, getter, or setter. | 4850 * The type of a function, method, constructor, getter, or setter. |
| 4869 */ | 4851 */ |
| 4870 class FunctionTypeImpl extends TypeImpl implements FunctionType { | 4852 class FunctionTypeImpl extends TypeImpl implements FunctionType { |
| 4871 /** | 4853 List<DartType> _typeArguments = DartType.EMPTY_LIST; |
|
Brian Wilkerson
2015/11/13 18:56:16
Not sure why you removed the comment. If it was wr
Jennifer Messerly
2015/11/13 19:04:46
The comment moved to the public getter. Normally I
Brian Wilkerson
2015/11/13 20:17:14
I know it's redundant, but I always comment both.
Jennifer Messerly
2015/11/13 22:53:14
yeah that would be good!
In the meantime, done! I
| |
| 4872 * A list containing the actual types of the type arguments. | |
| 4873 */ | |
| 4874 List<DartType> typeArguments = DartType.EMPTY_LIST; | |
| 4875 | 4854 |
| 4876 /** | 4855 /** |
| 4877 * The set of typedefs which should not be expanded when exploring this type, | 4856 * The set of typedefs which should not be expanded when exploring this type, |
| 4878 * to avoid creating infinite types in response to self-referential typedefs. | 4857 * to avoid creating infinite types in response to self-referential typedefs. |
| 4879 */ | 4858 */ |
| 4880 final List<FunctionTypeAliasElement> prunedTypedefs; | 4859 final List<FunctionTypeAliasElement> prunedTypedefs; |
| 4881 | 4860 |
| 4882 /** | 4861 /** |
| 4883 * Initialize a newly created function type to be declared by the given | 4862 * Initialize a newly created function type to be declared by the given |
| 4884 * [element]. | 4863 * [element], and also initialize [typeArguments] to match the |
| 4864 * [typeParameters], which permits later substitution. | |
| 4885 */ | 4865 */ |
| 4886 FunctionTypeImpl(ExecutableElement element, [this.prunedTypedefs]) | 4866 FunctionTypeImpl(ExecutableElement element, |
| 4887 : super(element, null); | 4867 [List<FunctionTypeAliasElement> prunedTypedefs]) |
| 4868 : this._(element, null, prunedTypedefs, null); | |
| 4888 | 4869 |
| 4889 /** | 4870 /** |
| 4890 * Initialize a newly created function type to be declared by the given | 4871 * Initialize a newly created function type to be declared by the given |
| 4891 * [element]. | 4872 * [element]. |
| 4892 */ | 4873 */ |
| 4893 @deprecated // Use new FunctionTypeImpl(element) | 4874 @deprecated // Use new FunctionTypeImpl(element) |
| 4894 FunctionTypeImpl.con1(ExecutableElement element) : this(element); | 4875 FunctionTypeImpl.con1(ExecutableElement element) : this(element); |
| 4895 | 4876 |
| 4896 /** | 4877 /** |
| 4897 * Initialize a newly created function type to be declared by the given | 4878 * Initialize a newly created function type to be declared by the given |
| 4898 * [element]. | 4879 * [element]. |
| 4899 */ | 4880 */ |
| 4900 @deprecated // Use new FunctionTypeImpl.forTypedef(element) | 4881 @deprecated // Use new FunctionTypeImpl.forTypedef(element) |
| 4901 FunctionTypeImpl.con2(FunctionTypeAliasElement element) | 4882 FunctionTypeImpl.con2(FunctionTypeAliasElement element) |
| 4902 : this.forTypedef(element); | 4883 : this.forTypedef(element); |
| 4903 | 4884 |
| 4904 /** | 4885 /** |
| 4905 * Initialize a newly created function type to be declared by the given | 4886 * Initialize a newly created function type to be declared by the given |
| 4906 * [element]. | 4887 * [element]. |
| 4907 */ | 4888 */ |
| 4908 FunctionTypeImpl.forTypedef(FunctionTypeAliasElement element, | 4889 FunctionTypeImpl.forTypedef(FunctionTypeAliasElement element, |
| 4909 [this.prunedTypedefs]) | 4890 [List<FunctionTypeAliasElement> prunedTypedefs]) |
| 4910 : super(element, element == null ? null : element.name); | 4891 : this._(element, element?.name, prunedTypedefs, null); |
| 4911 | 4892 |
| 4912 /** | 4893 /** |
| 4913 * Private constructor. | 4894 * Private constructor. |
| 4914 */ | 4895 */ |
| 4915 FunctionTypeImpl._(Element element, String name, this.prunedTypedefs) | 4896 FunctionTypeImpl._(Element element, String name, this.prunedTypedefs, |
| 4916 : super(element, name); | 4897 List<DartType> typeArguments) |
| 4898 : super(element, name) { | |
| 4899 if (typeArguments != null) { | |
| 4900 _typeArguments = typeArguments; | |
| 4901 } else { | |
| 4902 List<TypeParameterElement> typeParameters = this.typeParameters; | |
|
Brian Wilkerson
2015/11/13 18:56:16
See TypeParameterTypeImpl.getTypes
Jennifer Messerly
2015/11/13 19:04:46
Yeah, I tried that first. Unfortunately that doesn
Brian Wilkerson
2015/11/13 20:17:14
Yes, a comment would be great, thanks!
Jennifer Messerly
2015/11/13 22:53:14
Done.
| |
| 4903 if (typeParameters.isEmpty) { | |
| 4904 _typeArguments = DartType.EMPTY_LIST; | |
| 4905 } else { | |
| 4906 _typeArguments = new List<DartType>.from( | |
| 4907 typeParameters.map((t) => t.type), | |
| 4908 growable: false); | |
| 4909 } | |
| 4910 } | |
| 4911 } | |
| 4917 | 4912 |
| 4918 /** | 4913 /** |
| 4919 * Return the base parameter elements of this function element. | 4914 * Return the base parameter elements of this function element. |
| 4920 */ | 4915 */ |
| 4921 List<ParameterElement> get baseParameters { | 4916 List<ParameterElement> get baseParameters { |
| 4922 Element element = this.element; | 4917 Element element = this.element; |
| 4923 if (element is ExecutableElement) { | 4918 if (element is ExecutableElement) { |
| 4924 return element.parameters; | 4919 return element.parameters; |
| 4925 } else { | 4920 } else { |
| 4926 return (element as FunctionTypeAliasElement).parameters; | 4921 return (element as FunctionTypeAliasElement).parameters; |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5158 // If there are no arguments to substitute, or if the arguments size doesn't | 5153 // If there are no arguments to substitute, or if the arguments size doesn't |
| 5159 // match the parameter size, return the base return type. | 5154 // match the parameter size, return the base return type. |
| 5160 if (typeArguments.length == 0 || | 5155 if (typeArguments.length == 0 || |
| 5161 typeArguments.length != typeParameters.length) { | 5156 typeArguments.length != typeParameters.length) { |
| 5162 return (baseReturnType as TypeImpl).pruned(newPrune); | 5157 return (baseReturnType as TypeImpl).pruned(newPrune); |
| 5163 } | 5158 } |
| 5164 return (baseReturnType as TypeImpl).substitute2(typeArguments, | 5159 return (baseReturnType as TypeImpl).substitute2(typeArguments, |
| 5165 TypeParameterTypeImpl.getTypes(typeParameters), newPrune); | 5160 TypeParameterTypeImpl.getTypes(typeParameters), newPrune); |
| 5166 } | 5161 } |
| 5167 | 5162 |
| 5163 /** | |
| 5164 * A list containing the actual types of the type arguments. | |
| 5165 */ | |
| 5166 List<DartType> get typeArguments => _typeArguments; | |
| 5167 | |
| 5168 @override | 5168 @override |
| 5169 List<TypeParameterElement> get typeParameters { | 5169 List<TypeParameterElement> get typeParameters { |
| 5170 Element element = this.element; | 5170 // Combine the generic type arguments from all enclosing contexts. |
| 5171 if (element is FunctionTypeAliasElement) { | 5171 // For example, this could be a generic method in a class, or a local |
| 5172 return element.typeParameters; | 5172 // function within another function. |
| 5173 List<TypeParameterElement> typeParams = <TypeParameterElement>[]; | |
| 5174 for (Element e = element; e != null; e = e.enclosingElement) { | |
| 5175 if (e is TypeParameterizedElement) { | |
| 5176 typeParams.addAll(e.typeParameters); | |
| 5177 } | |
| 5173 } | 5178 } |
| 5174 ClassElement definingClass = | 5179 return typeParams; |
| 5175 element.getAncestor((element) => element is ClassElement); | |
| 5176 if (definingClass != null) { | |
| 5177 return definingClass.typeParameters; | |
| 5178 } | |
| 5179 return TypeParameterElement.EMPTY_LIST; | |
| 5180 } | 5180 } |
| 5181 | 5181 |
| 5182 @override | 5182 @override |
| 5183 bool operator ==(Object object) { | 5183 bool operator ==(Object object) { |
| 5184 if (object is! FunctionTypeImpl) { | 5184 if (object is! FunctionTypeImpl) { |
| 5185 return false; | 5185 return false; |
| 5186 } | 5186 } |
| 5187 FunctionTypeImpl otherType = object as FunctionTypeImpl; | 5187 FunctionTypeImpl otherType = object as FunctionTypeImpl; |
| 5188 return returnType == otherType.returnType && | 5188 return returnType == otherType.returnType && |
| 5189 TypeImpl.equalArrays( | 5189 TypeImpl.equalArrays( |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5495 return this; | 5495 return this; |
| 5496 } else if (prune.contains(element)) { | 5496 } else if (prune.contains(element)) { |
| 5497 // Circularity found. Prune the type declaration. | 5497 // Circularity found. Prune the type declaration. |
| 5498 return new CircularTypeImpl(); | 5498 return new CircularTypeImpl(); |
| 5499 } else { | 5499 } else { |
| 5500 // There should never be a reason to prune a type that has already been | 5500 // There should never be a reason to prune a type that has already been |
| 5501 // pruned, since pruning is only done when expanding a function type | 5501 // pruned, since pruning is only done when expanding a function type |
| 5502 // alias, and function type aliases are always expanded by starting with | 5502 // alias, and function type aliases are always expanded by starting with |
| 5503 // base types. | 5503 // base types. |
| 5504 assert(this.prunedTypedefs == null); | 5504 assert(this.prunedTypedefs == null); |
| 5505 FunctionTypeImpl result = new FunctionTypeImpl._(element, name, prune); | 5505 List<DartType> typeArgs = typeArguments |
| 5506 result.typeArguments = | 5506 .map((TypeImpl t) => t.pruned(prune)) |
| 5507 typeArguments.map((TypeImpl t) => t.pruned(prune)).toList(); | 5507 .toList(growable: false); |
| 5508 return result; | 5508 return new FunctionTypeImpl._(element, name, prune, typeArgs); |
| 5509 } | 5509 } |
| 5510 } | 5510 } |
| 5511 | 5511 |
| 5512 @override | 5512 @override |
| 5513 DartType substitute2( | 5513 DartType substitute2( |
| 5514 List<DartType> argumentTypes, List<DartType> parameterTypes, | 5514 List<DartType> argumentTypes, List<DartType> parameterTypes, |
| 5515 [List<FunctionTypeAliasElement> prune]) { | 5515 [List<FunctionTypeAliasElement> prune]) { |
| 5516 // Pruned types should only ever result from peforming type variable | 5516 // Pruned types should only ever result from performing type variable |
| 5517 // substitution, and it doesn't make sense to substitute again after | 5517 // substitution, and it doesn't make sense to substitute again after |
| 5518 // substituting once. | 5518 // substituting once. |
| 5519 assert(this.prunedTypedefs == null); | 5519 assert(this.prunedTypedefs == null); |
| 5520 if (argumentTypes.length != parameterTypes.length) { | 5520 if (argumentTypes.length != parameterTypes.length) { |
| 5521 throw new IllegalArgumentException( | 5521 throw new IllegalArgumentException( |
| 5522 "argumentTypes.length (${argumentTypes.length}) != parameterTypes.leng th (${parameterTypes.length})"); | 5522 "argumentTypes.length (${argumentTypes.length}) != parameterTypes.leng th (${parameterTypes.length})"); |
| 5523 } | 5523 } |
| 5524 Element element = this.element; | 5524 Element element = this.element; |
| 5525 if (prune != null && prune.contains(element)) { | 5525 if (prune != null && prune.contains(element)) { |
| 5526 // Circularity found. Prune the type declaration. | 5526 // Circularity found. Prune the type declaration. |
| 5527 return new CircularTypeImpl(); | 5527 return new CircularTypeImpl(); |
| 5528 } | 5528 } |
| 5529 if (argumentTypes.length == 0) { | 5529 if (argumentTypes.length == 0) { |
| 5530 return this.pruned(prune); | 5530 return this.pruned(prune); |
| 5531 } | 5531 } |
| 5532 FunctionTypeImpl newType = (element is ExecutableElement) | 5532 List<DartType> typeArgs = |
| 5533 ? new FunctionTypeImpl(element, prune) | |
| 5534 : new FunctionTypeImpl.forTypedef( | |
| 5535 element as FunctionTypeAliasElement, prune); | |
| 5536 newType.typeArguments = | |
| 5537 TypeImpl.substitute(typeArguments, argumentTypes, parameterTypes); | 5533 TypeImpl.substitute(typeArguments, argumentTypes, parameterTypes); |
| 5538 return newType; | 5534 return new FunctionTypeImpl._(element, name, prune, typeArgs); |
| 5539 } | 5535 } |
| 5540 | 5536 |
| 5541 @override | 5537 @override |
| 5542 FunctionTypeImpl substitute3(List<DartType> argumentTypes) => | 5538 FunctionTypeImpl substitute3(List<DartType> argumentTypes) => |
| 5543 substitute2(argumentTypes, typeArguments); | 5539 substitute2(argumentTypes, typeArguments); |
| 5544 | 5540 |
| 5545 /** | 5541 /** |
| 5546 * Compute the least upper bound of types [f] and [g], both of which are | 5542 * Compute the least upper bound of types [f] and [g], both of which are |
| 5547 * known to be function types. | 5543 * known to be function types. |
| 5548 * | 5544 * |
| (...skipping 2794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8343 List<DartType> argumentTypes = _definingType.typeArguments; | 8339 List<DartType> argumentTypes = _definingType.typeArguments; |
| 8344 List<DartType> parameterTypes = | 8340 List<DartType> parameterTypes = |
| 8345 TypeParameterTypeImpl.getTypes(_definingType.typeParameters); | 8341 TypeParameterTypeImpl.getTypes(_definingType.typeParameters); |
| 8346 return type.substitute2(argumentTypes, parameterTypes); | 8342 return type.substitute2(argumentTypes, parameterTypes); |
| 8347 } | 8343 } |
| 8348 | 8344 |
| 8349 /** | 8345 /** |
| 8350 * Return the list of types that results from replacing the type parameters in | 8346 * Return the list of types that results from replacing the type parameters in |
| 8351 * the given [types] with the type arguments associated with this member. | 8347 * the given [types] with the type arguments associated with this member. |
| 8352 */ | 8348 */ |
| 8349 @deprecated | |
| 8353 List<InterfaceType> substituteFor2(List<InterfaceType> types) { | 8350 List<InterfaceType> substituteFor2(List<InterfaceType> types) { |
| 8354 int count = types.length; | 8351 int count = types.length; |
| 8355 List<InterfaceType> substitutedTypes = new List<InterfaceType>(count); | 8352 List<InterfaceType> substitutedTypes = new List<InterfaceType>(count); |
| 8356 for (int i = 0; i < count; i++) { | 8353 for (int i = 0; i < count; i++) { |
| 8357 substitutedTypes[i] = substituteFor(types[i]); | 8354 substitutedTypes[i] = substituteFor(types[i]); |
| 8358 } | 8355 } |
| 8359 return substitutedTypes; | 8356 return substitutedTypes; |
| 8360 } | 8357 } |
| 8361 | 8358 |
| 8362 @override | 8359 @override |
| (...skipping 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10527 void appendTo(StringBuffer buffer) { | 10524 void appendTo(StringBuffer buffer) { |
| 10528 buffer.write(displayName); | 10525 buffer.write(displayName); |
| 10529 if (bound != null) { | 10526 if (bound != null) { |
| 10530 buffer.write(" extends "); | 10527 buffer.write(" extends "); |
| 10531 buffer.write(bound); | 10528 buffer.write(bound); |
| 10532 } | 10529 } |
| 10533 } | 10530 } |
| 10534 } | 10531 } |
| 10535 | 10532 |
| 10536 /** | 10533 /** |
| 10534 * An element that has type parameters. | |
| 10535 * | |
| 10536 * For example, a class or a typedef. This also includes functions methods if | |
|
Brian Wilkerson
2015/11/13 18:56:16
nit: "functions" --> "function"
Jennifer Messerly
2015/11/13 19:04:46
oops, it should be "functions and methods"
Jennifer Messerly
2015/11/13 22:53:14
Done.
| |
| 10537 * support for generic methods is enabled. | |
| 10538 */ | |
| 10539 abstract class TypeParameterizedElement implements Element { | |
| 10540 /** | |
| 10541 * Return a list containing all of the type parameters declared for this | |
| 10542 * class. | |
| 10543 */ | |
| 10544 List<TypeParameterElement> get typeParameters; | |
| 10545 } | |
| 10546 | |
| 10547 /** | |
| 10537 * The type introduced by a type parameter. | 10548 * The type introduced by a type parameter. |
| 10538 */ | 10549 */ |
| 10539 abstract class TypeParameterType implements DartType { | 10550 abstract class TypeParameterType implements DartType { |
| 10540 /** | 10551 /** |
| 10541 * An empty list of type parameter types. | 10552 * An empty list of type parameter types. |
| 10542 */ | 10553 */ |
| 10543 static const List<TypeParameterType> EMPTY_LIST = const <TypeParameterType>[]; | 10554 static const List<TypeParameterType> EMPTY_LIST = const <TypeParameterType>[]; |
| 10544 | 10555 |
| 10545 @override | 10556 @override |
| 10546 TypeParameterElement get element; | 10557 TypeParameterElement get element; |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11137 | 11148 |
| 11138 @override | 11149 @override |
| 11139 void visitElement(Element element) { | 11150 void visitElement(Element element) { |
| 11140 int offset = element.nameOffset; | 11151 int offset = element.nameOffset; |
| 11141 if (offset != -1) { | 11152 if (offset != -1) { |
| 11142 map[offset] = element; | 11153 map[offset] = element; |
| 11143 } | 11154 } |
| 11144 super.visitElement(element); | 11155 super.visitElement(element); |
| 11145 } | 11156 } |
| 11146 } | 11157 } |
| OLD | NEW |