auto case

I hope someone will tell me this already exists

I would like it if when I type  

switch ( someenum )

with a keystroke or two IntelliJ would list all the possible enums
each labelled with case xxx:

-



Lets say there are 7 enums. I specified 5 and left out two.

I would like it if IntelliJ would generate

default:
case missing1:
case missing2:

so that all cases are explicitly dealt with, even if default logic
handles them. I want some help catching errors where I forgot to
specify one of the options.


--
Roedy Green Canadian Mind Products http://mindprod.com
The art of strongly-typed language design is largely arranging
that errors are automatically detected as soon as possible
in the compose, compile, run cycle.

2 comments

On Mon, 11 Aug 2014 12:43:34 -0700, Roedy Green
<see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :

>
>default:
>case missing1:
>case missing2:

Are compilers smart enough not to generate any code for cases attached
to default?
--
Roedy Green Canadian Mind Products http://mindprod.com
The art of strongly-typed language design is largely arranging
that errors are automatically detected as soon as possible
in the compose, compile, run cycle.

0

Guest wrote:

switch ( someenum )

with a keystroke or two IntelliJ would list all the possible enums
each labelled with case xxx:


Using auto complete (Ctrl+Space) after typing the case keyword will allow you to list and add an enum individually. If you want to complete all, type the switch (enumVar) line, hit enter, then open the Intention Actions menu (Alt+Enter) and select "Create missing 'switch' branches".

In general, if you want or think some sort of auto-complete / auto-generate would be nice somewhere when coding, open the quick-fix/intentions actions menu (Alt+Enter) and see if what you want is there. You'd be surprised how often it is. (Sometimes you may need to try it with your cursor in different places).

0

Please sign in to leave a comment.