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

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

Issue 2041873003: Fix @protected to include closure references (linter#255). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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/hint_code_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 23b8f9eb0511b619381df113b8f07b7262e0ea1b..2a141a60268d7cb81f04cf573c09c602c66f989c 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -262,7 +262,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
@override
Object visitMethodInvocation(MethodInvocation node) {
_checkForCanBeNullAfterNullAware(node.realTarget, node.operator);
- _checkForInvalidProtectedMethodCalls(node);
DartType staticInvokeType = node.staticInvokeType;
if (staticInvokeType is InterfaceType) {
MethodElement methodElement = staticInvokeType.lookUpMethod(
@@ -300,7 +299,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
@override
Object visitSimpleIdentifier(SimpleIdentifier node) {
_checkForDeprecatedMemberUseAtIdentifier(node);
- _checkForInvalidProtectedPropertyAccess(node);
+ _checkForInvalidProtectedMemberAccess(node);
return super.visitSimpleIdentifier(node);
}
@@ -678,59 +677,35 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
}
/**
- * Produces a hint if the given invocation is of a protected method outside
- * a subclass instance method.
+ * Produces a hint if the given identifier is a protected closure, field or
+ * getter/setter, method closure or invocation accessed outside a subclass.
*/
- void _checkForInvalidProtectedMethodCalls(MethodInvocation node) {
- Element element = node.methodName.bestElement;
- if (element == null || !element.isProtected) {
- return;
- }
-
- ClassElement definingClass = element.enclosingElement;
-
- MethodDeclaration decl =
- node.getAncestor((AstNode node) => node is MethodDeclaration);
- if (decl == null) {
- _errorReporter.reportErrorForNode(
- HintCode.INVALID_USE_OF_PROTECTED_MEMBER,
- node,
- [node.methodName.toString(), definingClass.name]);
+ void _checkForInvalidProtectedMemberAccess(SimpleIdentifier identifier) {
+ if (identifier.inDeclarationContext()) {
return;
}
- ClassElement invokingClass = decl.element?.enclosingElement;
- if (!_hasTypeOrSuperType(invokingClass, definingClass.type)) {
- _errorReporter.reportErrorForNode(
- HintCode.INVALID_USE_OF_PROTECTED_MEMBER,
- node,
- [node.methodName.toString(), definingClass.name]);
+ bool isProtected(Element element) {
+ if (element is PropertyAccessorElement &&
+ element.enclosingElement is ClassElement &&
+ (element.isProtected || element.variable.isProtected)) {
+ return true;
+ }
+ if (element is MethodElement &&
+ element.enclosingElement is ClassElement &&
+ element.isProtected) {
+ return true;
+ }
+ return false;
}
- }
- /**
- * 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 is PropertyAccessorElement &&
- element.enclosingElement is ClassElement &&
- (element.isProtected || element.variable.isProtected)) {
+ if (isProtected(element)) {
ClassElement definingClass = element.enclosingElement;
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 (!_hasTypeOrSuperType(
- accessingClass.element, definingClass.type)) {
+ if (accessingClass == null ||
+ !_hasTypeOrSuperType(accessingClass.element, definingClass.type)) {
_errorReporter.reportErrorForNode(
HintCode.INVALID_USE_OF_PROTECTED_MEMBER,
identifier,
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/hint_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698