| 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.generated.resolver; | 5 library analyzer.src.generated.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 _checkForUnnecessaryNoSuchMethod(node); | 255 _checkForUnnecessaryNoSuchMethod(node); |
| 256 return super.visitMethodDeclaration(node); | 256 return super.visitMethodDeclaration(node); |
| 257 } finally { | 257 } finally { |
| 258 inDeprecatedMember = wasInDeprecatedMember; | 258 inDeprecatedMember = wasInDeprecatedMember; |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 @override | 262 @override |
| 263 Object visitMethodInvocation(MethodInvocation node) { | 263 Object visitMethodInvocation(MethodInvocation node) { |
| 264 _checkForCanBeNullAfterNullAware(node.realTarget, node.operator); | 264 _checkForCanBeNullAfterNullAware(node.realTarget, node.operator); |
| 265 _checkForInvalidProtectedMethodCalls(node); | |
| 266 DartType staticInvokeType = node.staticInvokeType; | 265 DartType staticInvokeType = node.staticInvokeType; |
| 267 if (staticInvokeType is InterfaceType) { | 266 if (staticInvokeType is InterfaceType) { |
| 268 MethodElement methodElement = staticInvokeType.lookUpMethod( | 267 MethodElement methodElement = staticInvokeType.lookUpMethod( |
| 269 FunctionElement.CALL_METHOD_NAME, _currentLibrary); | 268 FunctionElement.CALL_METHOD_NAME, _currentLibrary); |
| 270 _checkForDeprecatedMemberUse(methodElement, node); | 269 _checkForDeprecatedMemberUse(methodElement, node); |
| 271 } | 270 } |
| 272 return super.visitMethodInvocation(node); | 271 return super.visitMethodInvocation(node); |
| 273 } | 272 } |
| 274 | 273 |
| 275 @override | 274 @override |
| (...skipping 17 matching lines...) Expand all Loading... |
| 293 @override | 292 @override |
| 294 Object visitRedirectingConstructorInvocation( | 293 Object visitRedirectingConstructorInvocation( |
| 295 RedirectingConstructorInvocation node) { | 294 RedirectingConstructorInvocation node) { |
| 296 _checkForDeprecatedMemberUse(node.staticElement, node); | 295 _checkForDeprecatedMemberUse(node.staticElement, node); |
| 297 return super.visitRedirectingConstructorInvocation(node); | 296 return super.visitRedirectingConstructorInvocation(node); |
| 298 } | 297 } |
| 299 | 298 |
| 300 @override | 299 @override |
| 301 Object visitSimpleIdentifier(SimpleIdentifier node) { | 300 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 302 _checkForDeprecatedMemberUseAtIdentifier(node); | 301 _checkForDeprecatedMemberUseAtIdentifier(node); |
| 303 _checkForInvalidProtectedPropertyAccess(node); | 302 _checkForInvalidProtectedMemberAccess(node); |
| 304 return super.visitSimpleIdentifier(node); | 303 return super.visitSimpleIdentifier(node); |
| 305 } | 304 } |
| 306 | 305 |
| 307 @override | 306 @override |
| 308 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { | 307 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
| 309 _checkForDeprecatedMemberUse(node.staticElement, node); | 308 _checkForDeprecatedMemberUse(node.staticElement, node); |
| 310 return super.visitSuperConstructorInvocation(node); | 309 return super.visitSuperConstructorInvocation(node); |
| 311 } | 310 } |
| 312 | 311 |
| 313 @override | 312 @override |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 if (!_typeSystem.isAssignableTo(bestRightType, leftType)) { | 670 if (!_typeSystem.isAssignableTo(bestRightType, leftType)) { |
| 672 _errorReporter.reportTypeErrorForNode( | 671 _errorReporter.reportTypeErrorForNode( |
| 673 HintCode.INVALID_ASSIGNMENT, rhs, [bestRightType, leftType]); | 672 HintCode.INVALID_ASSIGNMENT, rhs, [bestRightType, leftType]); |
| 674 return true; | 673 return true; |
| 675 } | 674 } |
| 676 } | 675 } |
| 677 return false; | 676 return false; |
| 678 } | 677 } |
| 679 | 678 |
| 680 /** | 679 /** |
| 681 * Produces a hint if the given invocation is of a protected method outside | 680 * Produces a hint if the given identifier is a protected closure, field or |
| 682 * a subclass instance method. | 681 * getter/setter, method closure or invocation accessed outside a subclass. |
| 683 */ | 682 */ |
| 684 void _checkForInvalidProtectedMethodCalls(MethodInvocation node) { | 683 void _checkForInvalidProtectedMemberAccess(SimpleIdentifier identifier) { |
| 685 Element element = node.methodName.bestElement; | 684 if (identifier.inDeclarationContext()) { |
| 686 if (element == null || !element.isProtected) { | |
| 687 return; | 685 return; |
| 688 } | 686 } |
| 689 | 687 |
| 690 ClassElement definingClass = element.enclosingElement; | 688 bool isProtected(Element element) { |
| 691 | 689 if (element is PropertyAccessorElement && |
| 692 MethodDeclaration decl = | 690 element.enclosingElement is ClassElement && |
| 693 node.getAncestor((AstNode node) => node is MethodDeclaration); | 691 (element.isProtected || element.variable.isProtected)) { |
| 694 if (decl == null) { | 692 return true; |
| 695 _errorReporter.reportErrorForNode( | 693 } |
| 696 HintCode.INVALID_USE_OF_PROTECTED_MEMBER, | 694 if (element is MethodElement && |
| 697 node, | 695 element.enclosingElement is ClassElement && |
| 698 [node.methodName.toString(), definingClass.name]); | 696 element.isProtected) { |
| 699 return; | 697 return true; |
| 698 } |
| 699 return false; |
| 700 } | 700 } |
| 701 | 701 |
| 702 ClassElement invokingClass = decl.element?.enclosingElement; | |
| 703 if (!_hasTypeOrSuperType(invokingClass, definingClass.type)) { | |
| 704 _errorReporter.reportErrorForNode( | |
| 705 HintCode.INVALID_USE_OF_PROTECTED_MEMBER, | |
| 706 node, | |
| 707 [node.methodName.toString(), definingClass.name]); | |
| 708 } | |
| 709 } | |
| 710 | |
| 711 /** | |
| 712 * Produces a hint if the given identifier is a protected field or getter | |
| 713 * accessed outside a subclass. | |
| 714 */ | |
| 715 void _checkForInvalidProtectedPropertyAccess(SimpleIdentifier identifier) { | |
| 716 if (identifier.inDeclarationContext()) { | |
| 717 return; | |
| 718 } | |
| 719 Element element = identifier.bestElement; | 702 Element element = identifier.bestElement; |
| 720 if (element is PropertyAccessorElement && | 703 if (isProtected(element)) { |
| 721 element.enclosingElement is ClassElement && | |
| 722 (element.isProtected || element.variable.isProtected)) { | |
| 723 ClassElement definingClass = element.enclosingElement; | 704 ClassElement definingClass = element.enclosingElement; |
| 724 ClassDeclaration accessingClass = | 705 ClassDeclaration accessingClass = |
| 725 identifier.getAncestor((AstNode node) => node is ClassDeclaration); | 706 identifier.getAncestor((AstNode node) => node is ClassDeclaration); |
| 726 | 707 if (accessingClass == null || |
| 727 if (accessingClass == null) { | 708 !_hasTypeOrSuperType(accessingClass.element, definingClass.type)) { |
| 728 _errorReporter.reportErrorForNode( | 709 _errorReporter.reportErrorForNode( |
| 729 HintCode.INVALID_USE_OF_PROTECTED_MEMBER, | 710 HintCode.INVALID_USE_OF_PROTECTED_MEMBER, |
| 730 identifier, | 711 identifier, |
| 731 [identifier.name.toString(), definingClass.name]); | |
| 732 } else if (!_hasTypeOrSuperType( | |
| 733 accessingClass.element, definingClass.type)) { | |
| 734 _errorReporter.reportErrorForNode( | |
| 735 HintCode.INVALID_USE_OF_PROTECTED_MEMBER, | |
| 736 identifier, | |
| 737 [identifier.name.toString(), definingClass.name]); | 712 [identifier.name.toString(), definingClass.name]); |
| 738 } | 713 } |
| 739 } | 714 } |
| 740 } | 715 } |
| 741 | 716 |
| 742 /** | 717 /** |
| 743 * Check that the imported library does not define a loadLibrary function. The
import has already | 718 * Check that the imported library does not define a loadLibrary function. The
import has already |
| 744 * been determined to be deferred when this is called. | 719 * been determined to be deferred when this is called. |
| 745 * | 720 * |
| 746 * @param node the import directive to evaluate | 721 * @param node the import directive to evaluate |
| (...skipping 10202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10949 return null; | 10924 return null; |
| 10950 } | 10925 } |
| 10951 if (identical(node.staticElement, variable)) { | 10926 if (identical(node.staticElement, variable)) { |
| 10952 if (node.inSetterContext()) { | 10927 if (node.inSetterContext()) { |
| 10953 result = true; | 10928 result = true; |
| 10954 } | 10929 } |
| 10955 } | 10930 } |
| 10956 return null; | 10931 return null; |
| 10957 } | 10932 } |
| 10958 } | 10933 } |
| OLD | NEW |