diff options
Diffstat (limited to 'java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/PlainEnterProcessor.java')
-rw-r--r-- | java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/PlainEnterProcessor.java | 20 |
1 files changed, 16 insertions, 4 deletions
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 6bafcc00d983..884442c778cc 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 @@ -83,6 +83,22 @@ public class PlainEnterProcessor implements EnterProcessor { @Nullable private static PsiCodeBlock getControlStatementBlock(int caret, PsiElement element) { + if (element instanceof PsiTryStatement) { + PsiCodeBlock tryBlock = ((PsiTryStatement)element).getTryBlock(); + if (tryBlock != null && caret < tryBlock.getTextRange().getEndOffset()) return tryBlock; + + for (PsiCodeBlock catchBlock : ((PsiTryStatement)element).getCatchBlocks()) { + if (catchBlock != null && caret < catchBlock.getTextRange().getEndOffset()) return catchBlock; + } + + return ((PsiTryStatement)element).getFinallyBlock(); + } + + if (element instanceof PsiMethod) { + PsiCodeBlock methodBody = ((PsiMethod)element).getBody(); + if (methodBody != null) return methodBody; + } + PsiStatement body = null; if (element instanceof PsiIfStatement) { body = ((PsiIfStatement)element).getThenBranch(); @@ -102,10 +118,6 @@ public class PlainEnterProcessor implements EnterProcessor { else if (element instanceof PsiDoWhileStatement) { body = ((PsiDoWhileStatement)element).getBody(); } - else if (element instanceof PsiMethod) { - PsiCodeBlock methodBody = ((PsiMethod)element).getBody(); - if (methodBody != null) return methodBody; - } return body instanceof PsiBlockStatement ? ((PsiBlockStatement)body).getCodeBlock() : null; } |