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

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

Issue 2031053002: Extend @protected to include implemented interfaces. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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 d5035ee362263b63590c759d013c12d177814893..e14b4b07eae771af808e02797c743122a47dae8b 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -700,13 +700,11 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
}
ClassElement invokingClass = decl.element?.enclosingElement;
- if (invokingClass != null) {
- if (!_hasSuperClassOrMixin(invokingClass, definingClass.type)) {
- _errorReporter.reportErrorForNode(
- HintCode.INVALID_USE_OF_PROTECTED_MEMBER,
- node,
- [node.methodName.toString(), definingClass.name]);
- }
+ if (!_hasSuperType(invokingClass, definingClass.type)) {
+ _errorReporter.reportErrorForNode(
+ HintCode.INVALID_USE_OF_PROTECTED_MEMBER,
+ node,
+ [node.methodName.toString(), definingClass.name]);
}
}
@@ -731,8 +729,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
HintCode.INVALID_USE_OF_PROTECTED_MEMBER,
identifier,
[identifier.name.toString(), definingClass.name]);
- } else if (!_hasSuperClassOrMixin(
- accessingClass.element, definingClass.type)) {
+ } else if (!_hasSuperType(accessingClass.element, definingClass.type)) {
_errorReporter.reportErrorForNode(
HintCode.INVALID_USE_OF_PROTECTED_MEMBER,
identifier,
@@ -962,6 +959,25 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
}
/**
+ * Check for situations where the result of a method or function is used, when
+ * it returns 'void'.
+ *
+ * See [HintCode.USE_OF_VOID_RESULT].
+ */
+ void _checkForUseOfVoidResult(Expression expression) {
+ // TODO(jwren) Many other situations of use could be covered. We currently
+ // cover the cases var x = m() and x = m(), but we could also cover cases
+ // such as m().x, m()[k], a + m(), f(m()), return m().
+ if (expression is MethodInvocation) {
+ if (identical(expression.staticType, VoidTypeImpl.instance)) {
+ SimpleIdentifier methodName = expression.methodName;
+ _errorReporter.reportErrorForNode(
+ HintCode.USE_OF_VOID_RESULT, methodName, [methodName.name]);
+ }
+ }
+ }
+
+ /**
* Check for the passed class declaration for the
* [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code.
*
@@ -990,25 +1006,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
// return false;
// }
- /**
- * Check for situations where the result of a method or function is used, when
- * it returns 'void'.
- *
- * See [HintCode.USE_OF_VOID_RESULT].
- */
- void _checkForUseOfVoidResult(Expression expression) {
- // TODO(jwren) Many other situations of use could be covered. We currently
- // cover the cases var x = m() and x = m(), but we could also cover cases
- // such as m().x, m()[k], a + m(), f(m()), return m().
- if (expression is MethodInvocation) {
- if (identical(expression.staticType, VoidTypeImpl.instance)) {
- SimpleIdentifier methodName = expression.methodName;
- _errorReporter.reportErrorForNode(
- HintCode.USE_OF_VOID_RESULT, methodName, [methodName.name]);
- }
- }
- }
-
bool _hasSuperClassOrMixin(ClassElement element, InterfaceType type) {
List<ClassElement> seenClasses = <ClassElement>[];
while (element != null && !seenClasses.contains(element)) {
@@ -1027,6 +1024,9 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
return false;
}
+ bool _hasSuperType(ClassElement element, InterfaceType type) =>
+ element != null && element.allSupertypes.contains(type);
+
/**
* Given a parenthesized expression, this returns the parent (or recursively grand-parent) of the
* expression that is a parenthesized expression, but whose parent is not a parenthesized
« 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