IDEA-151470 Autocomplete not suggesting after finally block

This commit is contained in:
peter
2016-02-11 12:18:35 +01:00
parent d4d21bebf8
commit 15a7d36b6e
4 changed files with 19 additions and 10 deletions
@@ -99,6 +99,9 @@ public class JavaCompletionContributor extends CompletionContributor {
JavaTokenType.FLOAT_LITERAL, JavaTokenType.INTEGER_LITERAL)));
private static final ElementPattern<PsiElement> IMPORT_REFERENCE =
psiElement().withParent(psiElement(PsiJavaCodeReferenceElement.class).withParent(PsiImportStatementBase.class));
private static final ElementPattern<PsiElement> 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);
@@ -0,0 +1,7 @@
public class Test {
void fooBarGoo() {
try {}
finally {}
fbg<caret>
}
}
@@ -0,0 +1,7 @@
public class Test {
void fooBarGoo() {
try {}
finally {}
fooBarGoo();<caret>
}
}
@@ -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 {