Skip to content

Commit

Permalink
Add parens around the replaced node & update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nakulj committed Jun 6, 2024
1 parent 66eb977 commit 8ada3c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
return buildDescription(tree)
.setMessage(MESSAGE)
.addFix(SuggestedFix.builder()
.prefixWith(tree, "(")
.postfixWith(tree, ")")
.replace(
tree,
Streams.concat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void shouldWarnOnConstantNumberOfParams_fix() {
" }",
"}")
.addOutputLines(
"Test.java", "class Test {", " String f() {", " return \"foo\" + 1;", " }", "}")
"Test.java", "class Test {", " String f() {", " return (\"foo\" + 1);", " }", "}")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
}

Expand Down Expand Up @@ -86,7 +86,7 @@ public void shouldWarnOnConstantNumberOfParams_stringCtor_fix() {
"Test.java",
"class Test {",
" String f() {",
" return \"ctor\" + \"foo\" + 1;",
" return (\"ctor\" + \"foo\" + 1);",
" }",
"}")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
Expand Down Expand Up @@ -120,7 +120,7 @@ public void shouldWarnOnConstantNumberOfParams_charSequenceCtor_fix() {
"Test.java",
"class Test {",
" String f(CharSequence charSequence) {",
" return \"\" + charSequence + \"foo\" + 1;",
" return (\"\" + charSequence + \"foo\" + 1);",
" }",
"}")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
Expand Down Expand Up @@ -154,7 +154,7 @@ public void shouldWarnOnConstantNumberOfNonConstantParams_fix() {
"Test.java",
"class Test {",
" String f(long param0, double param1) {",
" return \"\" + param0 + param1;",
" return (\"\" + param0 + param1);",
" }",
"}")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
Expand All @@ -174,7 +174,7 @@ public void shouldWarnOnConstantNumberOfNonConstantParams_firstString_fix() {
"Test.java",
"class Test {",
" String f(String param0, double param1) {",
" return param0 + param1;",
" return (param0 + param1);",
" }",
"}")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
Expand Down Expand Up @@ -239,7 +239,7 @@ public void shouldWarnOnNoParams_fix() {
" return new StringBuilder().toString();",
" }",
"}")
.addOutputLines("Test.java", "class Test {", " String f() {", " return \"\";", " }", "}")
.addOutputLines("Test.java", "class Test {", " String f() {", " return (\"\");", " }", "}")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
}

Expand All @@ -257,7 +257,7 @@ public void suggestedFixRetainsCast() {
"Test.java",
"class Test {",
" String f(Object obj) {",
" return (String) obj + 1;",
" return ((String) obj + 1);",
" }",
"}")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
Expand All @@ -281,7 +281,7 @@ public void suggestedFixHandlesTernary() {
"Test.java",
"class Test {",
" String f(Object obj) {",
" return \"a\" + (obj == null ? \"nil\" : obj) + \"b\";",
" return (\"a\" + (obj == null ? \"nil\" : obj) + \"b\");",
" }",
"}")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
Expand All @@ -305,7 +305,7 @@ public void suggestedFixHandlesAddition() {
"Test.java",
"class Test {",
" String f(int param0, int param1) {",
" return \"a\" + (param0 + param1) + \"b\";",
" return (\"a\" + (param0 + param1) + \"b\");",
" }",
"}")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
Expand Down

0 comments on commit 8ada3c1

Please sign in to comment.