Ctrl-W and for loop

Over and over again I find myself trying to select all the setup
and control expressions of a for loop with Ctrl-W but it does
not work as I'm expecting (idea 4.5.2).

For example, with my cursor before "iterator":

for (Iterator i = list.|iterator(); i.hasNext(); ) {
...
}

I'd like to Ctrl-W a few times to select
"Iterator i = list.|iterator(); i.hasNext(); "
but can't because Idea selects the setup expression first
(Iterator i = .list.iterator();), and then selects the entire for
block.

I need that all the time to replace with the new for loops
( for (Item item : list) ... )

Does it "work as intended" or is it a problem?
Does anyone else know what I'm talking about? :)

Vince.



6 comments


It's as intended, I'm pretty sure. Ctrl-W just moves the selection to the parent parse tree element, and there is no intermediate element between the initialization or increment expressions and the whole for loop.

One bit of good news, there is an inspection in InspectionGadgets which will turn all of your old-style for loops into new style for-loops, if possible. The bad news is that the inspection is rather busted in the production builds, and won't be fixed until the Irida EAP. It works under some cases, but occasionally produces uncompilable code.

--Dave Griffith

0

Ah, I was thinking of writing an intention for the for conversion. I'll just
wait for a newer IG instead :)

Thanks,

Vince.


0

Vincent Mallet wrote:

I need that all the time to replace with the new for loops
( for (Item item : list) ... )


Sounds like the perfect use of a custom Intention Action plugin...

0

Actually it does not 100% replicate tree structure, there are some
exceptions. I don't know though if this special case deserves special
treatment.
If you think it does, please file a request to the tracker.

Eugene.

"Dave Griffith" <dave.griffith@cnn.com> wrote in message
news:25025770.1097863262234.JavaMail.itn@is.intellij.net...
>

It's as intended, I'm pretty sure. Ctrl-W just moves the selection to the

parent parse tree element, and there is no intermediate element between the
initialization or increment expressions and the whole for loop.
>

One bit of good news, there is an inspection in InspectionGadgets which

will turn all of your old-style for loops into new style for-loops, if
possible. The bad news is that the inspection is rather busted in the
production builds, and won't be fixed until the Irida EAP. It works under
some cases, but occasionally produces uncompilable code.
>

--Dave Griffith



0

You don't need to wait, I don't think -- the intention was there in 4.5.0, I haven't checked in 4.5.2 though.

0

Please sign in to leave a comment.