| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 @override | 231 @override |
| 232 Object visitRedirectingConstructorInvocation( | 232 Object visitRedirectingConstructorInvocation( |
| 233 RedirectingConstructorInvocation node) { | 233 RedirectingConstructorInvocation node) { |
| 234 _checkForDeprecatedMemberUse(node.staticElement, node); | 234 _checkForDeprecatedMemberUse(node.staticElement, node); |
| 235 return super.visitRedirectingConstructorInvocation(node); | 235 return super.visitRedirectingConstructorInvocation(node); |
| 236 } | 236 } |
| 237 | 237 |
| 238 @override | 238 @override |
| 239 Object visitSimpleIdentifier(SimpleIdentifier node) { | 239 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 240 _checkForDeprecatedMemberUseAtIdentifier(node); | 240 _checkForDeprecatedMemberUseAtIdentifier(node); |
| 241 _checkForInvalidProtectedPropertyAccess(node); |
| 241 return super.visitSimpleIdentifier(node); | 242 return super.visitSimpleIdentifier(node); |
| 242 } | 243 } |
| 243 | 244 |
| 244 @override | 245 @override |
| 245 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { | 246 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
| 246 _checkForDeprecatedMemberUse(node.staticElement, node); | 247 _checkForDeprecatedMemberUse(node.staticElement, node); |
| 247 return super.visitSuperConstructorInvocation(node); | 248 return super.visitSuperConstructorInvocation(node); |
| 248 } | 249 } |
| 249 | 250 |
| 250 @override | 251 @override |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 if (!_typeSystem.isAssignableTo(bestRightType, leftType)) { | 603 if (!_typeSystem.isAssignableTo(bestRightType, leftType)) { |
| 603 _errorReporter.reportTypeErrorForNode( | 604 _errorReporter.reportTypeErrorForNode( |
| 604 HintCode.INVALID_ASSIGNMENT, rhs, [bestRightType, leftType]); | 605 HintCode.INVALID_ASSIGNMENT, rhs, [bestRightType, leftType]); |
| 605 return true; | 606 return true; |
| 606 } | 607 } |
| 607 } | 608 } |
| 608 return false; | 609 return false; |
| 609 } | 610 } |
| 610 | 611 |
| 611 /** | 612 /** |
| 613 * Produces a hint if the given identifier is a protected field or getter |
| 614 * accessed outside a subclass. |
| 615 */ |
| 616 void _checkForInvalidProtectedPropertyAccess(SimpleIdentifier identifier) { |
| 617 if (identifier.inDeclarationContext()) { |
| 618 return; |
| 619 } |
| 620 Element element = identifier.bestElement; |
| 621 if (element is PropertyAccessorElement && |
| 622 (element.isProtected || element.variable.isProtected)) { |
| 623 ClassElement definingClass = element.enclosingElement; |
| 624 if (definingClass == null) { |
| 625 return; |
| 626 } |
| 627 ClassDeclaration accessingClass = |
| 628 identifier.getAncestor((AstNode node) => node is ClassDeclaration); |
| 629 |
| 630 if (accessingClass == null) { |
| 631 _errorReporter.reportErrorForNode( |
| 632 HintCode.INVALID_USE_OF_PROTECTED_MEMBER, |
| 633 identifier, |
| 634 [identifier.name.toString(), definingClass.name]); |
| 635 } else if (!_hasSuperClassOrMixin( |
| 636 accessingClass.element, definingClass.type)) { |
| 637 _errorReporter.reportErrorForNode( |
| 638 HintCode.INVALID_USE_OF_PROTECTED_MEMBER, |
| 639 identifier, |
| 640 [identifier.name.toString(), definingClass.name]); |
| 641 } |
| 642 } |
| 643 } |
| 644 |
| 645 /** |
| 612 * Produces a hint if the given invocation is of a protected method outside | 646 * Produces a hint if the given invocation is of a protected method outside |
| 613 * a subclass instance method. | 647 * a subclass instance method. |
| 614 */ | 648 */ |
| 615 void _checkForInvalidProtectedMethodCalls(MethodInvocation node) { | 649 void _checkForInvalidProtectedMethodCalls(MethodInvocation node) { |
| 616 Element element = node.methodName.bestElement; | 650 Element element = node.methodName.bestElement; |
| 617 if (element == null || !element.isProtected) { | 651 if (element == null || !element.isProtected) { |
| 618 return; | 652 return; |
| 619 } | 653 } |
| 620 | 654 |
| 621 ClassElement definingClass = element.enclosingElement; | 655 ClassElement definingClass = element.enclosingElement; |
| (...skipping 12324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12946 nonFields.add(node); | 12980 nonFields.add(node); |
| 12947 return null; | 12981 return null; |
| 12948 } | 12982 } |
| 12949 | 12983 |
| 12950 @override | 12984 @override |
| 12951 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 12985 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 12952 | 12986 |
| 12953 @override | 12987 @override |
| 12954 Object visitWithClause(WithClause node) => null; | 12988 Object visitWithClause(WithClause node) => null; |
| 12955 } | 12989 } |
| OLD | NEW |