mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't suggest void methods in a context where some return value is expected (suggest on second invocation)
This commit is contained in:
@@ -247,6 +247,8 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
if (reference instanceof PsiJavaReference) {
|
||||
final ElementFilter filter = getReferenceFilter(position);
|
||||
if (filter != null) {
|
||||
boolean filterVoid = JavaSmartCompletionContributor.getExpectedTypes(parameters).length > 0 && parameters.getInvocationCount() < 2;
|
||||
|
||||
final boolean isSwitchLabel = SWITCH_LABEL.accepts(position);
|
||||
final PsiFile originalFile = parameters.getOriginalFile();
|
||||
for (LookupElement element : JavaCompletionUtil.processJavaReference(position,
|
||||
@@ -268,6 +270,11 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
item.setTailType(TailType.NONE);
|
||||
}
|
||||
|
||||
Object object = element.getObject();
|
||||
if (filterVoid && object instanceof PsiMethod && PsiType.VOID.equals(((PsiMethod)object).getReturnType())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.addElement(element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,6 @@ public class Foo {
|
||||
});
|
||||
}
|
||||
|
||||
boolean fefefef() {}
|
||||
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class Foo {
|
||||
Object foo(){
|
||||
return noti<caret>
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class Foo {
|
||||
Object foo(){
|
||||
return notify<caret>
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
boolean zoo(String s) {
|
||||
return f<caret>
|
||||
return f<caret>x
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -46,7 +46,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
}
|
||||
|
||||
public void testReturnF() throws Throwable {
|
||||
checkPreferredItems(0, "false", "finalize");
|
||||
checkPreferredItems(0, "false");
|
||||
}
|
||||
|
||||
public void testPreferDefaultTypeToExpected() throws Throwable {
|
||||
@@ -84,7 +84,10 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
}
|
||||
|
||||
public void testClassStaticMembersInBooleanContext() throws Throwable {
|
||||
checkPreferredItems(0, "booleanMethod", "voidMethod", "BOOLEAN", "AN_OBJECT", "class");
|
||||
final String path = getTestName(false) + ".java";
|
||||
myFixture.configureByFile(path);
|
||||
myFixture.complete(CompletionType.BASIC, 2);
|
||||
assertPreferredItems(0, "booleanMethod", "voidMethod", "registerNatives", "BOOLEAN", "AN_OBJECT");
|
||||
}
|
||||
|
||||
public void testDispreferDeclared() throws Throwable {
|
||||
|
||||
+13
-5
@@ -5,6 +5,7 @@ import com.intellij.JavaTestUtil
|
||||
import com.intellij.codeInsight.CodeInsightSettings
|
||||
import com.intellij.codeInsight.lookup.Lookup
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
import com.intellij.codeInsight.lookup.LookupManager
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes
|
||||
@@ -14,7 +15,6 @@ import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
|
||||
public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
@Override
|
||||
@@ -677,7 +677,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
|
||||
public void testDoubleFalse() throws Throwable {
|
||||
configureByFile(getTestName(false) + ".java");
|
||||
assertStringItems("false", "finalize");
|
||||
assertStringItems("false", "fefefef");
|
||||
}
|
||||
|
||||
public void testSameNamedVariableInNestedClasses() throws Throwable {
|
||||
@@ -822,6 +822,16 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
|
||||
public void testMethodParameterAnnotationClass() throws Throwable { doTest(); }
|
||||
|
||||
public void testVoidMethodsInNonVoidContext() throws Throwable {
|
||||
configure()
|
||||
checkResultByFile(getTestName(false) + ".java")
|
||||
assertEmpty(myItems)
|
||||
assertNull(getLookup());
|
||||
|
||||
myFixture.complete(CompletionType.BASIC, 2)
|
||||
checkResult()
|
||||
}
|
||||
|
||||
public void testEnumConstantFromEnumMember() throws Throwable { doTest(); }
|
||||
|
||||
public void testPrimitiveMethodParameter() throws Throwable { doTest(); }
|
||||
@@ -892,9 +902,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testClassNameInsideIdentifierInIf() throws Throwable {
|
||||
configure()
|
||||
type '\n'
|
||||
checkResult()
|
||||
doTest '\n'
|
||||
}
|
||||
|
||||
public void testSuggestMembersOfStaticallyImportedClasses() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user