Skip to content

Commit

Permalink
Modify string concat to text block cleanup to handle empty strings (#…
Browse files Browse the repository at this point in the history
…1717)

- add logic to StringConcatToTextBlockFixCore to handle the case where
  empty strings are appended
- modify tests in CleanUpTest15 to add some empty strings to existing
  tests
- for #1703
  • Loading branch information
jjohnstn authored Oct 15, 2024
1 parent 29f2f2d commit c2ceaa2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public boolean visit(final InfixExpression visited) {
endPosition= getLineOffset(cUnit, lineNo + 1) == -1 ? cUnit.getLength() : getLineOffset(cUnit, lineNo + 1);
hasComments= hasComments || hasNLS(ASTNodes.getCommentsForRegion(cUnit, stringLiteral.getStartPosition(), endPosition - stringLiteral.getStartPosition()), cu);
String string= stringLiteral.getLiteralValue();
if (!string.isEmpty() && (fAllConcats || string.endsWith("\n") || i == extendedOperands.size() - 1)) { //$NON-NLS-1$
if (string.isEmpty() || fAllConcats || string.endsWith("\n") || i == extendedOperands.size() - 1) { //$NON-NLS-1$
continue;
}
}
Expand Down Expand Up @@ -315,8 +315,11 @@ public SourceRange computeSourceRange(final ASTNode nodeWithComment) {
expressions.forEach(new Consumer<Expression>() {
@Override
public void accept(Expression t) {
String value= ((StringLiteral) t).getEscapedValue();
parts.addAll(unescapeBlock(value.substring(1, value.length() - 1)));
StringLiteral literal= (StringLiteral)t;
if (!literal.getLiteralValue().equals("\"\"")) { //$NON-NLS-1$
String value= literal.getEscapedValue();
parts.addAll(unescapeBlock(value.substring(1, value.length() - 1)));
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ public void testParameter() {
Integer k = foo("" +\s
"abcdef\\n" +\s
"123456\\n" +\s
"klm");
"klm" +\s
"");
}
public void testAssignment() {
Integer k = null;
k = foo("" +\s
"abcdef\\n" +\s
"123456\\n" +\s
"klm");
"" + "klm");
}
public void testConcatInConstructor() {
new StringBuffer("abc\\n" + "def\\n" + "ghi");
Expand Down

0 comments on commit c2ceaa2

Please sign in to comment.