Chromium Code Reviews| Index: pkg/analyzer/lib/src/generated/resolver.dart |
| diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart |
| index f0d926bef3e8039fc56d1600386f28dec6587aea..9faabbd122422a9d0e60380d2cad43dadd6ca191 100644 |
| --- a/pkg/analyzer/lib/src/generated/resolver.dart |
| +++ b/pkg/analyzer/lib/src/generated/resolver.dart |
| @@ -238,6 +238,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> { |
| @override |
| Object visitSimpleIdentifier(SimpleIdentifier node) { |
| _checkForDeprecatedMemberUseAtIdentifier(node); |
| + _checkForInvalidProtectedPropertyAccess(node); |
| return super.visitSimpleIdentifier(node); |
| } |
| @@ -609,6 +610,41 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> { |
| } |
| /** |
| + * Produces a hint if the given identifier is a protected field or getter |
| + * accessed outside a subclass. |
| + */ |
| + void _checkForInvalidProtectedPropertyAccess(SimpleIdentifier identifier) { |
| + if (identifier.inDeclarationContext()) { |
| + return; |
| + } |
| + Element element = identifier.bestElement; |
| + if (element != null) { |
|
Brian Wilkerson
2016/02/24 19:54:25
The 'is' test below should negate the need to the
pquitslund
2016/02/24 20:34:43
Nice. I missed that when I refactored. Thanks!
|
| + if (element is PropertyAccessorElement && |
| + (element.isProtected || element.variable.isProtected)) { |
| + ClassElement definingClass = element.enclosingElement; |
| + if (definingClass == null) { |
| + return; |
| + } |
| + ClassDeclaration accessingClass = |
| + identifier.getAncestor((AstNode node) => node is ClassDeclaration); |
| + |
| + if (accessingClass == null) { |
| + _errorReporter.reportErrorForNode( |
| + HintCode.INVALID_USE_OF_PROTECTED_MEMBER, |
| + identifier, |
| + [identifier.name.toString(), definingClass.name]); |
| + } else if (!_hasSuperClassOrMixin( |
| + accessingClass.element, definingClass.type)) { |
| + _errorReporter.reportErrorForNode( |
| + HintCode.INVALID_USE_OF_PROTECTED_MEMBER, |
| + identifier, |
| + [identifier.name.toString(), definingClass.name]); |
| + } |
| + } |
| + } |
| + } |
| + |
| + /** |
| * Produces a hint if the given invocation is of a protected method outside |
| * a subclass instance method. |
| */ |