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 analyzer.src.dart.element.member; | 5 library analyzer.src.dart.element.member; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
9 import 'package:analyzer/dart/element/type.dart'; | 9 import 'package:analyzer/dart/element/type.dart'; |
10 import 'package:analyzer/src/dart/element/element.dart'; | 10 import 'package:analyzer/src/dart/element/element.dart'; |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
891 return true; | 891 return true; |
892 } | 892 } |
893 } | 893 } |
894 } | 894 } |
895 } | 895 } |
896 return false; | 896 return false; |
897 } | 897 } |
898 } | 898 } |
899 | 899 |
900 /** | 900 /** |
901 * A type parameter defined inside of another parameterized type, where the | |
902 * values of the enclosing type parameters are known. | |
903 * | |
904 * For example: | |
905 * | |
906 * class C<T> { | |
907 * S m<S extends T>(S s); | |
908 * } | |
909 * | |
910 * If we have `C<num>.m` and we ask for the type parameter "S", we should get | |
911 * `<S extends num>` instead of `<S extends T>`. This is how the parameter | |
912 * and return types work, see: [FunctionType.parameters], | |
913 * [FunctionType.returnType], and [ParameterMember]. | |
914 */ | |
915 class TypeParameterMember extends Member implements TypeParameterElement { | |
916 @override | |
917 final DartType bound; | |
918 | |
919 TypeParameterMember( | |
920 TypeParameterElement baseElement, DartType definingType, this.bound) | |
921 : super(baseElement, definingType); | |
922 | |
923 @override | |
924 TypeParameterElement get baseElement => | |
925 super.baseElement as TypeParameterElement; | |
926 | |
927 @override | |
928 Element get enclosingElement => baseElement.enclosingElement; | |
929 | |
930 @override | |
931 TypeParameterType get type => baseElement.type; | |
932 | |
933 @override | |
934 accept(ElementVisitor visitor) => visitor.visitTypeParameterElement(this); | |
935 | |
936 /** | |
937 * If the given [parameter]'s type is different when any type parameters from | |
938 * the defining type's declaration are replaced with the actual type | |
939 * arguments from the [definingType], create a parameter member representing | |
940 * the given parameter. Return the member that was created, or the base | |
941 * parameter if no member was created. | |
942 */ | |
943 static TypeParameterElement from( | |
Brian Wilkerson
2016/02/10 22:55:46
nit: I think our sorter sorts static methods to th
Jennifer Messerly
2016/02/11 20:13:16
Hmmm. It seems to think the file is already sorted
| |
944 TypeParameterElement parameter, ParameterizedType definingType) { | |
945 if (parameter?.bound == null || definingType.typeArguments.isEmpty) { | |
946 return parameter; | |
947 } | |
948 | |
949 DartType bound = parameter.bound; | |
950 List<DartType> argumentTypes = definingType.typeArguments; | |
951 List<DartType> parameterTypes = | |
952 TypeParameterTypeImpl.getTypes(definingType.typeParameters); | |
953 DartType substitutedBound = | |
954 bound.substitute2(argumentTypes, parameterTypes); | |
955 if (bound == substitutedBound) { | |
956 return parameter; | |
957 } | |
958 return new TypeParameterMember(parameter, definingType, substitutedBound); | |
959 } | |
960 } | |
961 | |
962 /** | |
901 * A variable element defined in a parameterized type where the values of the | 963 * A variable element defined in a parameterized type where the values of the |
902 * type parameters are known. | 964 * type parameters are known. |
903 */ | 965 */ |
904 abstract class VariableMember extends Member implements VariableElement { | 966 abstract class VariableMember extends Member implements VariableElement { |
905 @override | 967 @override |
906 final DartType type; | 968 final DartType type; |
907 | 969 |
908 /** | 970 /** |
909 * Initialize a newly created element to represent a variable, based on the | 971 * Initialize a newly created element to represent a variable, based on the |
910 * [baseElement], defined by the [definingType]. | 972 * [baseElement], defined by the [definingType]. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
959 bool get isStatic => baseElement.isStatic; | 1021 bool get isStatic => baseElement.isStatic; |
960 | 1022 |
961 @override | 1023 @override |
962 void visitChildren(ElementVisitor visitor) { | 1024 void visitChildren(ElementVisitor visitor) { |
963 // TODO(brianwilkerson) We need to finish implementing the accessors used | 1025 // TODO(brianwilkerson) We need to finish implementing the accessors used |
964 // below so that we can safely invoke them. | 1026 // below so that we can safely invoke them. |
965 super.visitChildren(visitor); | 1027 super.visitChildren(visitor); |
966 safelyVisitChild(baseElement.initializer, visitor); | 1028 safelyVisitChild(baseElement.initializer, visitor); |
967 } | 1029 } |
968 } | 1030 } |
OLD | NEW |