views:

460

answers:

3

Is there a template or something for generating a switch statement for Java enum in Eclipse?

So that when I got an enum and I want to have a switch with all the values, I didn't have to write all it myself?

A: 

Not that I know about. I think that you'd have to write it yourself.

I would be very surprised if you find this kind of template, because all the values in switch statement can do something totally different. I cannot see the way in which such template would work.

I know this answer is not helping much... sorry :)

Artur
Touko
+1  A: 

The content assists in Eclipse 3.4 will help you write the code. Just type case and press Ctrl+Space and you'll get a list of unused enums.

Aaron Digulla
Yes, but then I still got to write each one separately even though the completion speeds the process up.
Touko
+3  A: 

There certainly is, at least in 3.5.

Starting with something like this:

switch(a.getType()){

}

All you need to do is click on the switch keyword and hit CTRL+1. You should get a drop down which includes the option "Add missing case statements"

Peter Recore
Also works with eclipse 3.4
meriton
Nice, thanks. And in addition to this, using Ctrl-1 suggestions also with other cases than plain problems is a good thing to know.
Touko