From 0df183f2af2b164db4148e3c692d735d4d7ffaa5 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 15 Feb 2016 19:07:58 +0100 Subject: [PATCH] java smart enter: place caret inside braces for switch statement followed by an empty line --- .../editorActions/smartEnter/PlainEnterProcessor.java | 4 ++++ .../codeInsight/completeStatement/SwitchBraces.java | 7 +++++++ .../completeStatement/SwitchBraces_after.java | 9 +++++++++ .../com/intellij/codeInsight/CompleteStatementTest.java | 1 + 4 files changed, 21 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/completeStatement/SwitchBraces.java create mode 100644 java/java-tests/testData/codeInsight/completeStatement/SwitchBraces_after.java diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/PlainEnterProcessor.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/PlainEnterProcessor.java index 884442c778cc..bf5db4cfa64a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/PlainEnterProcessor.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/PlainEnterProcessor.java @@ -99,6 +99,10 @@ public class PlainEnterProcessor implements EnterProcessor { if (methodBody != null) return methodBody; } + if (element instanceof PsiSwitchStatement) { + return ((PsiSwitchStatement)element).getBody(); + } + PsiStatement body = null; if (element instanceof PsiIfStatement) { body = ((PsiIfStatement)element).getThenBranch(); diff --git a/java/java-tests/testData/codeInsight/completeStatement/SwitchBraces.java b/java/java-tests/testData/codeInsight/completeStatement/SwitchBraces.java new file mode 100644 index 000000000000..1aad36d34c23 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completeStatement/SwitchBraces.java @@ -0,0 +1,7 @@ + +class foo { + void foo() { + switch (i) + + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completeStatement/SwitchBraces_after.java b/java/java-tests/testData/codeInsight/completeStatement/SwitchBraces_after.java new file mode 100644 index 000000000000..fe421da21405 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completeStatement/SwitchBraces_after.java @@ -0,0 +1,9 @@ + +class foo { + void foo() { + switch (i) { + + } + + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java index d0a25d0bc7b2..91fc2b189106 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java @@ -218,6 +218,7 @@ public class CompleteStatementTest extends EditorActionTestCase { public void testSwitchKeyword() throws Exception { doTest(); } public void testSwitchKeywordWithCondition() throws Exception { doTest(); } + public void testSwitchBraces() { doTest(); } public void testCaseColon() { doTest(); } public void testNewInParentheses() throws Exception { doTest(); }