mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-144236 try-with-resources causes auto-complete to fail
This commit is contained in:
+10
-1
@@ -126,7 +126,7 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
return ElementClassFilter.CLASS;
|
||||
}
|
||||
|
||||
if (psiElement().afterLeaf(psiElement(JavaTokenType.RBRACE).withParents(PsiCodeBlock.class, PsiTryStatement.class)).accepts(position) ||
|
||||
if (isCatchFinallyPosition(position) ||
|
||||
JavaKeywordCompletion.START_SWITCH.accepts(position) ||
|
||||
JavaKeywordCompletion.isInstanceofPlace(position) ||
|
||||
JavaKeywordCompletion.isAfterPrimitiveOrArrayType(position)) {
|
||||
@@ -166,6 +166,15 @@ 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);
|
||||
|
||||
@@ -303,8 +303,9 @@ public class JavaKeywordCompletion {
|
||||
if (statement != null && statement.getTextRange().getStartOffset() == position.getTextRange().getStartOffset()) {
|
||||
if (!psiElement().withSuperParent(2, PsiSwitchStatement.class).afterLeaf("{").accepts(statement)) {
|
||||
PsiTryStatement tryStatement = PsiTreeUtil.getParentOfType(prevLeaf, PsiTryStatement.class);
|
||||
if (tryStatement == null || tryStatement.getCatchSections().length > 0 || tryStatement.getFinallyBlock() != null) {
|
||||
if (tryStatement == null || tryStatement.getCatchSections().length > 0 || tryStatement.getFinallyBlock() != null || tryStatement.getResourceList() != null) {
|
||||
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Util {
|
||||
int goo() {
|
||||
try (Object foo = bar()) {
|
||||
|
||||
}
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
+6
@@ -56,4 +56,10 @@ public class Normal17CompletionTest extends LightFixtureCompletionTestCase {
|
||||
myFixture.type('\n')
|
||||
checkResultByFile(getTestName(false) + "_after.java")
|
||||
}
|
||||
|
||||
public void testAfterTryWithResources() {
|
||||
configureByFile(getTestName(false) + ".java")
|
||||
def strings = myFixture.lookupElementStrings
|
||||
assert strings.containsAll(['final', 'finally', 'int', 'Util'])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user