Skip to content

Commit

Permalink
Variable created by ConstantPatternCompile should be private.
Browse files Browse the repository at this point in the history
Also fix the spacing issue.

Suggestions from #1655

flume hits : http://unknown commit

RELNOTES : Variable created by ConstantPatternCompile should be private. Also fix the spacing issue.
PiperOrigin-RevId: 322705160
  • Loading branch information
sumitbhagwani authored and Error Prone Team committed Jul 23, 2020
1 parent f849a90 commit 9e840a0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public Description matchVariable(VariableTree tree, VisitorState state) {
.replace(pos, pos + varName.length(), upperUnderscoreVarName)
.toString();

String modifiers = canUseStatic ? "static final " : "final ";
String variableTreeString = modifiers + variableReplacedString;
String modifiers = "private " + (canUseStatic ? "static " : "") + "final ";
String variableTreeString = modifiers + variableReplacedString + "\n";
SuggestedFix fix =
SuggestedFix.builder()
.merge(renameVariableOccurrences(tree, upperUnderscoreVarName, state))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testFixGenerationStatic() {
"import java.util.regex.Pattern;",
"class Test {",
" private static final String MY_COOL_PATTERN = \"a+\";",
" static final Pattern ATTERN = Pattern.compile(MY_COOL_PATTERN);",
" private static final Pattern ATTERN = Pattern.compile(MY_COOL_PATTERN);",
" public static void myPopularStaticMethod() {",
" Matcher m = ATTERN.matcher(\"aaaaab\");",
" }",
Expand Down Expand Up @@ -111,7 +111,7 @@ public void testFixGeneration_nonStaticInnerClass() {
"class Test {",
" private static final String MY_COOL_PATTERN = \"a+\";",
" class Inner {",
" final Pattern ATTERN = Pattern.compile(MY_COOL_PATTERN);",
" private final Pattern ATTERN = Pattern.compile(MY_COOL_PATTERN);",
" public void myPopularStaticMethod() {",
" Matcher m = ATTERN.matcher(\"aaaaab\");",
" }",
Expand Down

0 comments on commit 9e840a0

Please sign in to comment.