IntelliJ:生成开关盒

Ste*_*oth 71 java intellij-idea

是否真的无法为IntelliJ中的给定变量生成开关案例?

Ctrl + Space以及Ctrl + J不会产生任何结果.

Chr*_*ert 134

对于枚举变量,输入switch (myEnumVar)并按Alt+ Enter.智能完成将建议:Create missing 'switch' branches

Crazy Coder提供了以下屏幕截图,显示了如何启用Create Enum Switch Branches的意图.

意图:创建枚举开关分支

请参阅YouTrack issue 6374.

  • 此功能由需要启用的**Create Enum Switch Branches**提供:http://img844.imageshack.us/img844/6195/20120919130903.png. (4认同)

Fab*_*app 11

按照此处的步骤操作:https://confluence.jetbrains.com/display/PYH/Creating+and+applying+live+templates+(code+snippets)

对于上下文,使用JAVA和switch的代码 - case语句将是:

switch($switchVar$) {
case $value$:
    $END$
    break;
default:
    break;
}
Run Code Online (Sandbox Code Playgroud)

尝试做同样的事情 - 捕获;)

try {
$END$
} catch(Exception e) {e.printStackTrace();}
Run Code Online (Sandbox Code Playgroud)

我喜欢intellij中的模板功能并且使用它很多.

  • [这里是有关在 intelliJ 中创建实时模板的更新文档。](https://www.jetbrains.com/help/idea/creating-and-editing-live-templates.html)我刚刚在 IDE 中复制并粘贴了上面的文本,节省时间,谢谢@Fabian (2认同)