-
Notifications
You must be signed in to change notification settings - Fork 2
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
UnusedMethod: Support additional exempting method annotations #34
Conversation
3d2afe1
to
5f8ba8d
Compare
|
||
/** The set of types exempting a type that is extending or implementing them. */ | ||
private static final ImmutableSet<String> EXEMPTING_SUPER_TYPES = ImmutableSet.of(); | ||
|
||
private final ImmutableSet<String> exemptMethodAnnotations; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An open question:
- How do we want to name this variable? It is relatively similar to the setup in the
UnusedVariable
check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should stick with the "exempting" terminology, as the annotations "influence" whether the methods are flagged.
5f8ba8d
to
70431bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Added a commit and tweaked the suggested PR title.
" @Foo", | ||
" private void bar() {}", | ||
"}") | ||
.setArgs(ImmutableList.of("-XepOpt:UnusedMethod:ExemptMethodAnnotations=example.Foo")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.setArgs(ImmutableList.of("-XepOpt:UnusedMethod:ExemptMethodAnnotations=example.Foo")) | |
.setArgs("-XepOpt:UnusedMethod:ExemptMethodAnnotations=example.Foo") |
@@ -138,6 +139,21 @@ public void exemptedByName() { | |||
.doTest(); | |||
} | |||
|
|||
@Test | |||
public void exemptedByPassingViaArgs() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
public void exemptedByPassingViaArgs() { | |
public void exemptedByCustomAnnotation() { |
helper | ||
.addSourceLines("Foo.java", "package example;", "@interface Foo {}") | ||
.addSourceLines( | ||
"ExemptedViaArgs.java", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do a similar rename here; will push a proposal.
ImmutableSet.Builder<String> exemptMethodAnnotations = ImmutableSet.builder(); | ||
errorProneFlags | ||
.getList("UnusedMethod:ExemptMethodAnnotations") | ||
.ifPresent(exemptMethodAnnotations::addAll); | ||
this.exemptMethodAnnotations = exemptMethodAnnotations.build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ImmutableSet.Builder<String> exemptMethodAnnotations = ImmutableSet.builder(); | |
errorProneFlags | |
.getList("UnusedMethod:ExemptMethodAnnotations") | |
.ifPresent(exemptMethodAnnotations::addAll); | |
this.exemptMethodAnnotations = exemptMethodAnnotations.build(); | |
this.exemptMethodAnnotations = | |
errorProneFlags | |
.getList("UnusedMethod:ExemptMethodAnnotations") | |
.map(ImmutableSet::copyOf) | |
.orElseGet(ImmutableSet::of); |
|
||
/** The set of types exempting a type that is extending or implementing them. */ | ||
private static final ImmutableSet<String> EXEMPTING_SUPER_TYPES = ImmutableSet.of(); | ||
|
||
private final ImmutableSet<String> exemptMethodAnnotations; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should stick with the "exempting" terminology, as the annotations "influence" whether the methods are flagged.
public UnusedMethod(ErrorProneFlags errorProneFlags) { | ||
ImmutableSet.Builder<String> exemptMethodAnnotations = ImmutableSet.builder(); | ||
errorProneFlags | ||
.getList("UnusedMethod:ExemptMethodAnnotations") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably we can omit the second use of "Method", as that's implied.
Edit: but maybe later we also want to suppose class-level exempting methods, so perhaps better to keep it as-is.
We can squash the commits and use the suggested commit message? (current PR title)
One proposal/thing to consider, if we change the order of |
11119bd
to
10fcb9c
Compare
10fcb9c
to
a5d36e3
Compare
a5d36e3
to
99f8878
Compare
Fixed in google#3428. |
This solves two open issues (which can be linked if the PR is in a good state).