Intention string-concatenation to stringbuilder
Is there an intention to convert, for example,
return "foo " + value + " bar";
to
final StringBuilder buffer = new StringBuilder();
buffer.append("foo ");
buffer.append(value);
buffer.append(" bar");
return buffer.toString();
I only can find one which converts to a nasty long line of chained method calls:
return new StringBuilder().appened("foo ").append(value).
append(" bar").toString();
Tom
请先登录再写评论。
No, AFAIK there isn't.
Only if you already have a StringBuilder variable like in
StringBuilder builder = new StringBuilder().append("foo ").append("e").append(" bar");
there is an intention to convert that to a sequence like
StringBuilder builder = new StringBuilder();
builder.append("foo ");
builder.append("e");
builder.append(" bar");
So you first have to use "Introduce Variable" (ctrl-alt-v) on part of the expression.
Tom wrote:
Thanks, I'll try that. Although I still feel, that it rather should convert
it to my expected structure, because the other makes IMHO no more sense than
the original, but my expected structure allows to easily put if-statements
around some lines (which is the most often case for me converting the
concatenation to StringBuilder calls.
Tom
Stephen Friedrich wrote:
>> Is there an intention to convert, for example,
>>
>> return "foo " + value + " bar";
>>
>> to
>>
>> final StringBuilder buffer = new StringBuilder();
>> buffer.append("foo ");
>> buffer.append(value);
>> buffer.append(" bar");
>> return buffer.toString();
>>
>> I only can find one which converts to a nasty long line of chained
>> method calls:
>>
>> return new StringBuilder().appened("foo ").append(value).
>> append(" bar").toString();
>>
>> Tom
Hello Tom,
Please file a request with your suggestion and I will see what I can do to improve this intention.
Bas
Hi Bas, the issue is
http://www.jetbrains.net/jira/browse/IDEA-24166
Thanks in advance.
Tom
Hi Thomas,
That links seems to point to a different issue not related to the StringBuilder intention issue you are talking about here. Do you have another link?
Bas
You are right, I've mixed up these two RFEs. Here is the correct issue:
http://www.jetbrains.net/jira/browse/IDEA-24273
Thanks in advance,
Tom