Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuilderReturnThis: Don't flag already annotated builder methods #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading