|
|
|
Re: Structural search (and replace) [message #258509 is a reply to message #258501] |
Thu, 05 February 2009 11:14   |
Eclipse User |
|
|
|
Originally posted by: none.domain.invalid
jan_bar a écrit :
> Name wrote:
>
>> jan_bar a écrit :
>>> Hi,
>>>
>>> IDEA has nice feature - Structural Search and Replace
>>> (http://www.jetbrains.com/idea/documentation/ssr.html), I miss this
>>> in Eclipse. Eclipse has AST parser and manipulator so this should be
>>> easy to implement. Do I miss something? Is this planned in future
>>> versions?
>
>> Well may be a rationale about productivity benefits. I guess it's a
>> hard feature to add, so there should be a good reason to do so.
>
>> By the way, Netbeans has an experimental plugin called "Jackpot" :
>> http://jackpot.netbeans.org/. But when you look at the sample rules
>> for automated code refactoring, you see that they are not really useful:
>
>> http://jackpot.netbeans.org/docs/rule_examples.html
>
>> What would be your use of such a feature ?
>
> Oh, there are many useful samples:
I will have to be unpleasant:
>
> Sample 1 (Effective Java, Item 4: Avoid creating duplicate objects)
> ========
> new java.lang.String($s) => $s (if $s is java.lang.String)
> new java.lang.Boolean($b) => java.lang.Boolean.valueOf($b);
both ban de done with the replace tool of eclipse
> Sample 2
> ========
> replace String '+' and '+=' with StringBuffer.append()
this replacement should be done only on "hotspot" which need to be
accelerated. The javac compiler is supposed to do it itself for all the
other places.
> Sample 3
> ========
> find all getters of some class
for what ?
> Sample 4
> ========
> change the parent class for many classes, e.g. instead of TestCase use
> OurTestCase class
again, the find and replace tool is powerful enough to do that
|
|
|
Re: Structural search (and replace) [message #258512 is a reply to message #258509] |
Thu, 05 February 2009 11:37   |
Eclipse User |
|
|
|
Name wrote:
> jan_bar a écrit :
>> Name wrote:
>>
>>> jan_bar a écrit :
>>>> Hi,
>>>>
>>>> IDEA has nice feature - Structural Search and Replace
>>>> (http://www.jetbrains.com/idea/documentation/ssr.html), I miss this
>>>> in Eclipse. Eclipse has AST parser and manipulator so this should be
>>>> easy to implement. Do I miss something? Is this planned in future
>>>> versions?
>>
>>> Well may be a rationale about productivity benefits. I guess it's a
>>> hard feature to add, so there should be a good reason to do so.
>>
>>> By the way, Netbeans has an experimental plugin called "Jackpot" :
>>> http://jackpot.netbeans.org/. But when you look at the sample rules
>>> for automated code refactoring, you see that they are not really useful:
>>
>>> http://jackpot.netbeans.org/docs/rule_examples.html
>>
>>> What would be your use of such a feature ?
>>
>> Oh, there are many useful samples:
> I will have to be unpleasant:
No problem, rebuttals bellow
>>
>> Sample 1 (Effective Java, Item 4: Avoid creating duplicate objects)
>> ========
>> new java.lang.String($s) => $s (if $s is java.lang.String)
>> new java.lang.Boolean($b) => java.lang.Boolean.valueOf($b);
> both ban de done with the replace tool of eclipse
String s;
s = new String("string");// <-- should be replaced
s = new String(s.toString());// <-- should be replaced
s = new String(new StringBuffer());// <-- cannot be replaced
How you will replace them in on one shot? You will have to write several
replacements and hope that did not missed any. When you specify that
replacement will take place only when the argument is of type String, you
are done.
>> Sample 2
>> ========
>> replace String '+' and '+=' with StringBuffer.append()
> this replacement should be done only on "hotspot" which need to be
> accelerated. The javac compiler is supposed to do it itself for all the
> other places.
This is theory. In practice IBM Java 1.5 javac implementation doesn't
optimise as well as SUN's:
String s = "";
for(int i = 0; i < 10; i++)
s += " ";// will create StringBuilder inside the loop
So you may want to refactor the code to use StringBuilder outside the loop.
>> Sample 3
>> ========
>> find all getters of some class
> for what ?
Maybe you want to modify getter method, for instance add a log message to
any getter.
>> Sample 4
>> ========
>> change the parent class for many classes, e.g. instead of TestCase use
>> OurTestCase class
> again, the find and replace tool is powerful enough to do that
No, the replace tool is dumb tool for refactoring. With replace tool you
will have troubles with various formatting (whitespaces).
Regards, Jan
H.
|
|
|
|
Re: Structural search (and replace) [message #258689 is a reply to message #258583] |
Fri, 13 February 2009 08:26  |
Eclipse User |
|
|
|
>> IDEA has nice feature - Structural Search and Replace
>> (http://www.jetbrains.com/idea/documentation/ssr.html), I miss this in
>> Eclipse. Eclipse has AST parser and manipulator so this should be easy
>> to implement. Do I miss something? Is this planned in future versions?
>>
>> Thank you, Jan
>>
> We already have a similar request for this:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=110157
> We started work in this area but unfortunately we never had enough time
> to finalize it. So any help would be very welcome...
In my opinion this is closely related to refactoring. Refactorings are
just already prepared seach&replace templates (of course just roughly). I
will try to find some time to look at possible solutions. I never did any
Eclipse development...
|
|
|
Powered by
FUDForum. Page generated in 0.03761 seconds