Skip to content

Commit

Permalink
Fix StringBuffer/StringBuilder to text block to handle indexOf(x,y) (#…
Browse files Browse the repository at this point in the history
…1904)

- fix StringConcatToTextBlockFixCore.ChangeStringBufferToTextBlock
  to not assume indexOf() has just one parameter
- modify CleanUpTest15 to add new scenario
- fixes #1903
  • Loading branch information
jjohnstn authored Jan 7, 2025
1 parent 2213f68 commit cac5317
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2024 Red Hat Inc. and others.
* Copyright (c) 2021, 2025 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -1058,7 +1058,9 @@ public SourceRange computeSourceRange(final ASTNode nodeWithComment) {
SimpleName caller= ast.newSimpleName(newVarName);
newCall.setExpression(caller);
List<Expression> arguments= indexOfCall.arguments();
newCall.arguments().add(rewrite.createCopyTarget(arguments.get(0)));
for (Expression argument : arguments) {
newCall.arguments().add(rewrite.createCopyTarget(argument));
}
rewrite.replace(indexOfCall, newCall, group);
}
for (SimpleName arg : fArgList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ public void foo() {
StringBuilder buf9 = new StringBuilder("abc\\n").append("def\\n").append("ghi");
buf9.append("jkl\\n").append("mno");
System.out.println(buf9.toString());
int index2 = buf9.indexOf("ijk", 3); //$NON-NLS-1$
StringBuilder buf10= new StringBuilder();
buf10.append(" /** bar\\n");
buf10.append(" * foo\\n");
Expand Down Expand Up @@ -531,6 +532,7 @@ public class C {
jkl
mno\""";
System.out.println(str7);
int index2 = str7.indexOf("ijk", 3); //$NON-NLS-1$
String str8 = \"""
/** bar
* foo
Expand Down

0 comments on commit cac5317

Please sign in to comment.