GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Avoid line continuation escapes in text blocks with mixed newline content by Jenson3210 · Pull Request #975 · openrewrite/rewrite-migrate-java

Avoid line continuation escapes in text blocks with mixed newline content #975

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.

Sign up for GitHub

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

Merged
timtebeek merged 1 commit into main from Jenson3210/fix-textblock-line-continuation
Jan 29, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Avoid line continuation escapes in text blocks with mixed newline content #975

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
2fd94c6
Add avoidLineContinuations option to UseTextBlocks
Jenson3210 Jan 27, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

18 changes: 17 additions & 1 deletion 18 src/main/java/org/openrewrite/java/migrate/lang/UseTextBlocks.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,27 @@ public class UseTextBlocks extends Recipe {
required = false)
boolean convertStringsWithoutNewlines;

@Option(displayName = "Whether to avoid line continuation escape sequences.",
description = "When enabled, the recipe avoids using `\\` line continuation escapes in text blocks " +
"where the content contains newlines. Non-newline-joined strings are placed on the same " +
"text block line instead. The default value is false.",
example = "true",
required = false)
boolean avoidLineContinuations;

public UseTextBlocks() {
convertStringsWithoutNewlines = true;
avoidLineContinuations = false;
}

public UseTextBlocks(boolean convertStringsWithoutNewlines) {
this.convertStringsWithoutNewlines = convertStringsWithoutNewlines;
this.avoidLineContinuations = false;
}

public UseTextBlocks(boolean convertStringsWithoutNewlines, boolean avoidLineContinuations) {
this.convertStringsWithoutNewlines = convertStringsWithoutNewlines;
this.avoidLineContinuations = avoidLineContinuations;
}

String displayName = "Use text blocks";
Expand Down Expand Up @@ -122,14 +137,15 @@ private J.Literal toTextBlock(J.Binary binary, String content, List<J.Literal> s
stringLiterals = stringLiterals.stream()
.filter(s -> s.getValue() != null && !s.getValue().toString().isEmpty())
.collect(toList());
boolean skipLineContinuations = avoidLineContinuations && containsNewLineInContent(content);
for (int i = 0; i < stringLiterals.size(); i++) {
String s = requireNonNull(stringLiterals.get(i).getValue()).toString();
sb.append(s);
originalContent.append(s);
if (i != stringLiterals.size() - 1) {
String nextLine = requireNonNull(stringLiterals.get(i + 1).getValue()).toString();
char nextChar = nextLine.charAt(0);
if (!s.endsWith("\n") && nextChar != '\n') {
if (!s.endsWith("\n") && nextChar != '\n' && !skipLineContinuations) {
sb.append(passPhrase);
}
}
Expand Down
93 changes: 93 additions & 0 deletions 93 src/test/java/org/openrewrite/java/migrate/lang/UseTextBlocksTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,99 @@ void shouldNotUpdateKotlinCode() {
);
}

@Issue("https://github.com/moderneinc/customer-requests/issues/1763")
@Test
void noLineContinuationWhenContentHasNewlines() {
rewriteRun(
spec -> spec.recipe(new UseTextBlocks(true, true)),
//language=java
java(
"""
class Test {
String query = "select count(1) cls_count\\n" +
"from my_table\\n" +
"where a.id = b.id\\n" +
"and a.ts > b.ts\\n" +
"and a.id = :tag_id \\n" +
"and a.stat_cd = 'ACTV'" +
" and a.del_fl = 'N'" +
" and a.rgn = :region";
}
""",
"""
class Test {
String query = \"""
select count(1) cls_count
from my_table
where a.id = b.id
and a.ts > b.ts
and a.id = :tag_id\\s
and a.stat_cd = 'ACTV' and a.del_fl = 'N' and a.rgn = :region\""";
Comment thread
timtebeek marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

}
"""
)
);
}

@Issue("https://github.com/moderneinc/customer-requests/issues/1763")
@Test
void noLineContinuationInMixedConcatenation() {
rewriteRun(
spec -> spec.recipe(new UseTextBlocks(true, true)),
//language=java
java(
"""
class Test {
String query = "select b.id, b.val\\n" +
"from my_table b, other_table c\\n" +
"where c.no = :no\\n" +
"and b.vrsn = c.vrsn" +
" and b.rgn = :region" +
" and b.del_fl = 'N'" +
" and c.rgn = :region";
}
""",
"""
class Test {
String query = \"""
select b.id, b.val
from my_table b, other_table c
where c.no = :no
and b.vrsn = c.vrsn and b.rgn = :region and b.del_fl = 'N' and c.rgn = :region\""";
}
"""
)
);
}

@Issue("https://github.com/moderneinc/customer-requests/issues/1763")
@Test
void noLineContinuationInMiddleOfMixedConcatenation() {
rewriteRun(
spec -> spec.recipe(new UseTextBlocks(true, true)),
//language=java
java(
"""
class Test {
String query = "select b.id\\n" +
"from my_table" +
" inner join other_table\\n" +
"where b.id = :id\\n";
}
""",
"""
class Test {
String query = \"""
select b.id
from my_table inner join other_table
where b.id = :id
\""";
}
"""
)
);
}

@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/555")
@Test
void textBlockTrailingEscape() {
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.