IDEA-178377 No "final" completion suggestion in catch declaration

This commit is contained in:
peter
2017-09-16 19:11:43 +02:00
parent bca7598f88
commit 84f49683cb
4 changed files with 25 additions and 7 deletions
@@ -396,7 +396,7 @@ public class JavaKeywordCompletion {
}
}
if ((isInsideParameterList(myPosition) || isAtResourceVariableStart(myPosition) || isAtCatchVariableStart(myPosition)) &&
if ((isInsideParameterList(myPosition) || isAtCatchOrResourceVariableStart(myPosition)) &&
!psiElement().afterLeaf(PsiKeyword.FINAL).accepts(myPosition) &&
!AFTER_DOT.accepts(myPosition)) {
addKeyword(TailTypeDecorator.withTail(createKeyword(PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
@@ -732,12 +732,14 @@ public class JavaKeywordCompletion {
info -> InheritanceUtil.isInheritor(info.getType(), CommonClassNames.JAVA_LANG_CLASS)) != null;
}
private static boolean isAtResourceVariableStart(PsiElement position) {
return psiElement().insideStarting(psiElement(PsiTypeElement.class).withParent(PsiResourceList.class)).accepts(position);
}
private static boolean isAtCatchVariableStart(PsiElement position) {
return psiElement().insideStarting(psiElement(PsiTypeElement.class).withParent(PsiCatchSection.class)).accepts(position);
private static boolean isAtCatchOrResourceVariableStart(PsiElement position) {
PsiElement type = PsiTreeUtil.getParentOfType(position, PsiTypeElement.class);
if (type != null && type.getTextRange().getStartOffset() == position.getTextRange().getStartOffset()) {
PsiElement parent = type.getParent();
if (parent instanceof PsiVariable) parent = parent.getParent();
return parent instanceof PsiCatchSection || parent instanceof PsiResourceList;
}
return false;
}
private void addBreakContinue() {
@@ -0,0 +1,9 @@
public class X {
{
try {
} catch (<caret> AssertionError error) {
}
}
}
@@ -0,0 +1,5 @@
public class Util {
void foo() {
try (<caret> Type var = val)
}
}
@@ -139,7 +139,9 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
public void testNoCaseInsideWhileInSwitch() { doTest(0, "case", "default"); }
public void testFinalInCatch() { doTest(1, "final"); }
public void testFinalInIncompleteCatch() { doTest(1, "final"); }
public void testFinalInCompleteCatch() { doTest(1, "final"); }
public void testFinalInTryWithResources() { doTest(1, "final", "float", "class"); }
public void testFinalInCompleteTryWithResources() { doTest(1, "final", "float", "class"); }
public void testFinalInLambda() { doTest(2, "final", "float"); }
public void testNoFinalAfterTryBody() { doTest(1, "final", "finally"); }
public void testClassInMethod() { doTest(2, "class", "char"); }