@@ -79,11 +79,10 @@ public final class CanIgnoreReturnValueSuggester extends BugChecker implements M
79
79
80
80
private static final String AUTO_VALUE = "com.google.auto.value.AutoValue" ;
81
81
private static final String IMMUTABLE = "com.google.errorprone.annotations.Immutable" ;
82
+ private static final String CRV_SIMPLE_NAME = "CheckReturnValue" ;
82
83
private static final String CIRV_SIMPLE_NAME = "CanIgnoreReturnValue" ;
83
84
private static final ImmutableSet <String > EXEMPTING_METHOD_ANNOTATIONS =
84
- ImmutableSet .of (
85
- "com.google.errorprone.annotations.CheckReturnValue" ,
86
- "com.google.errorprone.refaster.annotation.AfterTemplate" );
85
+ ImmutableSet .of ("com.google.errorprone.refaster.annotation.AfterTemplate" );
87
86
88
87
private static final ImmutableSet <String > EXEMPTING_CLASS_ANNOTATIONS =
89
88
ImmutableSet .of (
@@ -112,14 +111,14 @@ public final class CanIgnoreReturnValueSuggester extends BugChecker implements M
112
111
@ Override
113
112
public Description matchMethod (MethodTree methodTree , VisitorState state ) {
114
113
MethodSymbol methodSymbol = getSymbol (methodTree );
115
- // Don't fire on overrides of methods within anonymous classes.
116
- if ( streamSuperMethods ( methodSymbol , state . getTypes ()). findFirst (). isPresent ()
117
- && methodSymbol . owner . isAnonymous ( )) {
114
+
115
+ // If the method is directly annotated w/ any @CanIgnoreReturnValue, then bail out.
116
+ if ( hasDirectAnnotationWithSimpleName ( methodSymbol , CIRV_SIMPLE_NAME )) {
118
117
return Description .NO_MATCH ;
119
118
}
120
119
121
- // If the method is @CanIgnoreReturnValue (in any package) , then bail out.
122
- if (hasDirectAnnotationWithSimpleName (methodSymbol , CIRV_SIMPLE_NAME )) {
120
+ // If the method is directly annotated w/ any @CheckReturnValue , then bail out.
121
+ if (hasDirectAnnotationWithSimpleName (methodSymbol , CRV_SIMPLE_NAME )) {
123
122
return Description .NO_MATCH ;
124
123
}
125
124
@@ -141,6 +140,12 @@ public Description matchMethod(MethodTree methodTree, VisitorState state) {
141
140
return Description .NO_MATCH ;
142
141
}
143
142
143
+ // Don't fire on overrides of methods within anonymous classes.
144
+ if (streamSuperMethods (methodSymbol , state .getTypes ()).findFirst ().isPresent ()
145
+ && methodSymbol .owner .isAnonymous ()) {
146
+ return Description .NO_MATCH ;
147
+ }
148
+
144
149
// if the method always return a single input param (of the same type), make it CIRV
145
150
if (methodAlwaysReturnsInputParam (methodTree , state )) {
146
151
return annotateWithCanIgnoreReturnValue (methodTree , state );
0 commit comments