How to trigger intention for if-else if to switch

I have the intention enabled that is supposed to convert an if-else if statement to a switch statement; however, I can't figure out how to trigger it. I have tried pressing alt-enter on various places on the if statement (including on the if itself) but the intention just won't popup in the the intention dialog. The only one that pops up is "Invert If condition".

How do I trigger converting if-else if to switch?

Screen shot 2011-04-13 at 10.56.40 AM.PNG

0
Avatar
Permanently deleted user

Hi Michael,

Just tried that with the latest 10.5 EAP - works fine, i.e. 'if' is highlighted and I have the option to transform it to switch when I put cursor on it and press <enter>:

1. Put cursor on 'if':
if-to-switch1.png

2. Press Alt+Enter:
if-to-switch2.png

Denis

1
Avatar
Permanently deleted user

My conditionals are enums compared with the equals() method. I am going to change it to use == to see if that makes a difference. Or to see if using an enum is the problem.

I will do some testing...

0

I think, with IntelliJ 2021, this intention seems not to be available any more:

 

0

Hello Oliver,

Please share the code sample where the intention is expected, but not suggested. Thank you 

0

请先登录再写评论。