如何自动将if-else if语句转换为switch [英] How to automatically convert if-else if statement to switch

查看:3343
本文介绍了如何自动将if-else if语句转换为switch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有热键或简单的方法用IntelliJ中的开关替换if-else if语句?我宁愿不手动将if-else if语句转换为开关。我希望能够突出显示if-else if语句并按下组合键或使用菜单按钮。

Is there a hot key or easy way to replace an if-else if statement with a switch in IntelliJ? I would prefer not to manually convert the if-else if statement to a switch. I am looking to be able to highlight the if-else if statement and press a combination of keys or use a menu button.

推荐答案

更新:正如@christopheml在另一个答案的评论中指出的那样,如果用Switch切换似乎在IntelliJ 2018.1中消失了。已经提交了一个错误此处

Update: as @christopheml pointed out in comments on another answer, "Replace If with Switch" seems to have disappeared in IntelliJ 2018.1. A bug has been filed here.

IntelliJ意图命名为替换If with Switch和Replace Switch with If。检查您的首选项以查看是否已启用这些选项。如果是这样,我希望您会在Mac上看到一个quickfix选项( Option + Enter Alt + Enter 在Windows上)每当IntelliJ可以自动处理从一个到另一个的转换。

There are IntelliJ intentions named "Replace If with Switch" and "Replace Switch with If". Check your preferences to see if those options are enabled. If so, I would expect that you would see a quickfix option (Option+Enter on Mac, Alt+Enter on Windows) whenever IntelliJ can automatically handle the conversion from one to the other.

这篇关于如何自动将if-else if语句转换为switch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆