Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 48240

Summary: [quick assist] Convert Immutable to Mutable (String to StringBuffer)
Product: [Eclipse Project] JDT Reporter: Mohamed ZERGAOUI <xmlizer>
Component: UIAssignee: Martin Aeschlimann <martinae>
Status: RESOLVED DUPLICATE QA Contact:
Severity: enhancement    
Priority: P4 CC: martinae
Version: 3.0Keywords: helpwanted
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Mohamed ZERGAOUI CLA 2003-12-07 16:53:58 EST
The main goal is to provide a way to convert some immutable, memory consuming, 
object to mutable object.
I imagine it would be in Right Click - Refactor - Immutable to Mutable 
For the beginning it will only work on String.
Selecting a String instance, it converts it to an StringBuffer instance, when 
there is concat() or operator + it will convert it to append(xxx) (as the 
compiler do, but this time you don't discard the StringBuffer object each time).
There will be some precondition to check.
In the case where the method doesn't have an equivalence in StringBuffer we 
have to use toString().
May be it won't be so useful as it may seem.
Comment 1 Dirk Baeumer CLA 2003-12-08 04:02:48 EST
This is more a quick assist than a refactoring.
Comment 2 Mohamed ZERGAOUI CLA 2004-04-15 10:25:20 EDT
This is an example
<pre>
...
String s = "";
for(int i = 0; i < MAX; i++) {
  switch (i % 3) {
    case 0 :
      s += "a";
      break;
    case 1 :
      s += "b";
      break;
    case 2 :
    default :
      s = "c" + s;   
  }
}
System.out.println(s);
...
</pre>
and when you select "s" and choose the quick assist "convert to StringBuffer"
or "convert to StringBuilder" (for 1.5)
you'll have
<pre>
...
StringBuffer s = new StringBuffer("");
for(int i = 0; i < MAX; i++) {
  switch (i % 3) {
    case 0 :
      s.append("a");
      break;
    case 1 :
      s.append("b");
      break;
    case 2 :
    default :
      s.insert(0, "c");   
  }
}
System.out.println(s);
...
</pre>
Comment 3 Mohamed ZERGAOUI CLA 2007-10-10 14:49:27 EDT
Is there any push in this direction ?
Comment 4 Mohamed ZERGAOUI CLA 2007-10-10 14:55:30 EDT
Furthermore it seems related to Bug 36350
Comment 5 Martin Aeschlimann CLA 2007-10-11 04:04:45 EDT
There are no plans at the moment for such a feature. Help is welcome to add this as a new quick assist.
Comment 6 Martin Aeschlimann CLA 2007-10-11 04:05:51 EDT

*** This bug has been marked as a duplicate of bug 36350 ***