Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2100)

Unified Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1730993003: Validation of @protected property accesses. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
*/
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698