Skip to content

Commit

Permalink
Handle NO_MATCH in VisitorState#reportMatch instead of `Scanner
Browse files Browse the repository at this point in the history
This fix prevents reports such as the following, which are hard to debug
for users:
```
[INFO] /path/to/some/File.java: [<no match>] <no match>
   (see <no match>)

Fixes #1609

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=311378177
  • Loading branch information
Stephan202 authored and kluever committed May 14, 2020
1 parent 87d4fe5 commit 5fdc31e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ public ErrorProneOptions errorProneOptions() {
}

public void reportMatch(Description description) {
if (description == null || description == Description.NO_MATCH) {
return;
}
// TODO(cushon): creating Descriptions with the default severity and updating them here isn't
// ideal (we could forget to do the update), so consider removing severity from Description.
// Instead, there could be another method on the listener that took a description and a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ protected Set<? extends Name> getCustomSuppressionAnnotations(VisitorState state
}

protected void reportMatch(Description description, VisitorState state) {
if (description == null || description == Description.NO_MATCH) {
return;
}
state.reportMatch(description);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,19 @@ public void fieldNotPrivate_noMatch() {
.doTest();
}

@Test
public void unusedField_noMatch() {
compilationHelper
.addSourceLines(
"Test.java",
"import java.io.Serializable;",
"class Test implements Serializable {",
" private static final long serialVersionUID = 1L;",
"}")
.expectNoDiagnostics()
.doTest();
}

@Test
public void whenJodaAndJavaInstantUsed_fullyQualifiesName() {
refactoringHelper
Expand Down

0 comments on commit 5fdc31e

Please sign in to comment.