Skip to content

Commit

Permalink
Fix trailing tab logic for converting to Text Block (#1244)
Browse files Browse the repository at this point in the history
- fix StringConcatToTextBlockFixCore.escapeTrailingWhitespace() method
- add new test to CleanUpTest15
- fixes #1240
  • Loading branch information
jjohnstn authored Mar 8, 2024
1 parent 9e6e796 commit 43c8c66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,12 @@ private static String escapeTrailingWhitespace(String unescaped) {
if (unescaped.charAt(whitespaceStart) == ' ') {
whitespaceStart--;
trailingWhitespace.append("\\s"); //$NON-NLS-1$
continue;
} else if (unescaped.charAt(whitespaceStart) == '\t') {
whitespaceStart--;
trailingWhitespace.append("\\t"); //$NON-NLS-1$
} else {
break;
}
break;
}

return unescaped.substring(0, whitespaceStart + 1) + trailingWhitespace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ public void testConcatToTextBlock() throws Exception {
+ " }\n" //
+ " public void testConcatInConstructor() {\n" //
+ " new StringBuffer(\"abc\\n\" + \"def\\n\" + \"ghi\");\n" //
+ " }\n" //
+ " public void testTabStart() {\n" //
+ " String x =\"\\tif (true) {\\n\" +\n" //
+ " \"\\t\\tstuff();\\n\" +\n" //
+ " \"\\t} else\\n\" +\n" //
+ " \"\\t\\tnoStuff\";\n" //
+ " }\n" //
+ "}\n";

Expand Down Expand Up @@ -182,7 +188,14 @@ public void testConcatToTextBlock() throws Exception {
+ " def\n" //
+ " ghi\"\"\");\n" //
+ " }\n" //
+ "}\n";
+ " public void testTabStart() {\n" //
+ " String x =\"\"\"\n" //
+ " \tif (true) {\n" //
+ " \t\tstuff();\n" //
+ " \t} else\n" //
+ " \t\tnoStuff\"\"\";\n" //
+ " }\n" //
+ "}\n";

assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }, null);
}
Expand Down

0 comments on commit 43c8c66

Please sign in to comment.