IntelliJ: 生成开关盒

在 IntelliJ 中真的没有办法为给定的变量生成开关情况吗?

Ctrl + Space 和 Ctrl + J 都没有结果。

46135 次浏览

For enum variables, enter switch (myEnumVar) and press Alt+Enter. Smart completion will suggest: Create missing 'switch' branches

Crazy Coder provided the following screenshot showing how to enable the Create Enum Switch Branches intention.

Intention: Create Enum Switch Branches

See YouTrack issue 6374.

Follow the steps here: https://confluence.jetbrains.com/display/PYH/Creating+and+applying+live+templates+(code+snippets)

for the context, use JAVA and the code for a switch - case Statement would be:

switch($switchVar$) {
case $value$:
$END$
break;
default:
break;
}

Do the same for try - catch ;)

try {
$END$
} catch(Exception e) {e.printStackTrace();}

I love the template function in intellij and use it a lot.