mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Completion in multi-catch
This commit is contained in:
+6
-5
@@ -67,7 +67,6 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static void addAllClasses(CompletionParameters parameters, final CompletionResultSet result, @NotNull final Consumer<LookupElement> consumer) {
|
||||
@@ -76,10 +75,12 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
|
||||
final ElementFilter filter =
|
||||
or(JavaSmartCompletionContributor.AFTER_THROW_NEW,
|
||||
JavaCompletionContributor.INSIDE_METHOD_THROWS_CLAUSE,
|
||||
JavaCompletionContributor.IN_CATCH_TYPE).accepts(insertedElement) ? new AssignableFromFilter(CommonClassNames.JAVA_LANG_THROWABLE) :
|
||||
IN_TYPE_PARAMETER.accepts(insertedElement) ? new ExcludeDeclaredFilter(new ClassFilter(PsiTypeParameter.class)) :
|
||||
TrueFilter.INSTANCE;
|
||||
|
||||
JavaCompletionContributor.IN_CATCH_TYPE,
|
||||
JavaCompletionContributor.IN_MULTI_CATCH_TYPE).accepts(insertedElement)
|
||||
? new AssignableFromFilter(CommonClassNames.JAVA_LANG_THROWABLE)
|
||||
: IN_TYPE_PARAMETER.accepts(insertedElement)
|
||||
? new ExcludeDeclaredFilter(new ClassFilter(PsiTypeParameter.class))
|
||||
: TrueFilter.INSTANCE;
|
||||
|
||||
final boolean inJavaContext = parameters.getPosition() instanceof PsiIdentifier;
|
||||
if (AFTER_NEW.accepts(insertedElement)) {
|
||||
|
||||
+4
-1
@@ -90,6 +90,9 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
psiElement().withParent(psiElement(PsiJavaCodeReferenceElement.class).withParent(PsiImportStatementBase.class));
|
||||
static final PsiJavaElementPattern.Capture<PsiElement> IN_CATCH_TYPE =
|
||||
psiElement().afterLeaf(psiElement().withText("(").withParent(PsiCatchSection.class));
|
||||
static final ElementPattern<PsiElement> IN_MULTI_CATCH_TYPE =
|
||||
or(psiElement().afterLeaf(psiElement().withText("|").withParent(PsiTypeElement.class).withSuperParent(2, PsiCatchSection.class)),
|
||||
psiElement().afterLeaf(psiElement().withText("|").withParent(PsiTypeElement.class).withSuperParent(2, PsiParameter.class).withSuperParent(3, PsiCatchSection.class)));
|
||||
static final PsiJavaElementPattern.Capture<PsiElement> INSIDE_METHOD_THROWS_CLAUSE = psiElement().afterLeaf(PsiKeyword.THROWS, ",").inside(
|
||||
PsiMethod.class).andNot(psiElement().inside(PsiCodeBlock.class)).andNot(psiElement().inside(PsiParameterList.class));
|
||||
|
||||
@@ -128,7 +131,7 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
return ElementClassFilter.VARIABLE;
|
||||
}
|
||||
|
||||
if (IN_CATCH_TYPE.accepts(position)) {
|
||||
if (IN_CATCH_TYPE.accepts(position) || IN_MULTI_CATCH_TYPE.accepts(position)) {
|
||||
return new AssignableFromFilter(CommonClassNames.JAVA_LANG_THROWABLE);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
String name();
|
||||
}
|
||||
|
||||
@Column(<caret>)
|
||||
@Column<caret>
|
||||
@interface Annotation {
|
||||
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class MyClass {
|
||||
static class MyException extends Exception { }
|
||||
|
||||
void m() {
|
||||
try { } catch (MyException<caret>) { }
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class MyClass {
|
||||
static class MyException extends Exception { }
|
||||
|
||||
void m() {
|
||||
try { } catch (My<caret>) { }
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class MyClass {
|
||||
static class MyException extends Exception { }
|
||||
|
||||
void m() {
|
||||
try { } catch (MyException<caret> e) { }
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class MyClass {
|
||||
static class MyException extends Exception { }
|
||||
|
||||
void m() {
|
||||
try { } catch (My<caret> e) { }
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class MyClass {
|
||||
static class MyException extends Exception { }
|
||||
|
||||
void m() {
|
||||
try { } catch (RuntimeException | MyException<caret>) { }
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class MyClass {
|
||||
static class MyException extends Exception { }
|
||||
|
||||
void m() {
|
||||
try { } catch (RuntimeException | My<caret>) { }
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class MyClass {
|
||||
static class MyException extends Exception { }
|
||||
|
||||
void m() {
|
||||
try { } catch (RuntimeException | MyException<caret> e) { }
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class MyClass {
|
||||
static class MyException extends Exception { }
|
||||
|
||||
void m() {
|
||||
try { } catch (RuntimeException | My<caret> e) { }
|
||||
}
|
||||
}
|
||||
+25
-8
@@ -9,6 +9,8 @@ import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.module.JavaModuleType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
|
||||
@@ -70,7 +72,7 @@ public class ClassNameCompletionTest extends CompletionTestCase {
|
||||
|
||||
public void testInPlainTextFile() throws Exception {
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".txt");
|
||||
checkResultByFile(BASE_PATH + getTestName(false) + "_after.txt");
|
||||
checkResultByFile(BASE_PATH + getTestName(false) + "_after.txt");
|
||||
}
|
||||
|
||||
public void testDoubleStringBuffer() throws Exception {
|
||||
@@ -95,7 +97,7 @@ public class ClassNameCompletionTest extends CompletionTestCase {
|
||||
private void doTest() throws Exception {
|
||||
String path = BASE_PATH + "/java/";
|
||||
configureByFile(path + getTestName(false) + ".java");
|
||||
checkResultByFile(path + getTestName(false) + "_after.java");
|
||||
checkResultByFile(path + getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
public void testNameCompletionJava() throws Exception {
|
||||
@@ -108,14 +110,14 @@ public class ClassNameCompletionTest extends CompletionTestCase {
|
||||
checkResultByFile(path + "/test2-result.java");
|
||||
}
|
||||
|
||||
public void testImplementsFiltering1() throws Exception{
|
||||
public void testImplementsFiltering1() throws Exception {
|
||||
final String path = BASE_PATH + "/nameCompletion/java";
|
||||
configureByFile(path + "/test4-source.java");
|
||||
performAction();
|
||||
checkResultByFile(path + "/test4-result.java");
|
||||
}
|
||||
|
||||
public void testImplementsFiltering2() throws Exception{
|
||||
public void testImplementsFiltering2() throws Exception {
|
||||
final String path = BASE_PATH + "/nameCompletion/java";
|
||||
configureByFile(path + "/test3-source.java");
|
||||
performAction();
|
||||
@@ -135,7 +137,7 @@ public class ClassNameCompletionTest extends CompletionTestCase {
|
||||
return "testAnnotationFiltering".equals(getName());
|
||||
}
|
||||
|
||||
public void testAnnotationFiltering() throws Exception{
|
||||
public void testAnnotationFiltering() throws Exception {
|
||||
final String path = BASE_PATH + "/nameCompletion/java";
|
||||
configureByFile(path + "/test7-source.java");
|
||||
performAction();
|
||||
@@ -217,9 +219,23 @@ public class ClassNameCompletionTest extends CompletionTestCase {
|
||||
checkResultByFile(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-result.java");
|
||||
}
|
||||
|
||||
public void testInCatchType1() throws Exception { doJavaTest(); }
|
||||
|
||||
public void testInCatchType2() throws Exception { doJavaTest(); }
|
||||
|
||||
public void testInMultiCatchType1() throws Exception {
|
||||
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
|
||||
doJavaTest();
|
||||
}
|
||||
|
||||
public void testInMultiCatchType2() throws Exception {
|
||||
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
|
||||
doJavaTest();
|
||||
}
|
||||
|
||||
private void doJavaTest() throws Exception {
|
||||
final String path = BASE_PATH + "/nameCompletion/java";
|
||||
configureByFile(path + "/" + getTestName(false) + "-source.java");
|
||||
configureByFileNoCompletion(path + "/" + getTestName(false) + "-source.java");
|
||||
performAction();
|
||||
checkResultByFile(path + "/" + getTestName(false) + "-result.java");
|
||||
}
|
||||
@@ -237,10 +253,11 @@ public class ClassNameCompletionTest extends CompletionTestCase {
|
||||
CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(CompletionType.CLASS_NAME);
|
||||
handler.invokeCompletion(myProject, myEditor);
|
||||
final LookupManager instance = LookupManager.getInstance(myProject);
|
||||
if(instance instanceof LookupManagerImpl){
|
||||
if (instance instanceof LookupManagerImpl) {
|
||||
final LookupManagerImpl testLookupManager = ((LookupManagerImpl)instance);
|
||||
if(testLookupManager.getActiveLookup() != null)
|
||||
if (testLookupManager.getActiveLookup() != null) {
|
||||
testLookupManager.forceSelection(Lookup.NORMAL_SELECT_CHAR, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user