Skip to content

Commit

Permalink
Dont flag @AfterTemplate methods with @CIRV
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed May 13, 2023
1 parent c2b71f9 commit f6221f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public final class CanIgnoreReturnValueSuggester extends BugChecker implements M
private static final String IMMUTABLE = "com.google.errorprone.annotations.Immutable";
private static final String CRV = "com.google.errorprone.annotations.CheckReturnValue";
private static final String CIRV = "com.google.errorprone.annotations.CanIgnoreReturnValue";
private static final String REFASTER_AFTER_TEMPLATE =
"com.google.errorprone.refaster.annotation.AfterTemplate";

private static final Supplier<Type> PROTO_BUILDER =
VisitorState.memoize(s -> s.getTypeFromString("com.google.protobuf.MessageLite.Builder"));
Expand All @@ -87,8 +89,10 @@ public final class CanIgnoreReturnValueSuggester extends BugChecker implements M
public Description matchMethod(MethodTree methodTree, VisitorState state) {
MethodSymbol methodSymbol = getSymbol(methodTree);

// if the method is already directly annotated w/ @CRV or @CIRV, bail out
if (hasAnnotation(methodSymbol, CRV, state) || hasAnnotation(methodSymbol, CIRV, state)) {
// If the method is already directly annotated w/ @CRV, @CIRV, or @AfterTemplate, bail out.
if (hasAnnotation(methodSymbol, CRV, state)
|| hasAnnotation(methodSymbol, CIRV, state)
|| hasAnnotation(methodSymbol, REFASTER_AFTER_TEMPLATE, state)) {
return Description.NO_MATCH;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,24 @@ public void constructor() {
.doTest();
}

@Test
public void refasterAfterTemplate() {
helper
.addInputLines(
"A.java",
"import com.google.errorprone.refaster.annotation.AfterTemplate;",
"class A {",
" static final class MethodLacksBeforeTemplateAnnotation {",
" @AfterTemplate",
" String after(String str) {",
" return str;",
" }",
" }",
"}")
.expectUnchanged()
.doTest();
}

@Test
public void sometimesThrows() {
helper
Expand Down

0 comments on commit f6221f0

Please sign in to comment.