Structural Search/Replace Help

I want to replace my for loops that use iterators with the new easier to read for each loops using the structural search and replace mechanism. I want the following:

 iterator = stringlist.iterator(); iterator.hasNext()) {
     String str = iterator.next();
     Blah, Blah, Blah...:
}]]>

to become:

I can find the for loop with the following:

 $variable$ = $container$.iterator(); $variable$.hasNext();) {
    $Statements$;
}]]>

but I can't find the following statement to assign the variable. I thought that the following would work but it doesn't, what am I missing?

 $variable$ = $container$.iterator(); $variable$.hasNext();) {
    $Type$ $var2$ = $variable$.next();
    $Statements$;
}]]>

then the replace would be:

5 comments

Michael Tennes wrote:

>I want to replace my for loops that use iterators with the new easier to read for each loops
>


If that's possible - sorry, no answer, I'm on Mac => jdk 1.4 -
, JetBrains should add a
Migrate to jdk 5
section in the default Structural Replace templates.

I'm sure there are other valid candidates for automatized migration.

Alain

0

Hi,

Your template is correct, this is the bug in SR. I will fix it in
Pallada also.

Michael Tennes wrote:

I want to replace my for loops that use iterators with the new easier to read for each loops using the structural search and replace mechanism. I want the following:

 iterator = stringlist.iterator(); iterator.hasNext()) {
>      String str = iterator.next();
>      Blah, Blah, Blah...:
> }]]>

to become:

      Blah, Blah, Blah...;
> }]]>

I can find the for loop with the following:

 $variable$ = $container$.iterator(); $variable$.hasNext();) {
>     $Statements$;
> }]]>

but I can't find the following statement to assign the variable. I thought that the following would work but it doesn't, what am I missing?

 $variable$ = $container$.iterator(); $variable$.hasNext();) {
>     $Type$ $var2$ = $variable$.next();
>     $Statements$;
> }]]>

then the replace would be:

     $Statements$;
> }
> ]]>



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

Is there a way to define a live template for the new for loop or is that broken too?

0

Never mind, looks like you've already done it (the new iter live template).

0

Hi,

Done for upcoming 4.5.3 and 3087.

Maxim Mossienko wrote:

Hi,

Your template is correct, this is the bug in SR. I will fix it in
Pallada also.

Michael Tennes wrote:

>> I want to replace my for loops that use iterators with the new easier
>> to read for each loops using the structural search and replace
>> mechanism. I want the following:

 iterator = 
>> stringlist.iterator(); iterator.hasNext()) {
>>      String str = iterator.next();
>>      Blah, Blah, Blah...:
>> }]]>

to become:
>>

>      Blah, Blah, Blah...;
>> }]]>

I can find the for loop with the following:

> (Iterator $variable$ = $container$.iterator(); 
>> $variable$.hasNext();) {
>>     $Statements$;
>> }]]>

but I can't find the following statement to assign the
>> variable. I thought that the following would work but it doesn't, what
>> am I missing?

 $variable$ = 
>> $container$.iterator(); $variable$.hasNext();) {
>>     $Type$ $var2$ = $variable$.next();
>>     $Statements$;
>> }]]>

then the replace would be:

> $container$) {
>>     $Statements$;
>> }
>> ]]>




--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

Please sign in to leave a comment.