Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,14 @@ public Description matchNewClass(NewClassTree tree, VisitorState state) {
parts.add(getOnlyElement(methodInvocationTree.getArguments()));
path = parentPath.getParentPath();
} else if (TO_STRING.matches(methodInvocationTree, state)) {
String replacement = replacement(state, parts);
Tree parent = grandParent.getParentPath().getLeaf();
if (parent instanceof MemberSelectTree memberSelectTree
&& memberSelectTree.getExpression().equals(methodInvocationTree)) {
replacement = "(" + replacement + ")";
}
return describeMatch(
methodInvocationTree,
SuggestedFix.replace(methodInvocationTree, replacement(state, parts)));
methodInvocationTree, SuggestedFix.replace(methodInvocationTree, replacement));
} else {
// another instance method on StringBuilder
return NO_MATCH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.google.errorprone.bugpatterns;

import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH;

import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.CompilationTestHelper;
import org.junit.Test;
Expand Down Expand Up @@ -204,7 +202,6 @@ void f() {
.doTest();
}

// TODO: b/472686687 - the refactoring should add parens
@Test
public void needsEnclosingParens() {
refactoringHelper
Expand All @@ -222,15 +219,10 @@ void f(String hello) {
"""
abstract class Test {
void f(String hello) {
hello + 1.getBytes();
(hello + 1).getBytes();
}
}
""")
// TODO: b/472686687 - remove allowBreakingChanges when the bug is fixed
.allowBreakingChanges()
// TODO: b/472686687 - remove allowFormattingErrors when the bug is fixed
.allowFormattingErrors()
// TODO: b/472686687 - remove TEXT_MATCH when the bug is fixed
.doTest(TEXT_MATCH);
.doTest();
}
}
Loading