Skip to content

Commit

Permalink
BuilderReturnThis: Dont flag already annotated builder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Sep 19, 2022
1 parent a034969 commit d3840ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.google.errorprone.fixes.SuggestedFixes.qualifyType;
import static com.google.errorprone.matchers.Description.NO_MATCH;
import static com.google.errorprone.util.ASTHelpers.getSymbol;
import static com.google.errorprone.util.ASTHelpers.hasAnnotation;
import static com.google.errorprone.util.ASTHelpers.isSameType;
import static com.google.errorprone.util.ASTHelpers.isSubtype;
import static java.lang.Boolean.TRUE;
Expand Down Expand Up @@ -57,6 +58,9 @@ public Description matchMethod(MethodTree tree, VisitorState state) {
if (tree.getBody() == null) {
return NO_MATCH;
}
if (hasAnnotation(tree, CRV, state)) {
return Description.NO_MATCH;
}
if (!instanceReturnsBuilder(sym, state)) {
return NO_MATCH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public void negative() {
testHelper
.addInputLines(
"Test.java",
"import com.google.errorprone.annotations.CheckReturnValue;",
"",
"class Test {",
" static class TestBuilder {",
" static TestBuilder builder() {",
Expand All @@ -58,6 +60,10 @@ public void negative() {
" TestBuilder setParens(String bar) {",
" return (this);",
" }",
" @CheckReturnValue",
" TestBuilder dontFlag(String flag) {",
" return new TestBuilder();",
" }",
" }",
"}")
.expectUnchanged()
Expand Down

0 comments on commit d3840ad

Please sign in to comment.