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 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1986 | 1986 |
| 1987 /** | 1987 /** |
| 1988 * A constructor element defined in a parameterized type where the values of the | 1988 * A constructor element defined in a parameterized type where the values of the |
| 1989 * type parameters are known. | 1989 * type parameters are known. |
| 1990 */ | 1990 */ |
| 1991 class ConstructorMember extends ExecutableMember implements ConstructorElement { | 1991 class ConstructorMember extends ExecutableMember implements ConstructorElement { |
| 1992 /** | 1992 /** |
| 1993 * Initialize a newly created element to represent a constructor, based on the | 1993 * Initialize a newly created element to represent a constructor, based on the |
| 1994 * [baseElement], defined by the [definingType]. | 1994 * [baseElement], defined by the [definingType]. |
| 1995 */ | 1995 */ |
| 1996 ConstructorMember(ConstructorElement baseElement, InterfaceType definingType) | 1996 ConstructorMember(ConstructorElement baseElement, InterfaceType definingType, |
| 1997 : super(baseElement, definingType); | 1997 [FunctionType type]) |
|
Leaf
2015/12/05 00:50:40
Document what type is in the comment?
Jennifer Messerly
2015/12/07 17:46:58
Done.
| |
| 1998 : super(baseElement, definingType, type); | |
| 1998 | 1999 |
| 1999 @override | 2000 @override |
| 2000 ConstructorElement get baseElement => super.baseElement as ConstructorElement; | 2001 ConstructorElement get baseElement => super.baseElement as ConstructorElement; |
| 2001 | 2002 |
| 2002 @override | 2003 @override |
| 2003 InterfaceType get definingType => super.definingType as InterfaceType; | 2004 InterfaceType get definingType => super.definingType as InterfaceType; |
| 2004 | 2005 |
| 2005 @override | 2006 @override |
| 2006 ClassElement get enclosingElement => baseElement.enclosingElement; | 2007 ClassElement get enclosingElement => baseElement.enclosingElement; |
| 2007 | 2008 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2075 // TODO(brianwilkerson) We need to understand when this can happen. | 2076 // TODO(brianwilkerson) We need to understand when this can happen. |
| 2076 return constructor; | 2077 return constructor; |
| 2077 } | 2078 } |
| 2078 List<DartType> argumentTypes = definingType.typeArguments; | 2079 List<DartType> argumentTypes = definingType.typeArguments; |
| 2079 List<DartType> parameterTypes = definingType.element.type.typeArguments; | 2080 List<DartType> parameterTypes = definingType.element.type.typeArguments; |
| 2080 FunctionType substitutedType = | 2081 FunctionType substitutedType = |
| 2081 baseType.substitute2(argumentTypes, parameterTypes); | 2082 baseType.substitute2(argumentTypes, parameterTypes); |
| 2082 if (baseType == substitutedType) { | 2083 if (baseType == substitutedType) { |
| 2083 return constructor; | 2084 return constructor; |
| 2084 } | 2085 } |
| 2085 // TODO(brianwilkerson) Consider caching the substituted type in the | 2086 return new ConstructorMember(constructor, definingType, substitutedType); |
| 2086 // instance. It would use more memory but speed up some operations. | |
| 2087 // We need to see how often the type is being re-computed. | |
| 2088 return new ConstructorMember(constructor, definingType); | |
| 2089 } | 2087 } |
| 2090 } | 2088 } |
| 2091 | 2089 |
| 2092 /** | 2090 /** |
| 2093 * A [TopLevelVariableElement] for a top-level 'const' variable that has an | 2091 * A [TopLevelVariableElement] for a top-level 'const' variable that has an |
| 2094 * initializer. | 2092 * initializer. |
| 2095 */ | 2093 */ |
| 2096 class ConstTopLevelVariableElementImpl extends TopLevelVariableElementImpl | 2094 class ConstTopLevelVariableElementImpl extends TopLevelVariableElementImpl |
| 2097 with ConstVariableElement { | 2095 with ConstVariableElement { |
| 2098 /** | 2096 /** |
| (...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3567 @override | 3565 @override |
| 3568 void visitChildren(ElementVisitor visitor) { | 3566 void visitChildren(ElementVisitor visitor) { |
| 3569 safelyVisitChild(_scriptLibrary, visitor); | 3567 safelyVisitChild(_scriptLibrary, visitor); |
| 3570 } | 3568 } |
| 3571 } | 3569 } |
| 3572 | 3570 |
| 3573 /** | 3571 /** |
| 3574 * An element representing an executable object, including functions, methods, | 3572 * An element representing an executable object, including functions, methods, |
| 3575 * constructors, getters, and setters. | 3573 * constructors, getters, and setters. |
| 3576 */ | 3574 */ |
| 3577 abstract class ExecutableElement implements TypeParameterizedElement { | 3575 abstract class ExecutableElement implements FunctionTypedElement { |
| 3578 /** | 3576 /** |
| 3579 * An empty list of executable elements. | 3577 * An empty list of executable elements. |
| 3580 */ | 3578 */ |
| 3581 static const List<ExecutableElement> EMPTY_LIST = const <ExecutableElement>[]; | 3579 static const List<ExecutableElement> EMPTY_LIST = const <ExecutableElement>[]; |
| 3582 | 3580 |
| 3583 /** | 3581 /** |
| 3584 * Return a list containing all of the functions defined within this | 3582 * Return a list containing all of the functions defined within this |
| 3585 * executable element. | 3583 * executable element. |
| 3586 */ | 3584 */ |
| 3587 List<FunctionElement> get functions; | 3585 List<FunctionElement> get functions; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3643 * Return a list containing all of the labels defined within this executable | 3641 * Return a list containing all of the labels defined within this executable |
| 3644 * element. | 3642 * element. |
| 3645 */ | 3643 */ |
| 3646 List<LabelElement> get labels; | 3644 List<LabelElement> get labels; |
| 3647 | 3645 |
| 3648 /** | 3646 /** |
| 3649 * Return a list containing all of the local variables defined within this | 3647 * Return a list containing all of the local variables defined within this |
| 3650 * executable element. | 3648 * executable element. |
| 3651 */ | 3649 */ |
| 3652 List<LocalVariableElement> get localVariables; | 3650 List<LocalVariableElement> get localVariables; |
| 3653 | |
| 3654 /** | |
| 3655 * Return a list containing all of the parameters defined by this executable | |
| 3656 * element. | |
| 3657 */ | |
| 3658 List<ParameterElement> get parameters; | |
| 3659 | |
| 3660 /** | |
| 3661 * Return the return type defined by this executable element. If the element | |
| 3662 * model is fully populated, then the [returnType] will not be `null`, even | |
| 3663 * if no return type was explicitly specified. | |
| 3664 */ | |
| 3665 DartType get returnType; | |
| 3666 | |
| 3667 /** | |
| 3668 * Return the type of function defined by this executable element. | |
| 3669 */ | |
| 3670 FunctionType get type; | |
| 3671 } | 3651 } |
| 3672 | 3652 |
| 3673 /** | 3653 /** |
| 3674 * A base class for concrete implementations of an [ExecutableElement]. | 3654 * A base class for concrete implementations of an [ExecutableElement]. |
| 3675 */ | 3655 */ |
| 3676 abstract class ExecutableElementImpl extends ElementImpl | 3656 abstract class ExecutableElementImpl extends ElementImpl |
| 3677 implements ExecutableElement { | 3657 implements ExecutableElement { |
| 3678 /** | 3658 /** |
| 3679 * An empty list of executable elements. | 3659 * An empty list of executable elements. |
| 3680 */ | 3660 */ |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3935 safelyVisitChildren(_localVariables, visitor); | 3915 safelyVisitChildren(_localVariables, visitor); |
| 3936 safelyVisitChildren(_parameters, visitor); | 3916 safelyVisitChildren(_parameters, visitor); |
| 3937 } | 3917 } |
| 3938 } | 3918 } |
| 3939 | 3919 |
| 3940 /** | 3920 /** |
| 3941 * An executable element defined in a parameterized type where the values of the | 3921 * An executable element defined in a parameterized type where the values of the |
| 3942 * type parameters are known. | 3922 * type parameters are known. |
| 3943 */ | 3923 */ |
| 3944 abstract class ExecutableMember extends Member implements ExecutableElement { | 3924 abstract class ExecutableMember extends Member implements ExecutableElement { |
| 3925 @override | |
| 3926 final FunctionType type; | |
| 3927 | |
| 3945 /** | 3928 /** |
| 3946 * Initialize a newly created element to represent a constructor, based on the | 3929 * Initialize a newly created element to represent a constructor, based on the |
| 3947 * [baseElement], defined by the [definingType]. | 3930 * [baseElement], defined by the [definingType]. |
| 3948 */ | 3931 */ |
| 3949 ExecutableMember(ExecutableElement baseElement, InterfaceType definingType) | 3932 ExecutableMember(ExecutableElement baseElement, InterfaceType definingType, |
| 3950 : super(baseElement, definingType); | 3933 [FunctionType type]) |
|
Leaf
2015/12/05 00:50:40
ditto?
Jennifer Messerly
2015/12/07 17:46:58
Done.
| |
| 3934 : type = type ?? | |
| 3935 baseElement.type.substitute2(definingType.typeArguments, | |
| 3936 TypeParameterTypeImpl.getTypes(definingType.typeParameters)), | |
| 3937 super(baseElement, definingType); | |
| 3951 | 3938 |
| 3952 @override | 3939 @override |
| 3953 ExecutableElement get baseElement => super.baseElement as ExecutableElement; | 3940 ExecutableElement get baseElement => super.baseElement as ExecutableElement; |
| 3954 | 3941 |
| 3955 @override | 3942 @override |
| 3956 List<FunctionElement> get functions { | 3943 List<FunctionElement> get functions { |
| 3957 // | 3944 // |
| 3958 // Elements within this element should have type parameters substituted, | 3945 // Elements within this element should have type parameters substituted, |
| 3959 // just like this element. | 3946 // just like this element. |
| 3960 // | 3947 // |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3993 List<LocalVariableElement> get localVariables { | 3980 List<LocalVariableElement> get localVariables { |
| 3994 // | 3981 // |
| 3995 // Elements within this element should have type parameters substituted, | 3982 // Elements within this element should have type parameters substituted, |
| 3996 // just like this element. | 3983 // just like this element. |
| 3997 // | 3984 // |
| 3998 throw new UnsupportedOperationException(); | 3985 throw new UnsupportedOperationException(); |
| 3999 // return getBaseElement().getLocalVariables(); | 3986 // return getBaseElement().getLocalVariables(); |
| 4000 } | 3987 } |
| 4001 | 3988 |
| 4002 @override | 3989 @override |
| 4003 List<ParameterElement> get parameters { | 3990 List<ParameterElement> get parameters => type.parameters; |
| 4004 List<ParameterElement> baseParameters = baseElement.parameters; | |
| 4005 int parameterCount = baseParameters.length; | |
| 4006 if (parameterCount == 0) { | |
| 4007 return baseParameters; | |
| 4008 } | |
| 4009 List<ParameterElement> parameterizedParameters = | |
| 4010 new List<ParameterElement>(parameterCount); | |
| 4011 for (int i = 0; i < parameterCount; i++) { | |
| 4012 parameterizedParameters[i] = | |
| 4013 ParameterMember.from(baseParameters[i], definingType); | |
| 4014 } | |
| 4015 return parameterizedParameters; | |
| 4016 } | |
| 4017 | 3991 |
| 4018 @override | 3992 @override |
| 4019 DartType get returnType => substituteFor(baseElement.returnType); | 3993 DartType get returnType => type.returnType; |
| 4020 | |
| 4021 @override | |
| 4022 FunctionType get type => substituteFor(baseElement.type); | |
| 4023 | 3994 |
| 4024 @override | 3995 @override |
| 4025 List<TypeParameterElement> get typeParameters => baseElement.typeParameters; | 3996 List<TypeParameterElement> get typeParameters => baseElement.typeParameters; |
| 4026 | 3997 |
| 4027 @override | 3998 @override |
| 4028 void visitChildren(ElementVisitor visitor) { | 3999 void visitChildren(ElementVisitor visitor) { |
| 4029 // TODO(brianwilkerson) We need to finish implementing the accessors used | 4000 // TODO(brianwilkerson) We need to finish implementing the accessors used |
| 4030 // below so that we can safely invoke them. | 4001 // below so that we can safely invoke them. |
| 4031 super.visitChildren(visitor); | 4002 super.visitChildren(visitor); |
| 4032 safelyVisitChildren(baseElement.functions, visitor); | 4003 safelyVisitChildren(baseElement.functions, visitor); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4256 * A parameter element defined in a parameterized type where the values of the | 4227 * A parameter element defined in a parameterized type where the values of the |
| 4257 * type parameters are known. | 4228 * type parameters are known. |
| 4258 */ | 4229 */ |
| 4259 class FieldFormalParameterMember extends ParameterMember | 4230 class FieldFormalParameterMember extends ParameterMember |
| 4260 implements FieldFormalParameterElement { | 4231 implements FieldFormalParameterElement { |
| 4261 /** | 4232 /** |
| 4262 * Initialize a newly created element to represent a constructor, based on the | 4233 * Initialize a newly created element to represent a constructor, based on the |
| 4263 * [baseElement], defined by the [definingType]. | 4234 * [baseElement], defined by the [definingType]. |
| 4264 */ | 4235 */ |
| 4265 FieldFormalParameterMember( | 4236 FieldFormalParameterMember( |
| 4266 FieldFormalParameterElement baseElement, ParameterizedType definingType) | 4237 FieldFormalParameterElement baseElement, ParameterizedType definingType, |
| 4267 : super(baseElement, definingType); | 4238 [DartType type]) |
|
Leaf
2015/12/05 00:50:41
also.
| |
| 4239 : super(baseElement, definingType, type); | |
| 4268 | 4240 |
| 4269 @override | 4241 @override |
| 4270 FieldElement get field { | 4242 FieldElement get field { |
| 4271 FieldElement field = (baseElement as FieldFormalParameterElement).field; | 4243 FieldElement field = (baseElement as FieldFormalParameterElement).field; |
| 4272 if (field is FieldElement) { | 4244 if (field is FieldElement) { |
| 4273 return FieldMember.from(field, definingType); | 4245 return FieldMember.from( |
| 4246 field, substituteFor(field.enclosingElement.type)); | |
| 4274 } | 4247 } |
| 4275 return field; | 4248 return field; |
| 4276 } | 4249 } |
| 4277 | 4250 |
| 4278 @override | 4251 @override |
| 4279 accept(ElementVisitor visitor) => | 4252 accept(ElementVisitor visitor) => |
| 4280 visitor.visitFieldFormalParameterElement(this); | 4253 visitor.visitFieldFormalParameterElement(this); |
| 4281 } | 4254 } |
| 4282 | 4255 |
| 4283 /** | 4256 /** |
| 4284 * A field element defined in a parameterized type where the values of the type | 4257 * A field element defined in a parameterized type where the values of the type |
| 4285 * parameters are known. | 4258 * parameters are known. |
| 4286 */ | 4259 */ |
| 4287 class FieldMember extends VariableMember implements FieldElement { | 4260 class FieldMember extends VariableMember implements FieldElement { |
| 4288 /** | 4261 /** |
| 4289 * Initialize a newly created element to represent a constructor, based on the | 4262 * Initialize a newly created element to represent a constructor, based on the |
| 4290 * [baseElement], defined by the [definingType]. | 4263 * [baseElement], defined by the [definingType]. |
| 4291 */ | 4264 */ |
| 4292 FieldMember(FieldElement baseElement, InterfaceType definingType) | 4265 FieldMember(FieldElement baseElement, InterfaceType definingType) |
| 4293 : super(baseElement, definingType); | 4266 : super(baseElement, definingType); |
| 4294 | 4267 |
| 4295 @override | 4268 @override |
| 4296 FieldElement get baseElement => super.baseElement as FieldElement; | 4269 FieldElement get baseElement => super.baseElement as FieldElement; |
| 4297 | 4270 |
| 4298 @override | 4271 @override |
| 4299 InterfaceType get definingType => super.definingType as InterfaceType; | |
| 4300 | |
| 4301 @override | |
| 4302 ClassElement get enclosingElement => baseElement.enclosingElement; | 4272 ClassElement get enclosingElement => baseElement.enclosingElement; |
| 4303 | 4273 |
| 4304 @override | 4274 @override |
| 4305 PropertyAccessorElement get getter => | 4275 PropertyAccessorElement get getter => |
| 4306 PropertyAccessorMember.from(baseElement.getter, definingType); | 4276 PropertyAccessorMember.from(baseElement.getter, definingType); |
| 4307 | 4277 |
| 4308 @override | 4278 @override |
| 4309 bool get isEnumConstant => baseElement.isEnumConstant; | 4279 bool get isEnumConstant => baseElement.isEnumConstant; |
| 4310 | 4280 |
| 4311 @override | 4281 @override |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 4324 @override | 4294 @override |
| 4325 String toString() => '$type $displayName'; | 4295 String toString() => '$type $displayName'; |
| 4326 | 4296 |
| 4327 /** | 4297 /** |
| 4328 * If the given [field]'s type is different when any type parameters from the | 4298 * If the given [field]'s type is different when any type parameters from the |
| 4329 * defining type's declaration are replaced with the actual type arguments | 4299 * defining type's declaration are replaced with the actual type arguments |
| 4330 * from the [definingType], create a field member representing the given | 4300 * from the [definingType], create a field member representing the given |
| 4331 * field. Return the member that was created, or the base field if no member | 4301 * field. Return the member that was created, or the base field if no member |
| 4332 * was created. | 4302 * was created. |
| 4333 */ | 4303 */ |
| 4334 static FieldElement from(FieldElement field, InterfaceType definingType) { | 4304 static FieldElement from(FieldElement field, ParameterizedType definingType) { |
| 4335 if (!_isChangedByTypeSubstitution(field, definingType)) { | 4305 if (!_isChangedByTypeSubstitution(field, definingType)) { |
| 4336 return field; | 4306 return field; |
| 4337 } | 4307 } |
| 4338 // TODO(brianwilkerson) Consider caching the substituted type in the | 4308 // TODO(brianwilkerson) Consider caching the substituted type in the |
| 4339 // instance. It would use more memory but speed up some operations. | 4309 // instance. It would use more memory but speed up some operations. |
| 4340 // We need to see how often the type is being re-computed. | 4310 // We need to see how often the type is being re-computed. |
| 4341 return new FieldMember(field, definingType); | 4311 return new FieldMember(field, definingType); |
| 4342 } | 4312 } |
| 4343 | 4313 |
| 4344 /** | 4314 /** |
| 4345 * Determine whether the given [field]'s type is changed when type parameters | 4315 * Determine whether the given [field]'s type is changed when type parameters |
| 4346 * from the [definingType]'s declaration are replaced with the actual type | 4316 * from the [definingType]'s declaration are replaced with the actual type |
| 4347 * arguments from the defining type. | 4317 * arguments from the defining type. |
| 4348 */ | 4318 */ |
| 4349 static bool _isChangedByTypeSubstitution( | 4319 static bool _isChangedByTypeSubstitution( |
| 4350 FieldElement field, InterfaceType definingType) { | 4320 FieldElement field, ParameterizedType definingType) { |
| 4351 List<DartType> argumentTypes = definingType.typeArguments; | 4321 List<DartType> argumentTypes = definingType.typeArguments; |
| 4352 if (field != null && argumentTypes.length != 0) { | 4322 if (field != null && argumentTypes.length != 0) { |
| 4353 DartType baseType = field.type; | 4323 DartType baseType = field.type; |
| 4354 List<DartType> parameterTypes = definingType.element.type.typeArguments; | 4324 List<DartType> parameterTypes = |
| 4325 (definingType.element as dynamic).type.typeArguments; | |
|
Leaf
2015/12/05 00:50:40
Lack of a common superclass? Maybe at least a comm
Jennifer Messerly
2015/12/07 17:46:58
yup, exactly. I actually have an idea for how to f
| |
| 4355 if (baseType != null) { | 4326 if (baseType != null) { |
| 4356 DartType substitutedType = | 4327 DartType substitutedType = |
| 4357 baseType.substitute2(argumentTypes, parameterTypes); | 4328 baseType.substitute2(argumentTypes, parameterTypes); |
| 4358 if (baseType != substitutedType) { | 4329 if (baseType != substitutedType) { |
| 4359 return true; | 4330 return true; |
| 4360 } | 4331 } |
| 4361 } | 4332 } |
| 4362 // If the field has a propagated type, then we need to check whether the | 4333 // If the field has a propagated type, then we need to check whether the |
| 4363 // propagated type needs substitution. | 4334 // propagated type needs substitution. |
| 4364 DartType basePropagatedType = field.propagatedType; | 4335 DartType basePropagatedType = field.propagatedType; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4519 * Set the parameters defined by this type alias to the given [parameters] | 4490 * Set the parameters defined by this type alias to the given [parameters] |
| 4520 * without becoming the parent of the parameters. This should only be used by | 4491 * without becoming the parent of the parameters. This should only be used by |
| 4521 * the [TypeResolverVisitor] when creating a synthetic type alias. | 4492 * the [TypeResolverVisitor] when creating a synthetic type alias. |
| 4522 */ | 4493 */ |
| 4523 void shareParameters(List<ParameterElement> parameters) { | 4494 void shareParameters(List<ParameterElement> parameters) { |
| 4524 this._parameters = parameters; | 4495 this._parameters = parameters; |
| 4525 } | 4496 } |
| 4526 } | 4497 } |
| 4527 | 4498 |
| 4528 /** | 4499 /** |
| 4500 * An element of a generic function, where the type parameters are known. | |
| 4501 */ | |
| 4502 // TODO(jmesserly): the term "function member" is a bit weird, but it allows | |
| 4503 // a certain consistency. | |
| 4504 class FunctionMember extends ExecutableMember implements FunctionElement { | |
| 4505 /** | |
| 4506 * Initialize a newly created element to represent a constructor, based on the | |
| 4507 * [baseElement], defined by the [definingType]. | |
|
Leaf
2015/12/05 00:50:40
Comment cut & pasted?
Jennifer Messerly
2015/12/07 17:46:58
Done.
Jennifer Messerly
2015/12/07 17:46:58
Done.
| |
| 4508 */ | |
| 4509 FunctionMember(FunctionElement baseElement, [DartType type]) | |
| 4510 : super(baseElement, null, type); | |
| 4511 | |
| 4512 @override | |
| 4513 FunctionElement get baseElement => super.baseElement as FunctionElement; | |
| 4514 | |
| 4515 @override | |
| 4516 Element get enclosingElement => baseElement.enclosingElement; | |
| 4517 | |
| 4518 @override | |
| 4519 bool get isEntryPoint => baseElement.isEntryPoint; | |
| 4520 | |
| 4521 @override | |
| 4522 SourceRange get visibleRange => baseElement.visibleRange; | |
| 4523 | |
| 4524 @override | |
| 4525 accept(ElementVisitor visitor) => visitor.visitFunctionElement(this); | |
| 4526 | |
| 4527 @override | |
| 4528 FunctionDeclaration computeNode() => baseElement.computeNode(); | |
| 4529 | |
| 4530 @override | |
| 4531 String toString() { | |
| 4532 StringBuffer buffer = new StringBuffer(); | |
| 4533 buffer.write(baseElement.displayName); | |
| 4534 (type as FunctionTypeImpl).appendTo(buffer); | |
| 4535 return buffer.toString(); | |
| 4536 } | |
| 4537 | |
| 4538 /** | |
| 4539 * If the given [method]'s type is different when any type parameters from the | |
| 4540 * defining type's declaration are replaced with the actual type arguments | |
| 4541 * from the [definingType], create a method member representing the given | |
| 4542 * method. Return the member that was created, or the base method if no member | |
| 4543 * was created. | |
| 4544 */ | |
| 4545 static MethodElement from( | |
| 4546 MethodElement method, ParameterizedType definingType) { | |
| 4547 if (method == null || definingType.typeArguments.length == 0) { | |
| 4548 return method; | |
| 4549 } | |
| 4550 FunctionType baseType = method.type; | |
| 4551 List<DartType> argumentTypes = definingType.typeArguments; | |
| 4552 List<DartType> parameterTypes = | |
| 4553 TypeParameterTypeImpl.getTypes(definingType.typeParameters); | |
| 4554 FunctionType substitutedType = | |
| 4555 baseType.substitute2(argumentTypes, parameterTypes); | |
| 4556 if (baseType == substitutedType) { | |
| 4557 return method; | |
| 4558 } | |
| 4559 return new MethodMember(method, definingType, substitutedType); | |
| 4560 } | |
| 4561 } | |
| 4562 | |
| 4563 /** | |
| 4529 * The type of a function, method, constructor, getter, or setter. Function | 4564 * The type of a function, method, constructor, getter, or setter. Function |
| 4530 * types come in three variations: | 4565 * types come in three variations: |
| 4531 * | 4566 * |
| 4532 * * The types of functions that only have required parameters. These have the | 4567 * * The types of functions that only have required parameters. These have the |
| 4533 * general form <i>(T<sub>1</sub>, …, T<sub>n</sub>) → T</i>. | 4568 * general form <i>(T<sub>1</sub>, …, T<sub>n</sub>) → T</i>. |
| 4534 * * The types of functions with optional positional parameters. These have the | 4569 * * The types of functions with optional positional parameters. These have the |
| 4535 * general form <i>(T<sub>1</sub>, …, T<sub>n</sub>, [T<sub>n+1</sub> | 4570 * general form <i>(T<sub>1</sub>, …, T<sub>n</sub>, [T<sub>n+1</sub> |
| 4536 * …, T<sub>n+k</sub>]) → T</i>. | 4571 * …, T<sub>n+k</sub>]) → T</i>. |
| 4537 * * The types of functions with named parameters. These have the general form | 4572 * * The types of functions with named parameters. These have the general form |
| 4538 * <i>(T<sub>1</sub>, …, T<sub>n</sub>, {T<sub>x1</sub> x1, …, | 4573 * <i>(T<sub>1</sub>, …, T<sub>n</sub>, {T<sub>x1</sub> x1, …, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4663 * `substitute(argumentTypes, getTypeArguments())`. | 4698 * `substitute(argumentTypes, getTypeArguments())`. |
| 4664 */ | 4699 */ |
| 4665 @deprecated // use instantiate | 4700 @deprecated // use instantiate |
| 4666 FunctionType substitute3(List<DartType> argumentTypes); | 4701 FunctionType substitute3(List<DartType> argumentTypes); |
| 4667 } | 4702 } |
| 4668 | 4703 |
| 4669 /** | 4704 /** |
| 4670 * A function type alias (`typedef`). | 4705 * A function type alias (`typedef`). |
| 4671 */ | 4706 */ |
| 4672 abstract class FunctionTypeAliasElement | 4707 abstract class FunctionTypeAliasElement |
| 4673 implements TypeDefiningElement, TypeParameterizedElement { | 4708 implements TypeDefiningElement, FunctionTypedElement { |
| 4674 /** | 4709 /** |
| 4675 * An empty array of type alias elements. | 4710 * An empty array of type alias elements. |
| 4676 */ | 4711 */ |
| 4677 static List<FunctionTypeAliasElement> EMPTY_LIST = | 4712 static List<FunctionTypeAliasElement> EMPTY_LIST = |
| 4678 new List<FunctionTypeAliasElement>(0); | 4713 new List<FunctionTypeAliasElement>(0); |
| 4679 | 4714 |
| 4680 /** | 4715 /** |
| 4681 * Return the compilation unit in which this type alias is defined. | 4716 * Return the compilation unit in which this type alias is defined. |
| 4682 */ | 4717 */ |
| 4683 @override | 4718 @override |
| 4684 CompilationUnitElement get enclosingElement; | 4719 CompilationUnitElement get enclosingElement; |
| 4685 | 4720 |
| 4686 /** | 4721 /** |
| 4687 * Return a list containing all of the parameters defined by this type alias. | |
| 4688 */ | |
| 4689 List<ParameterElement> get parameters; | |
| 4690 | |
| 4691 /** | |
| 4692 * Return the return type defined by this type alias. | |
| 4693 */ | |
| 4694 DartType get returnType; | |
| 4695 | |
| 4696 @override | |
| 4697 FunctionType get type; | |
| 4698 | |
| 4699 /** | |
| 4700 * Return the resolved function type alias node that declares this element. | 4722 * Return the resolved function type alias node that declares this element. |
| 4701 * | 4723 * |
| 4702 * This method is expensive, because resolved AST might be evicted from cache, | 4724 * This method is expensive, because resolved AST might be evicted from cache, |
| 4703 * so parsing and resolving will be performed. | 4725 * so parsing and resolving will be performed. |
| 4704 */ | 4726 */ |
| 4705 @override | 4727 @override |
| 4706 FunctionTypeAlias computeNode(); | 4728 FunctionTypeAlias computeNode(); |
| 4707 } | 4729 } |
| 4708 | 4730 |
| 4709 /** | 4731 /** |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4847 | 4869 |
| 4848 @override | 4870 @override |
| 4849 void visitChildren(ElementVisitor visitor) { | 4871 void visitChildren(ElementVisitor visitor) { |
| 4850 super.visitChildren(visitor); | 4872 super.visitChildren(visitor); |
| 4851 safelyVisitChildren(_parameters, visitor); | 4873 safelyVisitChildren(_parameters, visitor); |
| 4852 safelyVisitChildren(_typeParameters, visitor); | 4874 safelyVisitChildren(_typeParameters, visitor); |
| 4853 } | 4875 } |
| 4854 } | 4876 } |
| 4855 | 4877 |
| 4856 /** | 4878 /** |
| 4879 * An element that has a [FunctionType] as its [type]. | |
| 4880 * | |
| 4881 * This also provides convenient access to the parameters and return type. | |
| 4882 */ | |
| 4883 abstract class FunctionTypedElement implements TypeParameterizedElement { | |
| 4884 /** | |
| 4885 * Return a list containing all of the parameters defined by this executable | |
| 4886 * element. | |
| 4887 */ | |
| 4888 List<ParameterElement> get parameters; | |
| 4889 | |
| 4890 /** | |
| 4891 * Return the return type defined by this element. If the element model is | |
| 4892 * fully populated, then the [returnType] will not be `null`, even | |
| 4893 * if no return type was explicitly specified. | |
| 4894 */ | |
| 4895 DartType get returnType; | |
| 4896 | |
| 4897 /** | |
| 4898 * Return the type of function defined by this element. | |
| 4899 */ | |
| 4900 FunctionType get type; | |
| 4901 } | |
| 4902 | |
| 4903 /** | |
| 4857 * The type of a function, method, constructor, getter, or setter. | 4904 * The type of a function, method, constructor, getter, or setter. |
| 4858 */ | 4905 */ |
| 4859 class FunctionTypeImpl extends TypeImpl implements FunctionType { | 4906 class FunctionTypeImpl extends TypeImpl implements FunctionType { |
| 4860 /** | 4907 /** |
| 4861 * The list of [typeArguments]. | 4908 * The list of [typeArguments]. |
| 4862 */ | 4909 */ |
| 4863 List<DartType> _typeArguments; | 4910 List<DartType> _typeArguments; |
| 4864 | 4911 |
| 4865 /** | 4912 /** |
| 4866 * The list of [typeParameters]. | 4913 * The list of [typeParameters]. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4951 typeParameters.map((t) => t.type), | 4998 typeParameters.map((t) => t.type), |
| 4952 growable: false); | 4999 growable: false); |
| 4953 } | 5000 } |
| 4954 } | 5001 } |
| 4955 _typeArguments = typeArguments; | 5002 _typeArguments = typeArguments; |
| 4956 } | 5003 } |
| 4957 | 5004 |
| 4958 /** | 5005 /** |
| 4959 * Return the base parameter elements of this function element. | 5006 * Return the base parameter elements of this function element. |
| 4960 */ | 5007 */ |
| 4961 List<ParameterElement> get baseParameters { | 5008 List<ParameterElement> get baseParameters => element.parameters; |
| 4962 Element element = this.element; | |
| 4963 if (element is ExecutableElement) { | |
| 4964 return element.parameters; | |
| 4965 } else { | |
| 4966 return (element as FunctionTypeAliasElement).parameters; | |
| 4967 } | |
| 4968 } | |
| 4969 | 5009 |
| 4970 /** | 5010 /** |
| 4971 * Return the return type defined by this function's element. | 5011 * Return the return type defined by this function's element. |
| 4972 */ | 5012 */ |
| 4973 DartType get baseReturnType { | 5013 DartType get baseReturnType => element.returnType; |
| 4974 Element element = this.element; | |
| 4975 if (element is ExecutableElement) { | |
| 4976 return element.returnType; | |
| 4977 } else { | |
| 4978 return (element as FunctionTypeAliasElement).returnType; | |
| 4979 } | |
| 4980 } | |
| 4981 | 5014 |
| 4982 @override | 5015 @override |
| 4983 List<TypeParameterElement> get boundTypeParameters => _boundTypeParameters; | 5016 List<TypeParameterElement> get boundTypeParameters => _boundTypeParameters; |
| 4984 | 5017 |
| 4985 @override | 5018 @override |
| 4986 String get displayName { | 5019 String get displayName { |
| 4987 String name = this.name; | 5020 String name = this.name; |
| 4988 if (name == null || name.length == 0) { | 5021 if (name == null || name.length == 0) { |
| 4989 // Function types have an empty name when they are defined implicitly by | 5022 // Function types have an empty name when they are defined implicitly by |
| 4990 // either a closure or as part of a parameter declaration. | 5023 // either a closure or as part of a parameter declaration. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5047 buffer.write("null"); | 5080 buffer.write("null"); |
| 5048 } else { | 5081 } else { |
| 5049 buffer.write(returnType.displayName); | 5082 buffer.write(returnType.displayName); |
| 5050 } | 5083 } |
| 5051 name = buffer.toString(); | 5084 name = buffer.toString(); |
| 5052 } | 5085 } |
| 5053 return name; | 5086 return name; |
| 5054 } | 5087 } |
| 5055 | 5088 |
| 5056 @override | 5089 @override |
| 5090 FunctionTypedElement get element => super.element; | |
| 5091 | |
| 5092 @override | |
| 5057 int get hashCode { | 5093 int get hashCode { |
| 5058 if (element == null) { | 5094 if (element == null) { |
| 5059 return 0; | 5095 return 0; |
| 5060 } | 5096 } |
| 5061 // Reference the arrays of parameters | 5097 // Reference the arrays of parameters |
| 5062 List<DartType> normalParameterTypes = this.normalParameterTypes; | 5098 List<DartType> normalParameterTypes = this.normalParameterTypes; |
| 5063 List<DartType> optionalParameterTypes = this.optionalParameterTypes; | 5099 List<DartType> optionalParameterTypes = this.optionalParameterTypes; |
| 5064 Iterable<DartType> namedParameterTypes = this.namedParameterTypes.values; | 5100 Iterable<DartType> namedParameterTypes = this.namedParameterTypes.values; |
| 5065 // Generate the hashCode | 5101 // Generate the hashCode |
| 5066 int code = (returnType as TypeImpl).hashCode; | 5102 int code = (returnType as TypeImpl).hashCode; |
| 5067 for (int i = 0; i < normalParameterTypes.length; i++) { | 5103 for (int i = 0; i < normalParameterTypes.length; i++) { |
| 5068 code = (code << 1) + (normalParameterTypes[i] as TypeImpl).hashCode; | 5104 code = (code << 1) + (normalParameterTypes[i] as TypeImpl).hashCode; |
| 5069 } | 5105 } |
| 5070 for (int i = 0; i < optionalParameterTypes.length; i++) { | 5106 for (int i = 0; i < optionalParameterTypes.length; i++) { |
| 5071 code = (code << 1) + (optionalParameterTypes[i] as TypeImpl).hashCode; | 5107 code = (code << 1) + (optionalParameterTypes[i] as TypeImpl).hashCode; |
| 5072 } | 5108 } |
| 5073 for (DartType type in namedParameterTypes) { | 5109 for (DartType type in namedParameterTypes) { |
| 5074 code = (code << 1) + (type as TypeImpl).hashCode; | 5110 code = (code << 1) + (type as TypeImpl).hashCode; |
| 5075 } | 5111 } |
| 5076 return code; | 5112 return code; |
| 5077 } | 5113 } |
| 5078 | 5114 |
| 5115 /** | |
| 5116 * The type arguments that were used to instantiate this function type, if | |
| 5117 * any, otherwise this will return an empty list. | |
| 5118 * | |
| 5119 * Given a function type `f`: | |
| 5120 * | |
| 5121 * f == f.originalFunction.instantiate(f.instantiatedTypeArguments) | |
| 5122 * | |
| 5123 * Will always hold. | |
| 5124 */ | |
| 5125 List<DartType> get instantiatedTypeArguments { | |
| 5126 int typeParameterCount = element.type.boundTypeParameters.length; | |
| 5127 if (typeParameterCount == 0) { | |
| 5128 return DartType.EMPTY_LIST; | |
| 5129 } | |
| 5130 // The substituted types at the end should be our bound type parameters. | |
| 5131 int skipCount = typeArguments.length - typeParameterCount; | |
| 5132 return new List<DartType>.from(typeArguments.skip(skipCount)); | |
| 5133 } | |
| 5134 | |
| 5079 @override | 5135 @override |
| 5080 Map<String, DartType> get namedParameterTypes { | 5136 Map<String, DartType> get namedParameterTypes { |
| 5081 LinkedHashMap<String, DartType> namedParameterTypes = | 5137 LinkedHashMap<String, DartType> namedParameterTypes = |
| 5082 new LinkedHashMap<String, DartType>(); | 5138 new LinkedHashMap<String, DartType>(); |
| 5083 List<ParameterElement> parameters = baseParameters; | 5139 List<ParameterElement> parameters = baseParameters; |
| 5084 if (parameters.length == 0) { | 5140 if (parameters.length == 0) { |
| 5085 return namedParameterTypes; | 5141 return namedParameterTypes; |
| 5086 } | 5142 } |
| 5087 List<DartType> typeParameters = | 5143 List<DartType> typeParameters = |
| 5088 TypeParameterTypeImpl.getTypes(this.typeParameters); | 5144 TypeParameterTypeImpl.getTypes(this.typeParameters); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5166 .substitute2(typeArguments, typeParameters, newPrune); | 5222 .substitute2(typeArguments, typeParameters, newPrune); |
| 5167 } else { | 5223 } else { |
| 5168 type = (type as TypeImpl).pruned(newPrune); | 5224 type = (type as TypeImpl).pruned(newPrune); |
| 5169 } | 5225 } |
| 5170 types.add(type); | 5226 types.add(type); |
| 5171 } | 5227 } |
| 5172 } | 5228 } |
| 5173 return types; | 5229 return types; |
| 5174 } | 5230 } |
| 5175 | 5231 |
| 5232 /** | |
| 5233 * If this is an instantiation of a generic function type, this will get | |
| 5234 * the original function from which it was instantiated. | |
| 5235 * | |
| 5236 * Otherwise, this will return `this`. | |
| 5237 */ | |
| 5238 FunctionTypeImpl get originalFunction { | |
| 5239 if (element.type.boundTypeParameters.isEmpty) { | |
| 5240 return this; | |
| 5241 } | |
| 5242 return (element.type as FunctionTypeImpl).substitute2(typeArguments, | |
| 5243 TypeParameterTypeImpl.getTypes(typeParameters), prunedTypedefs); | |
| 5244 } | |
| 5245 | |
| 5176 @override | 5246 @override |
| 5177 List<ParameterElement> get parameters { | 5247 List<ParameterElement> get parameters { |
| 5178 List<ParameterElement> baseParameters = this.baseParameters; | 5248 List<ParameterElement> baseParameters = this.baseParameters; |
| 5179 // no parameters, quick return | 5249 // no parameters, quick return |
| 5180 int parameterCount = baseParameters.length; | 5250 int parameterCount = baseParameters.length; |
| 5181 if (parameterCount == 0) { | 5251 if (parameterCount == 0) { |
| 5182 return baseParameters; | 5252 return baseParameters; |
| 5183 } | 5253 } |
| 5184 // create specialized parameters | 5254 // create specialized parameters |
| 5185 List<ParameterElement> specializedParameters = | 5255 List<ParameterElement> specializedParameters = |
| (...skipping 3305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8491 for (Element child in children) { | 8561 for (Element child in children) { |
| 8492 child.accept(visitor); | 8562 child.accept(visitor); |
| 8493 } | 8563 } |
| 8494 } | 8564 } |
| 8495 } | 8565 } |
| 8496 | 8566 |
| 8497 /** | 8567 /** |
| 8498 * Return the type that results from replacing the type parameters in the | 8568 * Return the type that results from replacing the type parameters in the |
| 8499 * given [type] with the type arguments associated with this member. | 8569 * given [type] with the type arguments associated with this member. |
| 8500 */ | 8570 */ |
| 8571 @deprecated | |
| 8501 DartType substituteFor(DartType type) { | 8572 DartType substituteFor(DartType type) { |
| 8502 if (type == null) { | 8573 if (type == null) { |
| 8503 return null; | 8574 return null; |
| 8504 } | 8575 } |
| 8505 List<DartType> argumentTypes = _definingType.typeArguments; | 8576 List<DartType> argumentTypes = _definingType.typeArguments; |
| 8506 List<DartType> parameterTypes = | 8577 List<DartType> parameterTypes = |
| 8507 TypeParameterTypeImpl.getTypes(_definingType.typeParameters); | 8578 TypeParameterTypeImpl.getTypes(_definingType.typeParameters); |
| 8508 return type.substitute2(argumentTypes, parameterTypes); | 8579 return type.substitute2(argumentTypes, parameterTypes); |
| 8509 } | 8580 } |
| 8510 | 8581 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8639 getNodeMatching((node) => node is MethodDeclaration); | 8710 getNodeMatching((node) => node is MethodDeclaration); |
| 8640 } | 8711 } |
| 8641 | 8712 |
| 8642 /** | 8713 /** |
| 8643 * A method element defined in a parameterized type where the values of the type | 8714 * A method element defined in a parameterized type where the values of the type |
| 8644 * parameters are known. | 8715 * parameters are known. |
| 8645 */ | 8716 */ |
| 8646 class MethodMember extends ExecutableMember implements MethodElement { | 8717 class MethodMember extends ExecutableMember implements MethodElement { |
| 8647 /** | 8718 /** |
| 8648 * Initialize a newly created element to represent a constructor, based on the | 8719 * Initialize a newly created element to represent a constructor, based on the |
| 8649 * [baseElement], defined by the [definingType]. | 8720 * [baseElement], defined by the [definingType]. |
|
Leaf
2015/12/05 00:50:40
update comment.
Jennifer Messerly
2015/12/07 17:46:58
Done.
| |
| 8650 */ | 8721 */ |
| 8651 MethodMember(MethodElement baseElement, InterfaceType definingType) | 8722 MethodMember(MethodElement baseElement, InterfaceType definingType, |
| 8652 : super(baseElement, definingType); | 8723 [DartType type]) |
| 8724 : super(baseElement, definingType, type); | |
| 8653 | 8725 |
| 8654 @override | 8726 @override |
| 8655 MethodElement get baseElement => super.baseElement as MethodElement; | 8727 MethodElement get baseElement => super.baseElement as MethodElement; |
| 8656 | 8728 |
| 8657 @override | 8729 @override |
| 8658 ClassElement get enclosingElement => baseElement.enclosingElement; | 8730 ClassElement get enclosingElement => baseElement.enclosingElement; |
| 8659 | 8731 |
| 8660 @override | 8732 @override |
| 8661 accept(ElementVisitor visitor) => visitor.visitMethodElement(this); | 8733 accept(ElementVisitor visitor) => visitor.visitMethodElement(this); |
| 8662 | 8734 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8700 return method; | 8772 return method; |
| 8701 } | 8773 } |
| 8702 FunctionType baseType = method.type; | 8774 FunctionType baseType = method.type; |
| 8703 List<DartType> argumentTypes = definingType.typeArguments; | 8775 List<DartType> argumentTypes = definingType.typeArguments; |
| 8704 List<DartType> parameterTypes = definingType.element.type.typeArguments; | 8776 List<DartType> parameterTypes = definingType.element.type.typeArguments; |
| 8705 FunctionType substitutedType = | 8777 FunctionType substitutedType = |
| 8706 baseType.substitute2(argumentTypes, parameterTypes); | 8778 baseType.substitute2(argumentTypes, parameterTypes); |
| 8707 if (baseType == substitutedType) { | 8779 if (baseType == substitutedType) { |
| 8708 return method; | 8780 return method; |
| 8709 } | 8781 } |
| 8710 // TODO(brianwilkerson) Consider caching the substituted type in the | 8782 return new MethodMember(method, definingType, substitutedType); |
| 8711 // instance. It would use more memory but speed up some operations. | |
| 8712 // We need to see how often the type is being re-computed. | |
| 8713 return new MethodMember(method, definingType); | |
| 8714 } | 8783 } |
| 8715 } | 8784 } |
| 8716 | 8785 |
| 8717 /** | 8786 /** |
| 8718 * The enumeration `Modifier` defines constants for all of the modifiers defined | 8787 * The enumeration `Modifier` defines constants for all of the modifiers defined |
| 8719 * by the Dart language and for a few additional flags that are useful. | 8788 * by the Dart language and for a few additional flags that are useful. |
| 8720 */ | 8789 */ |
| 8721 class Modifier extends Enum<Modifier> { | 8790 class Modifier extends Enum<Modifier> { |
| 8722 /** | 8791 /** |
| 8723 * Indicates that the modifier 'abstract' was applied to the element. | 8792 * Indicates that the modifier 'abstract' was applied to the element. |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9431 | 9500 |
| 9432 /** | 9501 /** |
| 9433 * A parameter element defined in a parameterized type where the values of the | 9502 * A parameter element defined in a parameterized type where the values of the |
| 9434 * type parameters are known. | 9503 * type parameters are known. |
| 9435 */ | 9504 */ |
| 9436 class ParameterMember extends VariableMember | 9505 class ParameterMember extends VariableMember |
| 9437 with ParameterElementMixin | 9506 with ParameterElementMixin |
| 9438 implements ParameterElement { | 9507 implements ParameterElement { |
| 9439 /** | 9508 /** |
| 9440 * Initialize a newly created element to represent a constructor, based on the | 9509 * Initialize a newly created element to represent a constructor, based on the |
| 9441 * [baseElement], defined by the [definingType]. | 9510 * [baseElement], defined by the [definingType]. |
|
Leaf
2015/12/05 00:50:40
update comment. I think here and elsewhere there
Jennifer Messerly
2015/12/07 17:46:58
Done.
| |
| 9442 */ | 9511 */ |
| 9443 ParameterMember(ParameterElement baseElement, ParameterizedType definingType) | 9512 ParameterMember(ParameterElement baseElement, ParameterizedType definingType, |
| 9444 : super(baseElement, definingType); | 9513 [DartType type]) |
| 9514 : super._(baseElement, definingType, type); | |
| 9445 | 9515 |
| 9446 @override | 9516 @override |
| 9447 ParameterElement get baseElement => super.baseElement as ParameterElement; | 9517 ParameterElement get baseElement => super.baseElement as ParameterElement; |
| 9448 | 9518 |
| 9449 @override | 9519 @override |
| 9450 String get defaultValueCode => baseElement.defaultValueCode; | 9520 String get defaultValueCode => baseElement.defaultValueCode; |
| 9451 | 9521 |
| 9452 @override | 9522 @override |
| 9453 Element get enclosingElement => baseElement.enclosingElement; | 9523 Element get enclosingElement => baseElement.enclosingElement; |
| 9454 | 9524 |
| 9455 @override | 9525 @override |
| 9456 int get hashCode => baseElement.hashCode; | 9526 int get hashCode => baseElement.hashCode; |
| 9457 | 9527 |
| 9458 @override | 9528 @override |
| 9459 bool get isInitializingFormal => baseElement.isInitializingFormal; | 9529 bool get isInitializingFormal => baseElement.isInitializingFormal; |
| 9460 | 9530 |
| 9461 @override | 9531 @override |
| 9462 ParameterKind get parameterKind => baseElement.parameterKind; | 9532 ParameterKind get parameterKind => baseElement.parameterKind; |
| 9463 | 9533 |
| 9464 @override | 9534 @override |
| 9465 List<ParameterElement> get parameters { | 9535 List<ParameterElement> get parameters { |
| 9466 List<ParameterElement> baseParameters = baseElement.parameters; | 9536 DartType type = this.type; |
| 9467 int parameterCount = baseParameters.length; | 9537 if (type is FunctionType) { |
| 9468 if (parameterCount == 0) { | 9538 return type.parameters; |
| 9469 return baseParameters; | |
| 9470 } | 9539 } |
| 9471 List<ParameterElement> parameterizedParameters = | 9540 return ParameterElement.EMPTY_LIST; |
| 9472 new List<ParameterElement>(parameterCount); | |
| 9473 for (int i = 0; i < parameterCount; i++) { | |
| 9474 parameterizedParameters[i] = | |
| 9475 ParameterMember.from(baseParameters[i], definingType); | |
| 9476 } | |
| 9477 return parameterizedParameters; | |
| 9478 } | 9541 } |
| 9479 | 9542 |
| 9480 @override | 9543 @override |
| 9481 List<TypeParameterElement> get typeParameters => baseElement.typeParameters; | 9544 List<TypeParameterElement> get typeParameters => baseElement.typeParameters; |
| 9482 | 9545 |
| 9483 @override | 9546 @override |
| 9484 SourceRange get visibleRange => baseElement.visibleRange; | 9547 SourceRange get visibleRange => baseElement.visibleRange; |
| 9485 | 9548 |
| 9549 // TODO(jmesserly): this equality is broken. It should consider the defining | |
| 9550 // type as well, otherwise we're dropping the substitution. | |
| 9486 @override | 9551 @override |
| 9487 bool operator ==(Object object) => | 9552 bool operator ==(Object object) => |
| 9488 object is ParameterMember && baseElement == object.baseElement; | 9553 object is ParameterMember && baseElement == object.baseElement; |
| 9489 | 9554 |
| 9490 @override | 9555 @override |
| 9491 accept(ElementVisitor visitor) => visitor.visitParameterElement(this); | 9556 accept(ElementVisitor visitor) => visitor.visitParameterElement(this); |
| 9492 | 9557 |
| 9493 @override | 9558 @override |
| 9494 FormalParameter computeNode() => baseElement.computeNode(); | 9559 FormalParameter computeNode() => baseElement.computeNode(); |
| 9495 | 9560 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9542 * parameter if no member was created. | 9607 * parameter if no member was created. |
| 9543 */ | 9608 */ |
| 9544 static ParameterElement from( | 9609 static ParameterElement from( |
| 9545 ParameterElement parameter, ParameterizedType definingType) { | 9610 ParameterElement parameter, ParameterizedType definingType) { |
| 9546 if (parameter == null || definingType.typeArguments.length == 0) { | 9611 if (parameter == null || definingType.typeArguments.length == 0) { |
| 9547 return parameter; | 9612 return parameter; |
| 9548 } | 9613 } |
| 9549 // Check if parameter type depends on defining type type arguments. | 9614 // Check if parameter type depends on defining type type arguments. |
| 9550 // It is possible that we did not resolve field formal parameter yet, | 9615 // It is possible that we did not resolve field formal parameter yet, |
| 9551 // so skip this check for it. | 9616 // so skip this check for it. |
| 9552 bool isFieldFormal = parameter is FieldFormalParameterElement; | 9617 if (parameter is FieldFormalParameterElement) { |
| 9553 if (!isFieldFormal) { | 9618 return new FieldFormalParameterMember(parameter, definingType); |
| 9619 } else { | |
| 9554 DartType baseType = parameter.type; | 9620 DartType baseType = parameter.type; |
| 9555 List<DartType> argumentTypes = definingType.typeArguments; | 9621 List<DartType> argumentTypes = definingType.typeArguments; |
| 9556 List<DartType> parameterTypes = | 9622 List<DartType> parameterTypes = |
| 9557 TypeParameterTypeImpl.getTypes(definingType.typeParameters); | 9623 TypeParameterTypeImpl.getTypes(definingType.typeParameters); |
| 9558 DartType substitutedType = | 9624 DartType substitutedType = |
| 9559 baseType.substitute2(argumentTypes, parameterTypes); | 9625 baseType.substitute2(argumentTypes, parameterTypes); |
| 9560 if (baseType == substitutedType) { | 9626 if (baseType == substitutedType) { |
| 9561 return parameter; | 9627 return parameter; |
| 9562 } | 9628 } |
| 9629 return new ParameterMember(parameter, definingType, substitutedType); | |
| 9563 } | 9630 } |
| 9564 // TODO(brianwilkerson) Consider caching the substituted type in the | |
| 9565 // instance. It would use more memory but speed up some operations. | |
| 9566 // We need to see how often the type is being re-computed. | |
| 9567 if (isFieldFormal) { | |
| 9568 return new FieldFormalParameterMember( | |
| 9569 parameter as FieldFormalParameterElement, definingType); | |
| 9570 } | |
| 9571 return new ParameterMember(parameter, definingType); | |
| 9572 } | 9631 } |
| 9573 } | 9632 } |
| 9574 | 9633 |
| 9575 /** | 9634 /** |
| 9576 * A prefix used to import one or more libraries into another library. | 9635 * A prefix used to import one or more libraries into another library. |
| 9577 */ | 9636 */ |
| 9578 abstract class PrefixElement implements Element { | 9637 abstract class PrefixElement implements Element { |
| 9579 /** | 9638 /** |
| 9580 * An empty list of prefix elements. | 9639 * An empty list of prefix elements. |
| 9581 */ | 9640 */ |
| (...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11188 super.visitChildren(visitor); | 11247 super.visitChildren(visitor); |
| 11189 safelyVisitChild(_initializer, visitor); | 11248 safelyVisitChild(_initializer, visitor); |
| 11190 } | 11249 } |
| 11191 } | 11250 } |
| 11192 | 11251 |
| 11193 /** | 11252 /** |
| 11194 * A variable element defined in a parameterized type where the values of the | 11253 * A variable element defined in a parameterized type where the values of the |
| 11195 * type parameters are known. | 11254 * type parameters are known. |
| 11196 */ | 11255 */ |
| 11197 abstract class VariableMember extends Member implements VariableElement { | 11256 abstract class VariableMember extends Member implements VariableElement { |
| 11257 @override | |
| 11258 final DartType type; | |
| 11259 | |
| 11198 /** | 11260 /** |
| 11199 * Initialize a newly created element to represent a constructor, based on the | 11261 * Initialize a newly created element to represent a constructor, based on the |
| 11200 * [baseElement], defined by the [definingType]. | 11262 * [baseElement], defined by the [definingType]. |
|
Leaf
2015/12/05 00:50:40
comment.
Jennifer Messerly
2015/12/07 17:46:58
Done.
| |
| 11201 */ | 11263 */ |
| 11202 VariableMember(VariableElement baseElement, ParameterizedType definingType) | 11264 VariableMember(VariableElement baseElement, ParameterizedType definingType, |
| 11203 : super(baseElement, definingType); | 11265 [DartType type]) |
| 11266 : type = type ?? | |
| 11267 baseElement.type.substitute2(definingType.typeArguments, | |
| 11268 TypeParameterTypeImpl.getTypes(definingType.typeParameters)), | |
| 11269 super(baseElement, definingType); | |
| 11270 | |
| 11271 // TODO(jmesserly): this is temporary to allow the ParameterMember subclass. | |
| 11272 // Apparently mixins don't work with optional params. | |
| 11273 VariableMember._(VariableElement baseElement, ParameterizedType definingType, | |
| 11274 DartType type) | |
| 11275 : this(baseElement, definingType, type); | |
| 11204 | 11276 |
| 11205 @override | 11277 @override |
| 11206 VariableElement get baseElement => super.baseElement as VariableElement; | 11278 VariableElement get baseElement => super.baseElement as VariableElement; |
| 11207 | 11279 |
| 11208 @override | 11280 @override |
| 11209 DartObject get constantValue => baseElement.constantValue; | 11281 DartObject get constantValue => baseElement.constantValue; |
| 11210 | 11282 |
| 11211 @override | 11283 @override |
| 11212 bool get hasImplicitType => baseElement.hasImplicitType; | 11284 bool get hasImplicitType => baseElement.hasImplicitType; |
| 11213 | 11285 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 11232 baseElement.isPotentiallyMutatedInClosure; | 11304 baseElement.isPotentiallyMutatedInClosure; |
| 11233 | 11305 |
| 11234 @override | 11306 @override |
| 11235 bool get isPotentiallyMutatedInScope => | 11307 bool get isPotentiallyMutatedInScope => |
| 11236 baseElement.isPotentiallyMutatedInScope; | 11308 baseElement.isPotentiallyMutatedInScope; |
| 11237 | 11309 |
| 11238 @override | 11310 @override |
| 11239 bool get isStatic => baseElement.isStatic; | 11311 bool get isStatic => baseElement.isStatic; |
| 11240 | 11312 |
| 11241 @override | 11313 @override |
| 11242 DartType get type => substituteFor(baseElement.type); | |
| 11243 | |
| 11244 @override | |
| 11245 void visitChildren(ElementVisitor visitor) { | 11314 void visitChildren(ElementVisitor visitor) { |
| 11246 // TODO(brianwilkerson) We need to finish implementing the accessors used | 11315 // TODO(brianwilkerson) We need to finish implementing the accessors used |
| 11247 // below so that we can safely invoke them. | 11316 // below so that we can safely invoke them. |
| 11248 super.visitChildren(visitor); | 11317 super.visitChildren(visitor); |
| 11249 safelyVisitChild(baseElement.initializer, visitor); | 11318 safelyVisitChild(baseElement.initializer, visitor); |
| 11250 } | 11319 } |
| 11251 } | 11320 } |
| 11252 | 11321 |
| 11253 /** | 11322 /** |
| 11254 * The type `void`. | 11323 * The type `void`. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11321 | 11390 |
| 11322 @override | 11391 @override |
| 11323 void visitElement(Element element) { | 11392 void visitElement(Element element) { |
| 11324 int offset = element.nameOffset; | 11393 int offset = element.nameOffset; |
| 11325 if (offset != -1) { | 11394 if (offset != -1) { |
| 11326 map[offset] = element; | 11395 map[offset] = element; |
| 11327 } | 11396 } |
| 11328 super.visitElement(element); | 11397 super.visitElement(element); |
| 11329 } | 11398 } |
| 11330 } | 11399 } |
| OLD | NEW |