.append cleanup

The latest version of Intellij does not have the ability to convert
code of this form:

sb.append( x ).append( y ).append( z );
to
sb.append( x );
sb.append( y );
sb.append( z );

if sb is some sort of StringBuilder clone. It would be nice if that
pattern could work on any class where append behaves the same way that
StringBuilder does.





--
Roedy Green Canadian Mind Products
http://mindprod.com
Dont be discouraged by a failure. It can be a positive experience. Failure is, in a sense, the highway to success, inasmuch as every discovery of what is false leads us to seek earnestly after what is true, and every fresh experience points out some form of error which we shall afterwards carefully avoid.
~ John Keats (born: 1795-10-31 died: 1821-02-23 at age: 25)

1 comment
Comment actions Permalink

On 1/25/2010 10:48 PM, Roedy Green wrote:

The latest version of Intellij does not have the ability to convert
code of this form:

>

sb.append( x ).append( y ).append( z );
to
sb.append( x );
sb.append( y );
sb.append( z );

>

if sb is some sort of StringBuilder clone. It would be nice if that
pattern could work on any class where append behaves the same way that
StringBuilder does.


It might be worth adding a refactoring "unchain" or some such...  Any
method which returns the same type as the class containing the method
would be eligible, with the caveat that the returned value may not be
"this".

It would be even better if it could be determined statically that "this"
must be returned.

0

Please sign in to leave a comment.