-
Notifications
You must be signed in to change notification settings - Fork 88
ReplaceStringBuilderWithString should keep newlines #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReplaceStringBuilderWithString should keep newlines #504
Conversation
src/test/java/org/openrewrite/staticanalysis/ReplaceStringBuilderWithStringTest.java
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/ReplaceStringBuilderWithString.java
Show resolved
Hide resolved
I can't help but wonder if registering a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ReplaceStringBuilderWithString.java
- lines 32-32
a7132e2
to
0f3da5d
Compare
src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/ReplaceStringBuilderWithString.java
Show resolved
Hide resolved
Nice improvement already! I suggest we merge this once the forced pushed issues are resolved. Separately after we could look into supporting comments as well, as this right now fails. @Test
@Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/88")
void retainComments() {
rewriteRun(
//language=java
java(
"""
class A {
void foo() {
String scenarioFour = new StringBuilder()
// A
.append("A")
// B
.append("B")
// C
.append("C")
.toString();
}
}
""",
"""
class A {
void foo() {
String scenarioFour =
// A
"A" +
// B
"B" +
// C
"C" +
testString();
}
}
"""
)
);
} |
…derWithString
What's changed?
ReplaceStringBuilderWithString
will retain the prefix white space for the removed method calls on the argument.What's your motivation?
Anything in particular you'd like reviewers to focus on?
Anyone you would like to review specifically?
Have you considered any alternatives or workarounds?
Any additional context
Checklist