Skip to content

Commit

Permalink
Fix the workaround for SimpleCharStream.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 443616431
  • Loading branch information
graememorgan authored and Error Prone Team committed Apr 22, 2022
1 parent 330375e commit f489035
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION;
import static com.google.errorprone.matchers.Description.NO_MATCH;
import static com.google.errorprone.util.ASTHelpers.enclosingClass;
import static com.google.errorprone.util.ASTHelpers.getSymbol;

import com.google.common.base.CharMatcher;
Expand Down Expand Up @@ -74,7 +75,8 @@ private Description checkArrayDimensions(Tree tree, Tree type, VisitorState stat
if (idx > nonWhitespace) {
String replacement = dim.substring(idx) + dim.substring(0, idx);
// SimpleCharStream generates violations in other packages, and is challenging to fix.
if (getSymbol(tree).owner.name.contentEquals("SimpleCharStream")) {
var enclosingClass = enclosingClass(getSymbol(tree));
if (enclosingClass != null && enclosingClass.name.contentEquals("SimpleCharStream")) {
return NO_MATCH;
}
return describeMatch(tree, SuggestedFix.replace(start, end, replacement));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ public void negativeInSimpleCharStream() {
.addSourceLines(
"SimpleCharStream.java", //
"final class SimpleCharStream {",
" int a[];",
" void test() {",
" int a[];",
" }",
"}")
.doTest();
}
Expand Down

0 comments on commit f489035

Please sign in to comment.