diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java index 71b214075b85..cfccd1a21404 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java @@ -99,6 +99,9 @@ public class JavaCompletionContributor extends CompletionContributor { JavaTokenType.FLOAT_LITERAL, JavaTokenType.INTEGER_LITERAL))); private static final ElementPattern IMPORT_REFERENCE = psiElement().withParent(psiElement(PsiJavaCodeReferenceElement.class).withParent(PsiImportStatementBase.class)); + private static final ElementPattern CATCH_OR_FINALLY = psiElement().afterLeaf( + psiElement().withText("}").withParent( + psiElement(PsiCodeBlock.class).afterLeaf(PsiKeyword.TRY))); @Nullable public static ElementFilter getReferenceFilter(PsiElement position) { @@ -126,7 +129,7 @@ public class JavaCompletionContributor extends CompletionContributor { return ElementClassFilter.CLASS; } - if (isCatchFinallyPosition(position) || + if (CATCH_OR_FINALLY.accepts(position) || JavaKeywordCompletion.START_SWITCH.accepts(position) || JavaKeywordCompletion.isInstanceofPlace(position) || JavaKeywordCompletion.isAfterPrimitiveOrArrayType(position)) { @@ -166,15 +169,6 @@ public class JavaCompletionContributor extends CompletionContributor { return TrueFilter.INSTANCE; } - private static boolean isCatchFinallyPosition(PsiElement position) { - PsiElement leaf = PsiTreeUtil.prevVisibleLeaf(position); - return leaf != null && - leaf.textMatches("}") && - leaf.getParent() instanceof PsiCodeBlock && - leaf.getParent().getParent() instanceof PsiTryStatement && - ((PsiTryStatement)leaf.getParent().getParent()).getResourceList() == null; - } - private static boolean isInsideAnnotationName(PsiElement position) { PsiAnnotation anno = PsiTreeUtil.getParentOfType(position, PsiAnnotation.class, true, PsiMember.class); return anno != null && PsiTreeUtil.isAncestor(anno.getNameReferenceElement(), position, true); diff --git a/java/java-tests/testData/codeInsight/completion/normal/MethodCallAfterFinally.java b/java/java-tests/testData/codeInsight/completion/normal/MethodCallAfterFinally.java new file mode 100644 index 000000000000..1e46286667ee --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/MethodCallAfterFinally.java @@ -0,0 +1,7 @@ +public class Test { + void fooBarGoo() { + try {} + finally {} + fbg + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/normal/MethodCallAfterFinally_after.java b/java/java-tests/testData/codeInsight/completion/normal/MethodCallAfterFinally_after.java new file mode 100644 index 000000000000..3ffe529283bc --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normal/MethodCallAfterFinally_after.java @@ -0,0 +1,7 @@ +public class Test { + void fooBarGoo() { + try {} + finally {} + fooBarGoo(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index d836f4a658e3..9bbe5cbd2ca3 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -479,6 +479,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase { configure() assertStringItems 'final', 'finalize' } + public void testMethodCallAfterFinally() { doTest() } public void testPrivateInAnonymous() throws Throwable { doTest() } public void testMethodParenthesesSpaces() throws Throwable {