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.resolver.element_resolver; | 5 library engine.resolver.element_resolver; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'ast.dart'; | 9 import 'ast.dart'; |
10 import 'element.dart'; | 10 import 'element.dart'; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 String methodName = operatorType.lexeme; | 154 String methodName = operatorType.lexeme; |
155 DartType staticType = _getStaticType(leftHandSide); | 155 DartType staticType = _getStaticType(leftHandSide); |
156 MethodElement staticMethod = | 156 MethodElement staticMethod = |
157 _lookUpMethod(leftHandSide, staticType, methodName); | 157 _lookUpMethod(leftHandSide, staticType, methodName); |
158 node.staticElement = staticMethod; | 158 node.staticElement = staticMethod; |
159 DartType propagatedType = _getPropagatedType(leftHandSide); | 159 DartType propagatedType = _getPropagatedType(leftHandSide); |
160 MethodElement propagatedMethod = | 160 MethodElement propagatedMethod = |
161 _lookUpMethod(leftHandSide, propagatedType, methodName); | 161 _lookUpMethod(leftHandSide, propagatedType, methodName); |
162 node.propagatedElement = propagatedMethod; | 162 node.propagatedElement = propagatedMethod; |
163 if (_shouldReportMissingMember(staticType, staticMethod)) { | 163 if (_shouldReportMissingMember(staticType, staticMethod)) { |
164 _recordUndefinedToken(staticType.element, | 164 _recordUndefinedToken( |
165 StaticTypeWarningCode.UNDEFINED_METHOD, operator, [ | 165 staticType.element, |
166 methodName, | 166 StaticTypeWarningCode.UNDEFINED_METHOD, |
167 staticType.displayName | 167 operator, |
168 ]); | 168 [methodName, staticType.displayName]); |
169 } else if (_enableHints && | 169 } else if (_enableHints && |
170 _shouldReportMissingMember(propagatedType, propagatedMethod) && | 170 _shouldReportMissingMember(propagatedType, propagatedMethod) && |
171 !_memberFoundInSubclass( | 171 !_memberFoundInSubclass( |
172 propagatedType.element, methodName, true, false)) { | 172 propagatedType.element, methodName, true, false)) { |
173 _recordUndefinedToken(propagatedType.element, | 173 _recordUndefinedToken( |
174 HintCode.UNDEFINED_METHOD, operator, [ | 174 propagatedType.element, |
175 methodName, | 175 HintCode.UNDEFINED_METHOD, |
176 propagatedType.displayName | 176 operator, |
177 ]); | 177 [methodName, propagatedType.displayName]); |
178 } | 178 } |
179 } | 179 } |
180 } | 180 } |
181 return null; | 181 return null; |
182 } | 182 } |
183 | 183 |
184 @override | 184 @override |
185 Object visitBinaryExpression(BinaryExpression node) { | 185 Object visitBinaryExpression(BinaryExpression node) { |
186 sc.Token operator = node.operator; | 186 sc.Token operator = node.operator; |
187 if (operator.isUserDefinableOperator) { | 187 if (operator.isUserDefinableOperator) { |
188 _resolveBinaryExpression(node, operator.lexeme); | 188 _resolveBinaryExpression(node, operator.lexeme); |
189 } else if (operator.type == sc.TokenType.BANG_EQ) { | 189 } else if (operator.type == sc.TokenType.BANG_EQ) { |
190 _resolveBinaryExpression(node, sc.TokenType.EQ_EQ.lexeme); | 190 _resolveBinaryExpression(node, sc.TokenType.EQ_EQ.lexeme); |
191 } | 191 } |
192 return null; | 192 return null; |
193 } | 193 } |
194 | 194 |
195 @override | 195 @override |
196 Object visitBreakStatement(BreakStatement node) { | 196 Object visitBreakStatement(BreakStatement node) { |
197 node.target = _lookupBreakOrContinueTarget(node, node.label, false); | 197 node.target = _lookupBreakOrContinueTarget(node, node.label, false); |
198 return null; | 198 return null; |
199 } | 199 } |
200 | 200 |
201 @override | 201 @override |
202 Object visitClassDeclaration(ClassDeclaration node) { | 202 Object visitClassDeclaration(ClassDeclaration node) { |
203 setMetadata(node.element, node); | 203 setMetadata(node.element, node); |
204 return null; | 204 return null; |
205 } | 205 } |
| 206 |
206 @override | 207 @override |
207 Object visitClassTypeAlias(ClassTypeAlias node) { | 208 Object visitClassTypeAlias(ClassTypeAlias node) { |
208 setMetadata(node.element, node); | 209 setMetadata(node.element, node); |
209 return null; | 210 return null; |
210 } | 211 } |
211 | 212 |
212 @override | 213 @override |
213 Object visitCommentReference(CommentReference node) { | 214 Object visitCommentReference(CommentReference node) { |
214 Identifier identifier = node.identifier; | 215 Identifier identifier = node.identifier; |
215 if (identifier is SimpleIdentifier) { | 216 if (identifier is SimpleIdentifier) { |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 if (isInGetterContext && isInSetterContext) { | 488 if (isInGetterContext && isInSetterContext) { |
488 // lookup setter | 489 // lookup setter |
489 MethodElement setterStaticMethod = | 490 MethodElement setterStaticMethod = |
490 _lookUpMethod(target, staticType, setterMethodName); | 491 _lookUpMethod(target, staticType, setterMethodName); |
491 MethodElement setterPropagatedMethod = | 492 MethodElement setterPropagatedMethod = |
492 _lookUpMethod(target, propagatedType, setterMethodName); | 493 _lookUpMethod(target, propagatedType, setterMethodName); |
493 // set setter element | 494 // set setter element |
494 node.staticElement = setterStaticMethod; | 495 node.staticElement = setterStaticMethod; |
495 node.propagatedElement = setterPropagatedMethod; | 496 node.propagatedElement = setterPropagatedMethod; |
496 // generate undefined method warning | 497 // generate undefined method warning |
497 _checkForUndefinedIndexOperator(node, target, getterMethodName, | 498 _checkForUndefinedIndexOperator( |
498 setterStaticMethod, setterPropagatedMethod, staticType, | 499 node, |
| 500 target, |
| 501 getterMethodName, |
| 502 setterStaticMethod, |
| 503 setterPropagatedMethod, |
| 504 staticType, |
499 propagatedType); | 505 propagatedType); |
500 // lookup getter method | 506 // lookup getter method |
501 MethodElement getterStaticMethod = | 507 MethodElement getterStaticMethod = |
502 _lookUpMethod(target, staticType, getterMethodName); | 508 _lookUpMethod(target, staticType, getterMethodName); |
503 MethodElement getterPropagatedMethod = | 509 MethodElement getterPropagatedMethod = |
504 _lookUpMethod(target, propagatedType, getterMethodName); | 510 _lookUpMethod(target, propagatedType, getterMethodName); |
505 // set getter element | 511 // set getter element |
506 AuxiliaryElements auxiliaryElements = | 512 AuxiliaryElements auxiliaryElements = |
507 new AuxiliaryElements(getterStaticMethod, getterPropagatedMethod); | 513 new AuxiliaryElements(getterStaticMethod, getterPropagatedMethod); |
508 node.auxiliaryElements = auxiliaryElements; | 514 node.auxiliaryElements = auxiliaryElements; |
509 // generate undefined method warning | 515 // generate undefined method warning |
510 _checkForUndefinedIndexOperator(node, target, getterMethodName, | 516 _checkForUndefinedIndexOperator( |
511 getterStaticMethod, getterPropagatedMethod, staticType, | 517 node, |
| 518 target, |
| 519 getterMethodName, |
| 520 getterStaticMethod, |
| 521 getterPropagatedMethod, |
| 522 staticType, |
512 propagatedType); | 523 propagatedType); |
513 } else if (isInGetterContext) { | 524 } else if (isInGetterContext) { |
514 // lookup getter method | 525 // lookup getter method |
515 MethodElement staticMethod = | 526 MethodElement staticMethod = |
516 _lookUpMethod(target, staticType, getterMethodName); | 527 _lookUpMethod(target, staticType, getterMethodName); |
517 MethodElement propagatedMethod = | 528 MethodElement propagatedMethod = |
518 _lookUpMethod(target, propagatedType, getterMethodName); | 529 _lookUpMethod(target, propagatedType, getterMethodName); |
519 // set getter element | 530 // set getter element |
520 node.staticElement = staticMethod; | 531 node.staticElement = staticMethod; |
521 node.propagatedElement = propagatedMethod; | 532 node.propagatedElement = propagatedMethod; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 Element propagatedElement; | 596 Element propagatedElement; |
586 DartType staticType = null; | 597 DartType staticType = null; |
587 DartType propagatedType = null; | 598 DartType propagatedType = null; |
588 if (target == null) { | 599 if (target == null) { |
589 staticElement = _resolveInvokedElement(methodName); | 600 staticElement = _resolveInvokedElement(methodName); |
590 propagatedElement = null; | 601 propagatedElement = null; |
591 } else if (methodName.name == FunctionElement.LOAD_LIBRARY_NAME && | 602 } else if (methodName.name == FunctionElement.LOAD_LIBRARY_NAME && |
592 _isDeferredPrefix(target)) { | 603 _isDeferredPrefix(target)) { |
593 if (node.operator.type == sc.TokenType.QUESTION_PERIOD) { | 604 if (node.operator.type == sc.TokenType.QUESTION_PERIOD) { |
594 _resolver.reportErrorForNode( | 605 _resolver.reportErrorForNode( |
595 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, target, | 606 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, |
| 607 target, |
596 [(target as SimpleIdentifier).name]); | 608 [(target as SimpleIdentifier).name]); |
597 } | 609 } |
598 LibraryElement importedLibrary = _getImportedLibrary(target); | 610 LibraryElement importedLibrary = _getImportedLibrary(target); |
599 methodName.staticElement = importedLibrary.loadLibraryFunction; | 611 methodName.staticElement = importedLibrary.loadLibraryFunction; |
600 return null; | 612 return null; |
601 } else { | 613 } else { |
602 staticType = _getStaticType(target); | 614 staticType = _getStaticType(target); |
603 propagatedType = _getPropagatedType(target); | 615 propagatedType = _getPropagatedType(target); |
604 // | 616 // |
605 // If this method invocation is of the form 'C.m' where 'C' is a class, | 617 // If this method invocation is of the form 'C.m' where 'C' is a class, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 methodName.name == FunctionElement.CALL_METHOD_NAME) { | 726 methodName.name == FunctionElement.CALL_METHOD_NAME) { |
715 // TODO(brianwilkerson) Can we ever resolve the function being | 727 // TODO(brianwilkerson) Can we ever resolve the function being |
716 // invoked? | 728 // invoked? |
717 // resolveArgumentsToParameters(node.getArgumentList(), invokedFunction
); | 729 // resolveArgumentsToParameters(node.getArgumentList(), invokedFunction
); |
718 return null; | 730 return null; |
719 } | 731 } |
720 targetTypeName = targetType == null ? null : targetType.displayName; | 732 targetTypeName = targetType == null ? null : targetType.displayName; |
721 ErrorCode proxyErrorCode = (generatedWithTypePropagation | 733 ErrorCode proxyErrorCode = (generatedWithTypePropagation |
722 ? HintCode.UNDEFINED_METHOD | 734 ? HintCode.UNDEFINED_METHOD |
723 : StaticTypeWarningCode.UNDEFINED_METHOD); | 735 : StaticTypeWarningCode.UNDEFINED_METHOD); |
724 _recordUndefinedNode(targetType.element, proxyErrorCode, methodName, [ | 736 _recordUndefinedNode(targetType.element, proxyErrorCode, methodName, |
725 methodName.name, | 737 [methodName.name, targetTypeName]); |
726 targetTypeName | |
727 ]); | |
728 } | 738 } |
729 } else if (identical( | 739 } else if (identical( |
730 errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD)) { | 740 errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD)) { |
731 // Generate the type name. | 741 // Generate the type name. |
732 // The error code will never be generated via type propagation | 742 // The error code will never be generated via type propagation |
733 DartType targetType = _getStaticType(target); | 743 DartType targetType = _getStaticType(target); |
734 if (targetType is InterfaceType && !targetType.isObject) { | 744 if (targetType is InterfaceType && !targetType.isObject) { |
735 targetType = (targetType as InterfaceType).superclass; | 745 targetType = (targetType as InterfaceType).superclass; |
736 } | 746 } |
737 String targetTypeName = targetType == null ? null : targetType.name; | 747 String targetTypeName = targetType == null ? null : targetType.name; |
(...skipping 21 matching lines...) Expand all Loading... |
759 String methodName = _getPostfixOperator(node); | 769 String methodName = _getPostfixOperator(node); |
760 DartType staticType = _getStaticType(operand); | 770 DartType staticType = _getStaticType(operand); |
761 MethodElement staticMethod = _lookUpMethod(operand, staticType, methodName); | 771 MethodElement staticMethod = _lookUpMethod(operand, staticType, methodName); |
762 node.staticElement = staticMethod; | 772 node.staticElement = staticMethod; |
763 DartType propagatedType = _getPropagatedType(operand); | 773 DartType propagatedType = _getPropagatedType(operand); |
764 MethodElement propagatedMethod = | 774 MethodElement propagatedMethod = |
765 _lookUpMethod(operand, propagatedType, methodName); | 775 _lookUpMethod(operand, propagatedType, methodName); |
766 node.propagatedElement = propagatedMethod; | 776 node.propagatedElement = propagatedMethod; |
767 if (_shouldReportMissingMember(staticType, staticMethod)) { | 777 if (_shouldReportMissingMember(staticType, staticMethod)) { |
768 if (operand is SuperExpression) { | 778 if (operand is SuperExpression) { |
769 _recordUndefinedToken(staticType.element, | 779 _recordUndefinedToken( |
770 StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR, node.operator, [ | 780 staticType.element, |
771 methodName, | 781 StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR, |
772 staticType.displayName | 782 node.operator, |
773 ]); | 783 [methodName, staticType.displayName]); |
774 } else { | 784 } else { |
775 _recordUndefinedToken(staticType.element, | 785 _recordUndefinedToken( |
776 StaticTypeWarningCode.UNDEFINED_OPERATOR, node.operator, [ | 786 staticType.element, |
777 methodName, | 787 StaticTypeWarningCode.UNDEFINED_OPERATOR, |
778 staticType.displayName | 788 node.operator, |
779 ]); | 789 [methodName, staticType.displayName]); |
780 } | 790 } |
781 } else if (_enableHints && | 791 } else if (_enableHints && |
782 _shouldReportMissingMember(propagatedType, propagatedMethod) && | 792 _shouldReportMissingMember(propagatedType, propagatedMethod) && |
783 !_memberFoundInSubclass( | 793 !_memberFoundInSubclass( |
784 propagatedType.element, methodName, true, false)) { | 794 propagatedType.element, methodName, true, false)) { |
785 _recordUndefinedToken(propagatedType.element, HintCode.UNDEFINED_OPERATOR, | 795 _recordUndefinedToken(propagatedType.element, HintCode.UNDEFINED_OPERATOR, |
786 node.operator, [methodName, propagatedType.displayName]); | 796 node.operator, [methodName, propagatedType.displayName]); |
787 } | 797 } |
788 return null; | 798 return null; |
789 } | 799 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 DartType staticType = _getStaticType(operand); | 882 DartType staticType = _getStaticType(operand); |
873 MethodElement staticMethod = | 883 MethodElement staticMethod = |
874 _lookUpMethod(operand, staticType, methodName); | 884 _lookUpMethod(operand, staticType, methodName); |
875 node.staticElement = staticMethod; | 885 node.staticElement = staticMethod; |
876 DartType propagatedType = _getPropagatedType(operand); | 886 DartType propagatedType = _getPropagatedType(operand); |
877 MethodElement propagatedMethod = | 887 MethodElement propagatedMethod = |
878 _lookUpMethod(operand, propagatedType, methodName); | 888 _lookUpMethod(operand, propagatedType, methodName); |
879 node.propagatedElement = propagatedMethod; | 889 node.propagatedElement = propagatedMethod; |
880 if (_shouldReportMissingMember(staticType, staticMethod)) { | 890 if (_shouldReportMissingMember(staticType, staticMethod)) { |
881 if (operand is SuperExpression) { | 891 if (operand is SuperExpression) { |
882 _recordUndefinedToken(staticType.element, | 892 _recordUndefinedToken( |
883 StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR, operator, [ | 893 staticType.element, |
884 methodName, | 894 StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR, |
885 staticType.displayName | 895 operator, |
886 ]); | 896 [methodName, staticType.displayName]); |
887 } else { | 897 } else { |
888 _recordUndefinedToken(staticType.element, | 898 _recordUndefinedToken( |
889 StaticTypeWarningCode.UNDEFINED_OPERATOR, operator, [ | 899 staticType.element, |
890 methodName, | 900 StaticTypeWarningCode.UNDEFINED_OPERATOR, |
891 staticType.displayName | 901 operator, |
892 ]); | 902 [methodName, staticType.displayName]); |
893 } | 903 } |
894 } else if (_enableHints && | 904 } else if (_enableHints && |
895 _shouldReportMissingMember(propagatedType, propagatedMethod) && | 905 _shouldReportMissingMember(propagatedType, propagatedMethod) && |
896 !_memberFoundInSubclass( | 906 !_memberFoundInSubclass( |
897 propagatedType.element, methodName, true, false)) { | 907 propagatedType.element, methodName, true, false)) { |
898 _recordUndefinedToken(propagatedType.element, | 908 _recordUndefinedToken( |
899 HintCode.UNDEFINED_OPERATOR, operator, [ | 909 propagatedType.element, |
900 methodName, | 910 HintCode.UNDEFINED_OPERATOR, |
901 propagatedType.displayName | 911 operator, |
902 ]); | 912 [methodName, propagatedType.displayName]); |
903 } | 913 } |
904 } | 914 } |
905 return null; | 915 return null; |
906 } | 916 } |
907 | 917 |
908 @override | 918 @override |
909 Object visitPropertyAccess(PropertyAccess node) { | 919 Object visitPropertyAccess(PropertyAccess node) { |
910 Expression target = node.realTarget; | 920 Expression target = node.realTarget; |
911 if (target is SuperExpression && !_isSuperInValidContext(target)) { | 921 if (target is SuperExpression && !_isSuperInValidContext(target)) { |
912 return null; | 922 return null; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 // TODO(brianwilkerson) Recover from this error. | 1008 // TODO(brianwilkerson) Recover from this error. |
999 if (_isConstructorReturnType(node)) { | 1009 if (_isConstructorReturnType(node)) { |
1000 _resolver.reportErrorForNode( | 1010 _resolver.reportErrorForNode( |
1001 CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node); | 1011 CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node); |
1002 } else if (node.parent is Annotation) { | 1012 } else if (node.parent is Annotation) { |
1003 Annotation annotation = node.parent as Annotation; | 1013 Annotation annotation = node.parent as Annotation; |
1004 _resolver.reportErrorForNode( | 1014 _resolver.reportErrorForNode( |
1005 CompileTimeErrorCode.INVALID_ANNOTATION, annotation); | 1015 CompileTimeErrorCode.INVALID_ANNOTATION, annotation); |
1006 } else if (element is PrefixElement) { | 1016 } else if (element is PrefixElement) { |
1007 _resolver.reportErrorForNode( | 1017 _resolver.reportErrorForNode( |
1008 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, node, | 1018 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, |
| 1019 node, |
1009 [element.name]); | 1020 [element.name]); |
1010 } else { | 1021 } else { |
1011 _recordUndefinedNode(_resolver.enclosingClass, | 1022 _recordUndefinedNode(_resolver.enclosingClass, |
1012 StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]); | 1023 StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]); |
1013 } | 1024 } |
1014 } | 1025 } |
1015 node.staticElement = element; | 1026 node.staticElement = element; |
1016 if (node.inSetterContext() && | 1027 if (node.inSetterContext() && |
1017 node.inGetterContext() && | 1028 node.inGetterContext() && |
1018 enclosingClass != null) { | 1029 enclosingClass != null) { |
(...skipping 26 matching lines...) Expand all Loading... |
1045 } | 1056 } |
1046 SimpleIdentifier name = node.constructorName; | 1057 SimpleIdentifier name = node.constructorName; |
1047 String superName = name != null ? name.name : null; | 1058 String superName = name != null ? name.name : null; |
1048 ConstructorElement element = | 1059 ConstructorElement element = |
1049 superType.lookUpConstructor(superName, _definingLibrary); | 1060 superType.lookUpConstructor(superName, _definingLibrary); |
1050 if (element == null || | 1061 if (element == null || |
1051 (!enclosingClass.doesMixinLackConstructors && | 1062 (!enclosingClass.doesMixinLackConstructors && |
1052 !enclosingClass.isSuperConstructorAccessible(element))) { | 1063 !enclosingClass.isSuperConstructorAccessible(element))) { |
1053 if (name != null) { | 1064 if (name != null) { |
1054 _resolver.reportErrorForNode( | 1065 _resolver.reportErrorForNode( |
1055 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER, node, [ | 1066 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER, |
1056 superType.displayName, | 1067 node, |
1057 name | 1068 [superType.displayName, name]); |
1058 ]); | |
1059 } else { | 1069 } else { |
1060 _resolver.reportErrorForNode( | 1070 _resolver.reportErrorForNode( |
1061 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT, | 1071 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT, |
1062 node, [superType.displayName]); | 1072 node, |
| 1073 [superType.displayName]); |
1063 } | 1074 } |
1064 return null; | 1075 return null; |
1065 } else { | 1076 } else { |
1066 if (element.isFactory) { | 1077 if (element.isFactory) { |
1067 _resolver.reportErrorForNode( | 1078 _resolver.reportErrorForNode( |
1068 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, [element]); | 1079 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, [element]); |
1069 } | 1080 } |
1070 } | 1081 } |
1071 if (name != null) { | 1082 if (name != null) { |
1072 name.staticElement = element; | 1083 name.staticElement = element; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 } | 1201 } |
1191 return null; | 1202 return null; |
1192 } | 1203 } |
1193 | 1204 |
1194 /** | 1205 /** |
1195 * Check that the given index [expression] was resolved, otherwise a | 1206 * Check that the given index [expression] was resolved, otherwise a |
1196 * [StaticTypeWarningCode.UNDEFINED_OPERATOR] is generated. The [target] is | 1207 * [StaticTypeWarningCode.UNDEFINED_OPERATOR] is generated. The [target] is |
1197 * the target of the expression. The [methodName] is the name of the operator | 1208 * the target of the expression. The [methodName] is the name of the operator |
1198 * associated with the context of using of the given index expression. | 1209 * associated with the context of using of the given index expression. |
1199 */ | 1210 */ |
1200 bool _checkForUndefinedIndexOperator(IndexExpression expression, | 1211 bool _checkForUndefinedIndexOperator( |
1201 Expression target, String methodName, MethodElement staticMethod, | 1212 IndexExpression expression, |
1202 MethodElement propagatedMethod, DartType staticType, | 1213 Expression target, |
| 1214 String methodName, |
| 1215 MethodElement staticMethod, |
| 1216 MethodElement propagatedMethod, |
| 1217 DartType staticType, |
1203 DartType propagatedType) { | 1218 DartType propagatedType) { |
1204 bool shouldReportMissingMember_static = | 1219 bool shouldReportMissingMember_static = |
1205 _shouldReportMissingMember(staticType, staticMethod); | 1220 _shouldReportMissingMember(staticType, staticMethod); |
1206 bool shouldReportMissingMember_propagated = | 1221 bool shouldReportMissingMember_propagated = |
1207 !shouldReportMissingMember_static && | 1222 !shouldReportMissingMember_static && |
1208 _enableHints && | 1223 _enableHints && |
1209 _shouldReportMissingMember(propagatedType, propagatedMethod) && | 1224 _shouldReportMissingMember(propagatedType, propagatedMethod) && |
1210 !_memberFoundInSubclass( | 1225 !_memberFoundInSubclass( |
1211 propagatedType.element, methodName, true, false); | 1226 propagatedType.element, methodName, true, false); |
1212 if (shouldReportMissingMember_static || | 1227 if (shouldReportMissingMember_static || |
1213 shouldReportMissingMember_propagated) { | 1228 shouldReportMissingMember_propagated) { |
1214 sc.Token leftBracket = expression.leftBracket; | 1229 sc.Token leftBracket = expression.leftBracket; |
1215 sc.Token rightBracket = expression.rightBracket; | 1230 sc.Token rightBracket = expression.rightBracket; |
1216 ErrorCode errorCode; | 1231 ErrorCode errorCode; |
1217 if (shouldReportMissingMember_static) { | 1232 if (shouldReportMissingMember_static) { |
1218 if (target is SuperExpression) { | 1233 if (target is SuperExpression) { |
1219 errorCode = StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR; | 1234 errorCode = StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR; |
1220 } else { | 1235 } else { |
1221 errorCode = StaticTypeWarningCode.UNDEFINED_OPERATOR; | 1236 errorCode = StaticTypeWarningCode.UNDEFINED_OPERATOR; |
1222 } | 1237 } |
1223 } else { | 1238 } else { |
1224 errorCode = HintCode.UNDEFINED_OPERATOR; | 1239 errorCode = HintCode.UNDEFINED_OPERATOR; |
1225 } | 1240 } |
1226 DartType type = | 1241 DartType type = |
1227 shouldReportMissingMember_static ? staticType : propagatedType; | 1242 shouldReportMissingMember_static ? staticType : propagatedType; |
1228 if (leftBracket == null || rightBracket == null) { | 1243 if (leftBracket == null || rightBracket == null) { |
1229 _recordUndefinedNode(type.element, errorCode, expression, [ | 1244 _recordUndefinedNode(type.element, errorCode, expression, |
1230 methodName, | 1245 [methodName, type.displayName]); |
1231 type.displayName | |
1232 ]); | |
1233 } else { | 1246 } else { |
1234 int offset = leftBracket.offset; | 1247 int offset = leftBracket.offset; |
1235 int length = rightBracket.offset - offset + 1; | 1248 int length = rightBracket.offset - offset + 1; |
1236 _recordUndefinedOffset(type.element, errorCode, offset, length, [ | 1249 _recordUndefinedOffset(type.element, errorCode, offset, length, |
1237 methodName, | 1250 [methodName, type.displayName]); |
1238 type.displayName | |
1239 ]); | |
1240 } | 1251 } |
1241 return true; | 1252 return true; |
1242 } | 1253 } |
1243 return false; | 1254 return false; |
1244 } | 1255 } |
1245 | 1256 |
1246 /** | 1257 /** |
1247 * Given an [argumentList] and the executable [element] that will be invoked | 1258 * Given an [argumentList] and the executable [element] that will be invoked |
1248 * using those arguments, compute the list of parameters that correspond to | 1259 * using those arguments, compute the list of parameters that correspond to |
1249 * the list of arguments. Return the parameters that correspond to the | 1260 * the list of arguments. Return the parameters that correspond to the |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 /** | 1585 /** |
1575 * Look up the getter with the given [getterName] in the interfaces | 1586 * Look up the getter with the given [getterName] in the interfaces |
1576 * implemented by the given [targetType], either directly or indirectly. | 1587 * implemented by the given [targetType], either directly or indirectly. |
1577 * Return the element representing the getter that was found, or `null` if | 1588 * Return the element representing the getter that was found, or `null` if |
1578 * there is no getter with the given name. The flag [includeTargetType] should | 1589 * there is no getter with the given name. The flag [includeTargetType] should |
1579 * be `true` if the search should include the target type. The | 1590 * be `true` if the search should include the target type. The |
1580 * [visitedInterfaces] is a set containing all of the interfaces that have | 1591 * [visitedInterfaces] is a set containing all of the interfaces that have |
1581 * been examined, used to prevent infinite recursion and to optimize the | 1592 * been examined, used to prevent infinite recursion and to optimize the |
1582 * search. | 1593 * search. |
1583 */ | 1594 */ |
1584 PropertyAccessorElement _lookUpGetterInInterfaces(InterfaceType targetType, | 1595 PropertyAccessorElement _lookUpGetterInInterfaces( |
1585 bool includeTargetType, String getterName, | 1596 InterfaceType targetType, |
| 1597 bool includeTargetType, |
| 1598 String getterName, |
1586 HashSet<ClassElement> visitedInterfaces) { | 1599 HashSet<ClassElement> visitedInterfaces) { |
1587 // TODO(brianwilkerson) This isn't correct. Section 8.1.1 of the | 1600 // TODO(brianwilkerson) This isn't correct. Section 8.1.1 of the |
1588 // specification (titled "Inheritance and Overriding" under "Interfaces") | 1601 // specification (titled "Inheritance and Overriding" under "Interfaces") |
1589 // describes a much more complex scheme for finding the inherited member. | 1602 // describes a much more complex scheme for finding the inherited member. |
1590 // We need to follow that scheme. The code below should cover the 80% case. | 1603 // We need to follow that scheme. The code below should cover the 80% case. |
1591 ClassElement targetClass = targetType.element; | 1604 ClassElement targetClass = targetType.element; |
1592 if (visitedInterfaces.contains(targetClass)) { | 1605 if (visitedInterfaces.contains(targetClass)) { |
1593 return null; | 1606 return null; |
1594 } | 1607 } |
1595 visitedInterfaces.add(targetClass); | 1608 visitedInterfaces.add(targetClass); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 /** | 1661 /** |
1649 * Look up the method or getter with the given [memberName] in the interfaces | 1662 * Look up the method or getter with the given [memberName] in the interfaces |
1650 * implemented by the given [targetType], either directly or indirectly. | 1663 * implemented by the given [targetType], either directly or indirectly. |
1651 * Return the element representing the method or getter that was found, or | 1664 * Return the element representing the method or getter that was found, or |
1652 * `null` if there is no method or getter with the given name. The flag | 1665 * `null` if there is no method or getter with the given name. The flag |
1653 * [includeTargetType] should be `true` if the search should include the | 1666 * [includeTargetType] should be `true` if the search should include the |
1654 * target type. The [visitedInterfaces] is a set containing all of the | 1667 * target type. The [visitedInterfaces] is a set containing all of the |
1655 * interfaces that have been examined, used to prevent infinite recursion and | 1668 * interfaces that have been examined, used to prevent infinite recursion and |
1656 * to optimize the search. | 1669 * to optimize the search. |
1657 */ | 1670 */ |
1658 ExecutableElement _lookUpGetterOrMethodInInterfaces(InterfaceType targetType, | 1671 ExecutableElement _lookUpGetterOrMethodInInterfaces( |
1659 bool includeTargetType, String memberName, | 1672 InterfaceType targetType, |
| 1673 bool includeTargetType, |
| 1674 String memberName, |
1660 HashSet<ClassElement> visitedInterfaces) { | 1675 HashSet<ClassElement> visitedInterfaces) { |
1661 // TODO(brianwilkerson) This isn't correct. Section 8.1.1 of the | 1676 // TODO(brianwilkerson) This isn't correct. Section 8.1.1 of the |
1662 // specification (titled "Inheritance and Overriding" under "Interfaces") | 1677 // specification (titled "Inheritance and Overriding" under "Interfaces") |
1663 // describes a much more complex scheme for finding the inherited member. | 1678 // describes a much more complex scheme for finding the inherited member. |
1664 // We need to follow that scheme. The code below should cover the 80% case. | 1679 // We need to follow that scheme. The code below should cover the 80% case. |
1665 ClassElement targetClass = targetType.element; | 1680 ClassElement targetClass = targetType.element; |
1666 if (visitedInterfaces.contains(targetClass)) { | 1681 if (visitedInterfaces.contains(targetClass)) { |
1667 return null; | 1682 return null; |
1668 } | 1683 } |
1669 visitedInterfaces.add(targetClass); | 1684 visitedInterfaces.add(targetClass); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 /** | 1744 /** |
1730 * Look up the method with the given [methodName] in the interfaces | 1745 * Look up the method with the given [methodName] in the interfaces |
1731 * implemented by the given [targetType], either directly or indirectly. | 1746 * implemented by the given [targetType], either directly or indirectly. |
1732 * Return the element representing the method that was found, or `null` if | 1747 * Return the element representing the method that was found, or `null` if |
1733 * there is no method with the given name. The flag [includeTargetType] should | 1748 * there is no method with the given name. The flag [includeTargetType] should |
1734 * be `true` if the search should include the target type. The | 1749 * be `true` if the search should include the target type. The |
1735 * [visitedInterfaces] is a set containing all of the interfaces that have | 1750 * [visitedInterfaces] is a set containing all of the interfaces that have |
1736 * been examined, used to prevent infinite recursion and to optimize the | 1751 * been examined, used to prevent infinite recursion and to optimize the |
1737 * search. | 1752 * search. |
1738 */ | 1753 */ |
1739 MethodElement _lookUpMethodInInterfaces(InterfaceType targetType, | 1754 MethodElement _lookUpMethodInInterfaces( |
1740 bool includeTargetType, String methodName, | 1755 InterfaceType targetType, |
| 1756 bool includeTargetType, |
| 1757 String methodName, |
1741 HashSet<ClassElement> visitedInterfaces) { | 1758 HashSet<ClassElement> visitedInterfaces) { |
1742 // TODO(brianwilkerson) This isn't correct. Section 8.1.1 of the | 1759 // TODO(brianwilkerson) This isn't correct. Section 8.1.1 of the |
1743 // specification (titled "Inheritance and Overriding" under "Interfaces") | 1760 // specification (titled "Inheritance and Overriding" under "Interfaces") |
1744 // describes a much more complex scheme for finding the inherited member. | 1761 // describes a much more complex scheme for finding the inherited member. |
1745 // We need to follow that scheme. The code below should cover the 80% case. | 1762 // We need to follow that scheme. The code below should cover the 80% case. |
1746 ClassElement targetClass = targetType.element; | 1763 ClassElement targetClass = targetType.element; |
1747 if (visitedInterfaces.contains(targetClass)) { | 1764 if (visitedInterfaces.contains(targetClass)) { |
1748 return null; | 1765 return null; |
1749 } | 1766 } |
1750 visitedInterfaces.add(targetClass); | 1767 visitedInterfaces.add(targetClass); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 * Look up the setter with the given [setterName] in the interfaces | 1824 * Look up the setter with the given [setterName] in the interfaces |
1808 * implemented by the given [targetType], either directly or indirectly. | 1825 * implemented by the given [targetType], either directly or indirectly. |
1809 * Return the element representing the setter that was found, or `null` if | 1826 * Return the element representing the setter that was found, or `null` if |
1810 * there is no setter with the given name. The [targetType] is the type in | 1827 * there is no setter with the given name. The [targetType] is the type in |
1811 * which the setter might be defined. The flag [includeTargetType] should be | 1828 * which the setter might be defined. The flag [includeTargetType] should be |
1812 * `true` if the search should include the target type. The | 1829 * `true` if the search should include the target type. The |
1813 * [visitedInterfaces] is a set containing all of the interfaces that have | 1830 * [visitedInterfaces] is a set containing all of the interfaces that have |
1814 * been examined, used to prevent infinite recursion and to optimize the | 1831 * been examined, used to prevent infinite recursion and to optimize the |
1815 * search. | 1832 * search. |
1816 */ | 1833 */ |
1817 PropertyAccessorElement _lookUpSetterInInterfaces(InterfaceType targetType, | 1834 PropertyAccessorElement _lookUpSetterInInterfaces( |
1818 bool includeTargetType, String setterName, | 1835 InterfaceType targetType, |
| 1836 bool includeTargetType, |
| 1837 String setterName, |
1819 HashSet<ClassElement> visitedInterfaces) { | 1838 HashSet<ClassElement> visitedInterfaces) { |
1820 // TODO(brianwilkerson) This isn't correct. Section 8.1.1 of the | 1839 // TODO(brianwilkerson) This isn't correct. Section 8.1.1 of the |
1821 // specification (titled "Inheritance and Overriding" under "Interfaces") | 1840 // specification (titled "Inheritance and Overriding" under "Interfaces") |
1822 // describes a much more complex scheme for finding the inherited member. | 1841 // describes a much more complex scheme for finding the inherited member. |
1823 // We need to follow that scheme. The code below should cover the 80% case. | 1842 // We need to follow that scheme. The code below should cover the 80% case. |
1824 ClassElement targetClass = targetType.element; | 1843 ClassElement targetClass = targetType.element; |
1825 if (visitedInterfaces.contains(targetClass)) { | 1844 if (visitedInterfaces.contains(targetClass)) { |
1826 return null; | 1845 return null; |
1827 } | 1846 } |
1828 visitedInterfaces.add(targetClass); | 1847 visitedInterfaces.add(targetClass); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2004 if (nameNode1 != null && nameNode2 == null && nameNode3 == null) { | 2023 if (nameNode1 != null && nameNode2 == null && nameNode3 == null) { |
2005 Element element1 = nameNode1.staticElement; | 2024 Element element1 = nameNode1.staticElement; |
2006 // CONST | 2025 // CONST |
2007 if (element1 is PropertyAccessorElement) { | 2026 if (element1 is PropertyAccessorElement) { |
2008 _resolveAnnotationElementGetter(annotation, element1); | 2027 _resolveAnnotationElementGetter(annotation, element1); |
2009 return; | 2028 return; |
2010 } | 2029 } |
2011 // Class(args) | 2030 // Class(args) |
2012 if (element1 is ClassElement) { | 2031 if (element1 is ClassElement) { |
2013 ClassElement classElement = element1; | 2032 ClassElement classElement = element1; |
2014 constructor = new InterfaceTypeImpl(classElement).lookUpConstructor( | 2033 constructor = new InterfaceTypeImpl(classElement) |
2015 null, _definingLibrary); | 2034 .lookUpConstructor(null, _definingLibrary); |
2016 } | 2035 } |
2017 } | 2036 } |
2018 // | 2037 // |
2019 // prefix.CONST or prefix.Class() or Class.CONST or Class.constructor(args) | 2038 // prefix.CONST or prefix.Class() or Class.CONST or Class.constructor(args) |
2020 // | 2039 // |
2021 if (nameNode1 != null && nameNode2 != null && nameNode3 == null) { | 2040 if (nameNode1 != null && nameNode2 != null && nameNode3 == null) { |
2022 Element element1 = nameNode1.staticElement; | 2041 Element element1 = nameNode1.staticElement; |
2023 Element element2 = nameNode2.staticElement; | 2042 Element element2 = nameNode2.staticElement; |
2024 // Class.CONST - not resolved yet | 2043 // Class.CONST - not resolved yet |
2025 if (element1 is ClassElement) { | 2044 if (element1 is ClassElement) { |
2026 ClassElement classElement = element1; | 2045 ClassElement classElement = element1; |
2027 element2 = classElement.lookUpGetter(nameNode2.name, _definingLibrary); | 2046 element2 = classElement.lookUpGetter(nameNode2.name, _definingLibrary); |
2028 } | 2047 } |
2029 // prefix.CONST or Class.CONST | 2048 // prefix.CONST or Class.CONST |
2030 if (element2 is PropertyAccessorElement) { | 2049 if (element2 is PropertyAccessorElement) { |
2031 nameNode2.staticElement = element2; | 2050 nameNode2.staticElement = element2; |
2032 annotation.element = element2; | 2051 annotation.element = element2; |
2033 _resolveAnnotationElementGetter(annotation, element2); | 2052 _resolveAnnotationElementGetter(annotation, element2); |
2034 return; | 2053 return; |
2035 } | 2054 } |
2036 // prefix.Class() | 2055 // prefix.Class() |
2037 if (element2 is ClassElement) { | 2056 if (element2 is ClassElement) { |
2038 constructor = element2.unnamedConstructor; | 2057 constructor = element2.unnamedConstructor; |
2039 } | 2058 } |
2040 // Class.constructor(args) | 2059 // Class.constructor(args) |
2041 if (element1 is ClassElement) { | 2060 if (element1 is ClassElement) { |
2042 ClassElement classElement = element1; | 2061 ClassElement classElement = element1; |
2043 constructor = new InterfaceTypeImpl(classElement).lookUpConstructor( | 2062 constructor = new InterfaceTypeImpl(classElement) |
2044 nameNode2.name, _definingLibrary); | 2063 .lookUpConstructor(nameNode2.name, _definingLibrary); |
2045 nameNode2.staticElement = constructor; | 2064 nameNode2.staticElement = constructor; |
2046 } | 2065 } |
2047 } | 2066 } |
2048 // | 2067 // |
2049 // prefix.Class.CONST or prefix.Class.constructor(args) | 2068 // prefix.Class.CONST or prefix.Class.constructor(args) |
2050 // | 2069 // |
2051 if (nameNode1 != null && nameNode2 != null && nameNode3 != null) { | 2070 if (nameNode1 != null && nameNode2 != null && nameNode3 != null) { |
2052 Element element2 = nameNode2.staticElement; | 2071 Element element2 = nameNode2.staticElement; |
2053 // element2 should be ClassElement | 2072 // element2 should be ClassElement |
2054 if (element2 is ClassElement) { | 2073 if (element2 is ClassElement) { |
2055 ClassElement classElement = element2; | 2074 ClassElement classElement = element2; |
2056 String name3 = nameNode3.name; | 2075 String name3 = nameNode3.name; |
2057 // prefix.Class.CONST | 2076 // prefix.Class.CONST |
2058 PropertyAccessorElement getter = | 2077 PropertyAccessorElement getter = |
2059 classElement.lookUpGetter(name3, _definingLibrary); | 2078 classElement.lookUpGetter(name3, _definingLibrary); |
2060 if (getter != null) { | 2079 if (getter != null) { |
2061 nameNode3.staticElement = getter; | 2080 nameNode3.staticElement = getter; |
2062 annotation.element = element2; | 2081 annotation.element = element2; |
2063 _resolveAnnotationElementGetter(annotation, getter); | 2082 _resolveAnnotationElementGetter(annotation, getter); |
2064 return; | 2083 return; |
2065 } | 2084 } |
2066 // prefix.Class.constructor(args) | 2085 // prefix.Class.constructor(args) |
2067 constructor = new InterfaceTypeImpl(classElement).lookUpConstructor( | 2086 constructor = new InterfaceTypeImpl(classElement) |
2068 name3, _definingLibrary); | 2087 .lookUpConstructor(name3, _definingLibrary); |
2069 nameNode3.staticElement = constructor; | 2088 nameNode3.staticElement = constructor; |
2070 } | 2089 } |
2071 } | 2090 } |
2072 // we need constructor | 2091 // we need constructor |
2073 if (constructor == null) { | 2092 if (constructor == null) { |
2074 _resolver.reportErrorForNode( | 2093 _resolver.reportErrorForNode( |
2075 CompileTimeErrorCode.INVALID_ANNOTATION, annotation); | 2094 CompileTimeErrorCode.INVALID_ANNOTATION, annotation); |
2076 return; | 2095 return; |
2077 } | 2096 } |
2078 // record element | 2097 // record element |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 if (unnamedIndex < unnamedParameterCount) { | 2200 if (unnamedIndex < unnamedParameterCount) { |
2182 resolvedParameters[i] = unnamedParameters[unnamedIndex++]; | 2201 resolvedParameters[i] = unnamedParameters[unnamedIndex++]; |
2183 } | 2202 } |
2184 } | 2203 } |
2185 } | 2204 } |
2186 if (positionalArgumentCount < requiredParameters.length && | 2205 if (positionalArgumentCount < requiredParameters.length && |
2187 noBlankArguments) { | 2206 noBlankArguments) { |
2188 ErrorCode errorCode = (reportError | 2207 ErrorCode errorCode = (reportError |
2189 ? CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS | 2208 ? CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS |
2190 : StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS); | 2209 : StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS); |
2191 _resolver.reportErrorForNode(errorCode, argumentList, [ | 2210 _resolver.reportErrorForNode(errorCode, argumentList, |
2192 requiredParameters.length, | 2211 [requiredParameters.length, positionalArgumentCount]); |
2193 positionalArgumentCount | |
2194 ]); | |
2195 } else if (positionalArgumentCount > unnamedParameterCount && | 2212 } else if (positionalArgumentCount > unnamedParameterCount && |
2196 noBlankArguments) { | 2213 noBlankArguments) { |
2197 ErrorCode errorCode = (reportError | 2214 ErrorCode errorCode = (reportError |
2198 ? CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS | 2215 ? CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS |
2199 : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS); | 2216 : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS); |
2200 _resolver.reportErrorForNode(errorCode, argumentList, [ | 2217 _resolver.reportErrorForNode(errorCode, argumentList, |
2201 unnamedParameterCount, | 2218 [unnamedParameterCount, positionalArgumentCount]); |
2202 positionalArgumentCount | |
2203 ]); | |
2204 } | 2219 } |
2205 return resolvedParameters; | 2220 return resolvedParameters; |
2206 } | 2221 } |
2207 | 2222 |
2208 void _resolveBinaryExpression(BinaryExpression node, String methodName) { | 2223 void _resolveBinaryExpression(BinaryExpression node, String methodName) { |
2209 Expression leftOperand = node.leftOperand; | 2224 Expression leftOperand = node.leftOperand; |
2210 if (leftOperand != null) { | 2225 if (leftOperand != null) { |
2211 DartType staticType = _getStaticType(leftOperand); | 2226 DartType staticType = _getStaticType(leftOperand); |
2212 MethodElement staticMethod = | 2227 MethodElement staticMethod = |
2213 _lookUpMethod(leftOperand, staticType, methodName); | 2228 _lookUpMethod(leftOperand, staticType, methodName); |
2214 node.staticElement = staticMethod; | 2229 node.staticElement = staticMethod; |
2215 DartType propagatedType = _getPropagatedType(leftOperand); | 2230 DartType propagatedType = _getPropagatedType(leftOperand); |
2216 MethodElement propagatedMethod = | 2231 MethodElement propagatedMethod = |
2217 _lookUpMethod(leftOperand, propagatedType, methodName); | 2232 _lookUpMethod(leftOperand, propagatedType, methodName); |
2218 node.propagatedElement = propagatedMethod; | 2233 node.propagatedElement = propagatedMethod; |
2219 if (_shouldReportMissingMember(staticType, staticMethod)) { | 2234 if (_shouldReportMissingMember(staticType, staticMethod)) { |
2220 if (leftOperand is SuperExpression) { | 2235 if (leftOperand is SuperExpression) { |
2221 _recordUndefinedToken(staticType.element, | 2236 _recordUndefinedToken( |
2222 StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR, node.operator, [ | 2237 staticType.element, |
2223 methodName, | 2238 StaticTypeWarningCode.UNDEFINED_SUPER_OPERATOR, |
2224 staticType.displayName | 2239 node.operator, |
2225 ]); | 2240 [methodName, staticType.displayName]); |
2226 } else { | 2241 } else { |
2227 _recordUndefinedToken(staticType.element, | 2242 _recordUndefinedToken( |
2228 StaticTypeWarningCode.UNDEFINED_OPERATOR, node.operator, [ | 2243 staticType.element, |
2229 methodName, | 2244 StaticTypeWarningCode.UNDEFINED_OPERATOR, |
2230 staticType.displayName | 2245 node.operator, |
2231 ]); | 2246 [methodName, staticType.displayName]); |
2232 } | 2247 } |
2233 } else if (_enableHints && | 2248 } else if (_enableHints && |
2234 _shouldReportMissingMember(propagatedType, propagatedMethod) && | 2249 _shouldReportMissingMember(propagatedType, propagatedMethod) && |
2235 !_memberFoundInSubclass( | 2250 !_memberFoundInSubclass( |
2236 propagatedType.element, methodName, true, false)) { | 2251 propagatedType.element, methodName, true, false)) { |
2237 _recordUndefinedToken(propagatedType.element, | 2252 _recordUndefinedToken( |
2238 HintCode.UNDEFINED_OPERATOR, node.operator, [ | 2253 propagatedType.element, |
2239 methodName, | 2254 HintCode.UNDEFINED_OPERATOR, |
2240 propagatedType.displayName | 2255 node.operator, |
2241 ]); | 2256 [methodName, propagatedType.displayName]); |
2242 } | 2257 } |
2243 } | 2258 } |
2244 } | 2259 } |
2245 | 2260 |
2246 /** | 2261 /** |
2247 * Resolve the names in the given [combinators] in the scope of the given | 2262 * Resolve the names in the given [combinators] in the scope of the given |
2248 * [library]. | 2263 * [library]. |
2249 */ | 2264 */ |
2250 void _resolveCombinators( | 2265 void _resolveCombinators( |
2251 LibraryElement library, NodeList<Combinator> combinators) { | 2266 LibraryElement library, NodeList<Combinator> combinators) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2364 // style of [lookUpMethod]. | 2379 // style of [lookUpMethod]. |
2365 element = _lookUpGetter(target, targetType, methodName.name); | 2380 element = _lookUpGetter(target, targetType, methodName.name); |
2366 } | 2381 } |
2367 return element; | 2382 return element; |
2368 } else if (target is SimpleIdentifier) { | 2383 } else if (target is SimpleIdentifier) { |
2369 Element targetElement = target.staticElement; | 2384 Element targetElement = target.staticElement; |
2370 if (targetElement is PrefixElement) { | 2385 if (targetElement is PrefixElement) { |
2371 if (isConditional) { | 2386 if (isConditional) { |
2372 _resolver.reportErrorForNode( | 2387 _resolver.reportErrorForNode( |
2373 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, | 2388 CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT, |
2374 target, [target.name]); | 2389 target, |
| 2390 [target.name]); |
2375 } | 2391 } |
2376 // | 2392 // |
2377 // Look to see whether the name of the method is really part of a | 2393 // Look to see whether the name of the method is really part of a |
2378 // prefixed identifier for an imported top-level function or top-level | 2394 // prefixed identifier for an imported top-level function or top-level |
2379 // getter that returns a function. | 2395 // getter that returns a function. |
2380 // | 2396 // |
2381 String name = "${target.name}.$methodName"; | 2397 String name = "${target.name}.$methodName"; |
2382 Identifier functionName = new SyntheticIdentifier(name, methodName); | 2398 Identifier functionName = new SyntheticIdentifier(name, methodName); |
2383 Element element = | 2399 Element element = |
2384 _resolver.nameScope.lookup(functionName, _definingLibrary); | 2400 _resolver.nameScope.lookup(functionName, _definingLibrary); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2473 if (!_enableStrictCallChecks && | 2489 if (!_enableStrictCallChecks && |
2474 targetType != null && | 2490 targetType != null && |
2475 targetType.isDartCoreFunction && | 2491 targetType.isDartCoreFunction && |
2476 propertyName.name == FunctionElement.CALL_METHOD_NAME) { | 2492 propertyName.name == FunctionElement.CALL_METHOD_NAME) { |
2477 // TODO(brianwilkerson) Can we ever resolve the function being | 2493 // TODO(brianwilkerson) Can we ever resolve the function being |
2478 // invoked? | 2494 // invoked? |
2479 // resolveArgumentsToParameters(node.getArgumentList(), invokedFuncti
on); | 2495 // resolveArgumentsToParameters(node.getArgumentList(), invokedFuncti
on); |
2480 return; | 2496 return; |
2481 } else if (classElement.isEnum && propertyName.name == "_name") { | 2497 } else if (classElement.isEnum && propertyName.name == "_name") { |
2482 _resolver.reportErrorForNode( | 2498 _resolver.reportErrorForNode( |
2483 CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD, propertyName, | 2499 CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD, |
| 2500 propertyName, |
2484 [propertyName.name]); | 2501 [propertyName.name]); |
2485 return; | 2502 return; |
2486 } | 2503 } |
2487 } | 2504 } |
2488 } | 2505 } |
2489 Element declaringElement = | 2506 Element declaringElement = |
2490 staticType.isVoid ? null : staticOrPropagatedEnclosingElt; | 2507 staticType.isVoid ? null : staticOrPropagatedEnclosingElt; |
2491 if (propertyName.inSetterContext()) { | 2508 if (propertyName.inSetterContext()) { |
2492 ErrorCode errorCode; | 2509 ErrorCode errorCode; |
2493 if (shouldReportMissingMember_static) { | 2510 if (shouldReportMissingMember_static) { |
2494 if (target is SuperExpression) { | 2511 if (target is SuperExpression) { |
2495 if (isStaticProperty && !staticType.isVoid) { | 2512 if (isStaticProperty && !staticType.isVoid) { |
2496 errorCode = StaticWarningCode.UNDEFINED_SUPER_SETTER; | 2513 errorCode = StaticWarningCode.UNDEFINED_SUPER_SETTER; |
2497 } else { | 2514 } else { |
2498 errorCode = StaticTypeWarningCode.UNDEFINED_SUPER_SETTER; | 2515 errorCode = StaticTypeWarningCode.UNDEFINED_SUPER_SETTER; |
2499 } | 2516 } |
2500 } else { | 2517 } else { |
2501 if (isStaticProperty && !staticType.isVoid) { | 2518 if (isStaticProperty && !staticType.isVoid) { |
2502 errorCode = StaticWarningCode.UNDEFINED_SETTER; | 2519 errorCode = StaticWarningCode.UNDEFINED_SETTER; |
2503 } else { | 2520 } else { |
2504 errorCode = StaticTypeWarningCode.UNDEFINED_SETTER; | 2521 errorCode = StaticTypeWarningCode.UNDEFINED_SETTER; |
2505 } | 2522 } |
2506 } | 2523 } |
2507 } else { | 2524 } else { |
2508 errorCode = HintCode.UNDEFINED_SETTER; | 2525 errorCode = HintCode.UNDEFINED_SETTER; |
2509 } | 2526 } |
2510 _recordUndefinedNode(declaringElement, errorCode, propertyName, [ | 2527 _recordUndefinedNode(declaringElement, errorCode, propertyName, |
2511 propertyName.name, | 2528 [propertyName.name, displayType.displayName]); |
2512 displayType.displayName | |
2513 ]); | |
2514 } else if (propertyName.inGetterContext()) { | 2529 } else if (propertyName.inGetterContext()) { |
2515 ErrorCode errorCode; | 2530 ErrorCode errorCode; |
2516 if (shouldReportMissingMember_static) { | 2531 if (shouldReportMissingMember_static) { |
2517 if (target is SuperExpression) { | 2532 if (target is SuperExpression) { |
2518 if (isStaticProperty && !staticType.isVoid) { | 2533 if (isStaticProperty && !staticType.isVoid) { |
2519 errorCode = StaticWarningCode.UNDEFINED_SUPER_GETTER; | 2534 errorCode = StaticWarningCode.UNDEFINED_SUPER_GETTER; |
2520 } else { | 2535 } else { |
2521 errorCode = StaticTypeWarningCode.UNDEFINED_SUPER_GETTER; | 2536 errorCode = StaticTypeWarningCode.UNDEFINED_SUPER_GETTER; |
2522 } | 2537 } |
2523 } else { | 2538 } else { |
2524 if (isStaticProperty && !staticType.isVoid) { | 2539 if (isStaticProperty && !staticType.isVoid) { |
2525 errorCode = StaticWarningCode.UNDEFINED_GETTER; | 2540 errorCode = StaticWarningCode.UNDEFINED_GETTER; |
2526 } else { | 2541 } else { |
2527 errorCode = StaticTypeWarningCode.UNDEFINED_GETTER; | 2542 errorCode = StaticTypeWarningCode.UNDEFINED_GETTER; |
2528 } | 2543 } |
2529 } | 2544 } |
2530 } else { | 2545 } else { |
2531 errorCode = HintCode.UNDEFINED_GETTER; | 2546 errorCode = HintCode.UNDEFINED_GETTER; |
2532 } | 2547 } |
2533 _recordUndefinedNode(declaringElement, errorCode, propertyName, [ | 2548 _recordUndefinedNode(declaringElement, errorCode, propertyName, |
2534 propertyName.name, | 2549 [propertyName.name, displayType.displayName]); |
2535 displayType.displayName | |
2536 ]); | |
2537 } else { | 2550 } else { |
2538 _recordUndefinedNode(declaringElement, | 2551 _recordUndefinedNode( |
2539 StaticWarningCode.UNDEFINED_IDENTIFIER, propertyName, | 2552 declaringElement, |
| 2553 StaticWarningCode.UNDEFINED_IDENTIFIER, |
| 2554 propertyName, |
2540 [propertyName.name]); | 2555 [propertyName.name]); |
2541 } | 2556 } |
2542 } | 2557 } |
2543 } | 2558 } |
2544 | 2559 |
2545 /** | 2560 /** |
2546 * Resolve the given simple [identifier] if possible. Return the element to | 2561 * Resolve the given simple [identifier] if possible. Return the element to |
2547 * which it could be resolved, or `null` if it could not be resolved. This | 2562 * which it could be resolved, or `null` if it could not be resolved. This |
2548 * does not record the results of the resolution. | 2563 * does not record the results of the resolution. |
2549 */ | 2564 */ |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2800 | 2815 |
2801 @override | 2816 @override |
2802 Element get staticElement => null; | 2817 Element get staticElement => null; |
2803 | 2818 |
2804 @override | 2819 @override |
2805 accept(AstVisitor visitor) => null; | 2820 accept(AstVisitor visitor) => null; |
2806 | 2821 |
2807 @override | 2822 @override |
2808 void visitChildren(AstVisitor visitor) {} | 2823 void visitChildren(AstVisitor visitor) {} |
2809 } | 2824 } |
OLD | NEW |