A zany refactoring question [message #153860] |
Thu, 06 November 2003 17:21  |
Eclipse User |
|
|
|
Originally posted by: johnhkc.earthlink.net
I'd like to know if the following is possible using Eclipse.
This is for use in a code generator.
Imagine I have a piece of Java code that stretches over many lines and
builds a String like this:
String mystr = "the " +
"cow " +
"said " +
"moo " +
"moo " +
"moo " +
"! ";
I want to write a refactoring routine where the user hilights a line that
will have a condition added. For example, I could highlight the last
"moo" and the refactoring routine would add an IF so that the code changes
to this:
String mystr = "the " +
"cow " +
"said " +
"moo " +
"moo ";
if ( someFlag == true )
{
mystr += "moo ";
}
mystr += "!";
Is there a way to programmatically parse through the String declaration,
see the last "moo", end the statement before it, surround the last "moo"
with a condition and append the trailing "!" as in the code above?
|
|
|
|
Re: A zany refactoring question [message #153965 is a reply to message #153860] |
Fri, 07 November 2003 03:04  |
Eclipse User |
|
|
|
John H wrote:
> I want to write a refactoring routine where the user hilights a line
> that will have a condition added. For example, I could highlight the
> last "moo" and the refactoring routine would add an IF so that the
> code changes to this:
> String mystr = "the " +
> "cow " +
> "said " +
> "moo " +
> "moo ";
> if ( someFlag == true )
> {
> mystr += "moo ";
> }
> mystr += "!";
If the code
String mystr = "the " +
"cow " +
"said " +
"moo " +
"moo " +
(someFlag ? "moo " : "") +
"!";
would be ok, too (it should be equivalent), this could be easily done using
code templates:
(${condition} ? ${word_selection} : "")
Take care, Ilja
|
|
|
Powered by
FUDForum. Page generated in 0.25355 seconds