You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The clean-up Convert String/StringBuffer/StringBuilder concatenation to Text Block is often not applicable on multi-line Strings that are built using StringBuffer/StringBuilder chains. The corresponding quick-fix is also not available when pressing Ctrl+1 at such expression.
When I manually convert the StringBuffer/StringBuilder chain into a simple String-concatenation using +, then the conversion to Text-block is possible.
In the first example, the StringBuffer is being passed as an argument to a method. The code generally looks to ensure the StringBuffer isn't being used again and also looks for a toString() call. In this case, additional checks need to be made to see if the StringBuffer is being passed as a String argument so toString() is implied. When you changed it to a concatenated String, it is different logic.
Thanks for your answer, that makes sense.
With that in mind I have to added that I changed the called method from accepting a StringBuffer to accept a CharSequence.
Without that it would indeed not be possible to change the concatenation to a Text-Block, but for a case like the following it should work theoretically:
- fix StringConcatToTextBlockFixCore to allow conversion if the
StringBuffer/StringBuilder is passed to a method as a String or
CharSequence argument, even if no toString() call is made
- add new tests to CleanUpTest15 and AssistQuickFixTest15
- fixeseclipse-jdt#1554
The clean-up
Convert String/StringBuffer/StringBuilder concatenation to Text Block
is often not applicable on multi-line Strings that are built usingStringBuffer/StringBuilder
chains. The corresponding quick-fix is also not available when pressing Ctrl+1 at such expression.When I manually convert the
StringBuffer/StringBuilder
chain into a simple String-concatenation using +, then the conversion to Text-block is possible.One specific example is
https://github.com/eclipse-pde/eclipse.pde/blob/e1b548604a23c54170625a6f9725e7465286624b/build/org.eclipse.pde.build.tests/src/org/eclipse/pde/build/internal/tests/p2/PublishingTests.java#L371-L396
But that file contains many more places where this does not work
https://github.com/eclipse-pde/eclipse.pde/blob/e1b548604a23c54170625a6f9725e7465286624b/build/org.eclipse.pde.build.tests/src/org/eclipse/pde/build/internal/tests/p2/PublishingTests.java
The text was updated successfully, but these errors were encountered: