mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't suggest final after unfinished try (IDEA-104498)
This commit is contained in:
@@ -404,9 +404,13 @@ public class JavaCompletionData extends JavaAwareCompletionData {
|
||||
if (statement == null) {
|
||||
statement = PsiTreeUtil.getParentOfType(position, PsiDeclarationStatement.class);
|
||||
}
|
||||
PsiElement prevLeaf = PsiTreeUtil.prevVisibleLeaf(position);
|
||||
if (statement != null && statement.getTextRange().getStartOffset() == position.getTextRange().getStartOffset()) {
|
||||
if (!psiElement().withSuperParent(2, PsiSwitchStatement.class).afterLeaf("{").accepts(statement)) {
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
PsiTryStatement tryStatement = PsiTreeUtil.getParentOfType(prevLeaf, PsiTryStatement.class);
|
||||
if (tryStatement == null || tryStatement.getCatchSections().length > 0 || tryStatement.getFinallyBlock() != null) {
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,7 +467,7 @@ public class JavaCompletionData extends JavaAwareCompletionData {
|
||||
if (!(file instanceof PsiExpressionCodeFragment) &&
|
||||
!(file instanceof PsiJavaCodeReferenceCodeFragment) &&
|
||||
!(file instanceof PsiTypeCodeFragment)) {
|
||||
if (PsiTreeUtil.prevVisibleLeaf(position) == null) {
|
||||
if (prevLeaf == null) {
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.PACKAGE), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.IMPORT), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Util {
|
||||
void foo() {
|
||||
try {
|
||||
|
||||
}
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
class A {
|
||||
{
|
||||
try {}
|
||||
try {} catch (Exception e) {}
|
||||
fin<caret>x
|
||||
}
|
||||
}
|
||||
+3
-10
@@ -75,16 +75,8 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
|
||||
public void testMethodScope3() throws Exception { doTest(1, "final", "public", "static", "volatile", "abstract", "throws", "instanceof"); }
|
||||
public void testMethodScope4() throws Exception { doTest(6, "final", "try", "for", "while", "return", "throw"); }
|
||||
public void testMethodScope5() throws Exception { doTest(true); }
|
||||
public void testExtraBracketAfterFinally1() throws Exception {
|
||||
configureByFile(BASE_PATH + "/" + getTestName(true) + ".java");
|
||||
selectItem(myItems[1]);
|
||||
checkResultByFile(BASE_PATH + "/" + getTestName(true) + "_after.java");
|
||||
}
|
||||
public void testExtraBracketAfterFinally2() throws Exception {
|
||||
configureByFile(BASE_PATH + "/" + getTestName(true) + ".java");
|
||||
selectItem(myItems[1]);
|
||||
checkResultByFile(BASE_PATH + "/" + getTestName(true) + "_after.java");
|
||||
}
|
||||
public void testExtraBracketAfterFinally1() throws Exception { doTest(false); }
|
||||
public void testExtraBracketAfterFinally2() throws Exception { doTest(false); }
|
||||
public void testExtendsInCastTypeParameters() throws Exception { doTest(false); }
|
||||
public void testExtendsInCastTypeParameters2() throws Exception { doTest(2, "extends", "super"); }
|
||||
public void testExtendsWithRightContextInClassTypeParameters() throws Exception { doTest(false); }
|
||||
@@ -113,6 +105,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
|
||||
public void testFinalAfterParameterAnno2() throws Exception { doTest(2, "final", "float", "class"); }
|
||||
public void testFinalAfterCase() throws Exception { doTest(3, "final", "float", "class"); }
|
||||
public void testFinalInTryWithResources() throws Exception { doTest(1, "final", "float", "class"); }
|
||||
public void testNoFinalAfterTryBody() throws Exception { doTest(1, "final", "finally"); }
|
||||
public void testClassInMethod() throws Exception { doTest(2, "class", "char"); }
|
||||
public void testIntInClassArray() throws Throwable { doTest(2, "int", "char", "final"); }
|
||||
public void testIntInClassArray2() throws Throwable { doTest(2, "int", "char", "final"); }
|
||||
|
||||
Reference in New Issue
Block a user