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/constant/value.dart'; | 8 import 'package:analyzer/dart/constant/value.dart'; |
9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 break; | 735 break; |
736 } | 736 } |
737 return '$left$type ${baseElement.displayName}$right'; | 737 return '$left$type ${baseElement.displayName}$right'; |
738 } | 738 } |
739 | 739 |
740 @override | 740 @override |
741 void visitChildren(ElementVisitor visitor) { | 741 void visitChildren(ElementVisitor visitor) { |
742 super.visitChildren(visitor); | 742 super.visitChildren(visitor); |
743 safelyVisitChildren(parameters, visitor); | 743 safelyVisitChildren(parameters, visitor); |
744 } | 744 } |
745 | |
746 /** | |
747 * If the given [parameter]'s type is different when any type parameters from | |
748 * the defining type's declaration are replaced with the actual type | |
749 * arguments from the [definingType], create a parameter member representing | |
750 * the given parameter. Return the member that was created, or the base | |
751 * parameter if no member was created. | |
752 */ | |
753 static ParameterElement from( | |
754 ParameterElement parameter, ParameterizedType definingType) { | |
755 if (parameter == null || definingType.typeArguments.length == 0) { | |
756 return parameter; | |
757 } | |
758 // Check if parameter type depends on defining type type arguments. | |
759 // It is possible that we did not resolve field formal parameter yet, | |
760 // so skip this check for it. | |
761 if (parameter is FieldFormalParameterElement) { | |
762 return new FieldFormalParameterMember(parameter, definingType); | |
763 } else { | |
764 DartType baseType = parameter.type; | |
765 List<DartType> argumentTypes = definingType.typeArguments; | |
766 List<DartType> parameterTypes = | |
767 TypeParameterTypeImpl.getTypes(definingType.typeParameters); | |
768 DartType substitutedType = | |
769 baseType.substitute2(argumentTypes, parameterTypes); | |
770 return new ParameterMember(parameter, definingType, substitutedType); | |
771 } | |
772 } | |
773 } | 745 } |
774 | 746 |
775 /** | 747 /** |
776 * A property accessor element defined in a parameterized type where the values | 748 * A property accessor element defined in a parameterized type where the values |
777 * of the type parameters are known. | 749 * of the type parameters are known. |
778 */ | 750 */ |
779 class PropertyAccessorMember extends ExecutableMember | 751 class PropertyAccessorMember extends ExecutableMember |
780 implements PropertyAccessorElement { | 752 implements PropertyAccessorElement { |
781 /** | 753 /** |
782 * Initialize a newly created element to represent a property, based on the | 754 * Initialize a newly created element to represent a property, based on the |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 DartObject computeConstantValue() => baseElement.computeConstantValue(); | 1021 DartObject computeConstantValue() => baseElement.computeConstantValue(); |
1050 | 1022 |
1051 @override | 1023 @override |
1052 void visitChildren(ElementVisitor visitor) { | 1024 void visitChildren(ElementVisitor visitor) { |
1053 // TODO(brianwilkerson) We need to finish implementing the accessors used | 1025 // TODO(brianwilkerson) We need to finish implementing the accessors used |
1054 // below so that we can safely invoke them. | 1026 // below so that we can safely invoke them. |
1055 super.visitChildren(visitor); | 1027 super.visitChildren(visitor); |
1056 baseElement.initializer?.accept(visitor); | 1028 baseElement.initializer?.accept(visitor); |
1057 } | 1029 } |
1058 } | 1030 } |
OLD | NEW |