mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
honor 'exclude from completion' settings (IDEA-54855)
This commit is contained in:
+8
-4
@@ -1,6 +1,7 @@
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.simple.PsiMethodInsertHandler;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.StaticImportMethodFix;
|
||||
import com.intellij.codeInsight.lookup.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -28,7 +29,7 @@ public class JavaGlobalMemberNameCompletionContributor extends CompletionContrib
|
||||
PsiFormatUtil.SHOW_PARAMETERS,
|
||||
PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE);
|
||||
if (containingClass != null) {
|
||||
presentation.setTailText(params + " in (" + containingClass.getName() + ")");
|
||||
presentation.setTailText(params + " in " + containingClass.getName());
|
||||
} else {
|
||||
presentation.setTailText(params);
|
||||
}
|
||||
@@ -98,9 +99,12 @@ public class JavaGlobalMemberNameCompletionContributor extends CompletionContrib
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC) && resolveHelper.isAccessible(method, position, null)) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
result.addElement(LookupElementDecorator.withInsertHandler(
|
||||
LookupElementDecorator.withRenderer(LookupElementBuilder.create(method), STATIC_METHOD_RENDERER),
|
||||
STATIC_METHOD_INSERT_HANDLER));
|
||||
if (!JavaCompletionUtil.isInExcludedPackage(containingClass) && !StaticImportMethodFix.isExcluded(method)) {
|
||||
result.addElement(LookupElementDecorator.withInsertHandler(
|
||||
LookupElementDecorator.withRenderer(LookupElementBuilder.create(method), STATIC_METHOD_RENDERER),
|
||||
STATIC_METHOD_INSERT_HANDLER));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -138,7 +138,7 @@ public class StaticImportMethodFix implements IntentionAction {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean isExcluded(PsiMethod method) {
|
||||
public static boolean isExcluded(PsiMethod method) {
|
||||
String name = getQName(method);
|
||||
CodeInsightSettings cis = CodeInsightSettings.getInstance();
|
||||
for (String excluded : cis.EXCLUDED_PACKAGES) {
|
||||
|
||||
+51
-6
@@ -1,6 +1,8 @@
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import com.intellij.codeInsight.CodeInsightSettings
|
||||
import com.intellij.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -17,13 +19,56 @@ public class Foo {
|
||||
}
|
||||
""")
|
||||
|
||||
myFixture.configureByText("a.java", "class Bar {{ abcm<caret> }}")
|
||||
|
||||
myFixture.complete(CompletionType.CLASS_NAME)
|
||||
myFixture.type('\n')
|
||||
myFixture.checkResult """import static foo.Foo.abcmethod;
|
||||
doTest "class Bar {{ abcm<caret> }}", """import static foo.Foo.abcmethod;
|
||||
|
||||
class Bar {{ abcmethod()<caret> }}"""
|
||||
}
|
||||
|
||||
@Override protected void tearDown() {
|
||||
CodeInsightSettings.instance.EXCLUDED_PACKAGES = ArrayUtil.EMPTY_STRING_ARRAY
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
public void testExcludeClassFromCompletion() throws Exception {
|
||||
myFixture.addClass("""package foo;
|
||||
public class Foo {
|
||||
public static int abcmethod() {}
|
||||
}
|
||||
""")
|
||||
myFixture.addClass("""package foo;
|
||||
public class Excl {
|
||||
public static int abcmethod2() {}
|
||||
}
|
||||
""")
|
||||
|
||||
CodeInsightSettings.instance.EXCLUDED_PACKAGES = ["foo.Excl"] as String[]
|
||||
|
||||
doTest "class Bar {{ abcm<caret> }}", """import static foo.Foo.abcmethod;
|
||||
|
||||
class Bar {{ abcmethod()<caret> }}"""
|
||||
}
|
||||
|
||||
public void testExcludeMethodFromCompletion() throws Exception {
|
||||
myFixture.addClass("""package foo;
|
||||
public class Foo {
|
||||
public static int abcmethod1() {}
|
||||
public static int abcmethodExcluded() {}
|
||||
}
|
||||
""")
|
||||
|
||||
CodeInsightSettings.instance.EXCLUDED_PACKAGES = ["foo.Foo.abcmethodExcluded"] as String[]
|
||||
|
||||
doTest "class Bar {{ abcm<caret> }}", """import static foo.Foo.abcmethod1;
|
||||
|
||||
class Bar {{ abcmethod1()<caret> }}"""
|
||||
}
|
||||
|
||||
private void doTest(String input, String output) {
|
||||
myFixture.configureByText("a.java", input)
|
||||
|
||||
assertOneElement myFixture.complete(CompletionType.CLASS_NAME)
|
||||
myFixture.type('\n')
|
||||
myFixture.checkResult output
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user