mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
suggest inheritor members on second completion only, prefer the default collection getters to them
This commit is contained in:
+4
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.lookup.AutoCompletionPolicy;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.Consumer;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -28,6 +29,8 @@ import static com.intellij.psi.CommonClassNames.*;
|
||||
* @author peter
|
||||
*/
|
||||
class CollectionsUtilityMethodsProvider {
|
||||
public static final Key<Boolean> COLLECTION_FACTORY = Key.create("CollectionFactory");
|
||||
|
||||
public static void addCompletions(@NotNull final JavaSmartCompletionParameters parameters,
|
||||
@NotNull final Consumer<LookupElement> result) {
|
||||
final PsiElement element = parameters.getPosition();
|
||||
@@ -85,6 +88,7 @@ class CollectionsUtilityMethodsProvider {
|
||||
final JavaMethodCallElement item = new JavaMethodCallElement(method, false, false);
|
||||
item.setAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
|
||||
item.setInferenceSubstitutor(SmartCompletionDecorator.calculateMethodReturnTypeSubstitutor(method, expectedType));
|
||||
item.putUserData(COLLECTION_FACTORY, true);
|
||||
result.consume(item);
|
||||
}
|
||||
|
||||
|
||||
@@ -542,7 +542,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
!(position.getParent() instanceof PsiLiteralExpression) &&
|
||||
!(position.getParent().getParent() instanceof PsiSwitchLabelStatement)) {
|
||||
for (final ExpectedTypeInfo info : JavaSmartCompletionContributor.getExpectedTypes(parameters)) {
|
||||
new JavaMembersGetter(info.getDefaultType()).addMembers(position, parameters.getInvocationCount() > 0, new Consumer<LookupElement>() {
|
||||
new JavaMembersGetter(info.getDefaultType()).addMembers(position, parameters.getInvocationCount() > 1, new Consumer<LookupElement>() {
|
||||
@Override
|
||||
public void consume(LookupElement element) {
|
||||
result.addElement(element);
|
||||
|
||||
+3
-2
@@ -223,9 +223,10 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
parent != null &&
|
||||
!(parent.getParent() instanceof PsiSwitchLabelStatement)) {
|
||||
for (ExpectedTypeInfo info : mergedInfos) {
|
||||
new JavaMembersGetter(info.getType()).addMembers(position, true, noTypeCheck);
|
||||
final boolean searchInheritors = params.getInvocationCount() > 1;
|
||||
new JavaMembersGetter(info.getType()).addMembers(position, searchInheritors, noTypeCheck);
|
||||
if (!info.getDefaultType().equals(info.getType())) {
|
||||
new JavaMembersGetter(info.getDefaultType()).addMembers(position, true, noTypeCheck);
|
||||
new JavaMembersGetter(info.getDefaultType()).addMembers(position, searchInheritors, noTypeCheck);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -44,6 +44,7 @@ public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends LookupEle
|
||||
qualifiedWithField,
|
||||
qualifiedWithGetter,
|
||||
superMethodParameters,
|
||||
collectionFactory,
|
||||
normal,
|
||||
nonInitialized,
|
||||
classLiteral,
|
||||
@@ -70,6 +71,10 @@ public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends LookupEle
|
||||
if (object instanceof String && item.getUserData(JavaCompletionUtil.SUPER_METHOD_PARAMETERS) == Boolean.TRUE) {
|
||||
return MyResult.superMethodParameters;
|
||||
}
|
||||
|
||||
if (item.getUserData(CollectionsUtilityMethodsProvider.COLLECTION_FACTORY) != null) {
|
||||
return MyResult.collectionFactory;
|
||||
}
|
||||
|
||||
final JavaChainLookupElement chain = item.as(JavaChainLookupElement.CLASS_CONDITION_KEY);
|
||||
if (chain != null) {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
public class Aaaaaaa {
|
||||
|
||||
{
|
||||
java.util.List<String> local = null;
|
||||
java.util.List<String> l = <caret>
|
||||
}
|
||||
|
||||
}
|
||||
+22
-6
@@ -48,7 +48,7 @@ public class SecondSmartTypeCompletionTest extends LightCompletionTestCase {
|
||||
configure();
|
||||
assertStringItems("foos().toArray(EMPTY_ARRAY)", "foos().toArray(EMPTY_ARRAY2)");
|
||||
selectItem(myItems[0]);
|
||||
checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
|
||||
checkResult();
|
||||
}
|
||||
|
||||
public void testToArrayGenericArrayCreation() throws Throwable { doTest(); }
|
||||
@@ -62,7 +62,7 @@ public class SecondSmartTypeCompletionTest extends LightCompletionTestCase {
|
||||
configure();
|
||||
assertStringItems("foos().toArray(Bar.EMPTY_ARRAY)", "foos().toArray(Bar.EMPTY_ARRAY2)");
|
||||
selectItem(myItems[0]);
|
||||
checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
|
||||
checkResult();
|
||||
}
|
||||
|
||||
public void testNonInitializedField() throws Throwable { doTest(); }
|
||||
@@ -104,14 +104,14 @@ public class SecondSmartTypeCompletionTest extends LightCompletionTestCase {
|
||||
assertEquals("Arrays.asList(f.bar())", ((LookupItem)((LookupElementDecorator)myItems[0]).getDelegate()).getPresentableText());
|
||||
assertEquals("Arrays.asList(f.foo())", ((LookupItem)((LookupElementDecorator)myItems[1]).getDelegate()).getPresentableText());
|
||||
selectItem(myItems[1]);
|
||||
checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
|
||||
checkResult();
|
||||
}
|
||||
|
||||
public void testRestoreInitialPrefix() throws Throwable {
|
||||
configureByFileNoComplete(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
complete(1);
|
||||
assertStringItems("MyEnum.Bar", "MyEnum.Foo");
|
||||
checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
|
||||
checkResult();
|
||||
complete(1);
|
||||
assertStringItems("my.getEnum", "MyEnum.Bar", "MyEnum.Foo");
|
||||
}
|
||||
@@ -155,13 +155,17 @@ public class SecondSmartTypeCompletionTest extends LightCompletionTestCase {
|
||||
public void testEmptyListInMethodCall() throws Throwable {
|
||||
configure();
|
||||
selectItem(myItems[0]);
|
||||
checkResult();
|
||||
}
|
||||
|
||||
private void checkResult() {
|
||||
checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
|
||||
}
|
||||
|
||||
public void testSingletonMap() throws Throwable {
|
||||
configure();
|
||||
selectItem(myItems[0]);
|
||||
checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
|
||||
checkResult();
|
||||
}
|
||||
|
||||
protected void checkResultByFile(@NonNls final String filePath) {
|
||||
@@ -174,7 +178,19 @@ public class SecondSmartTypeCompletionTest extends LightCompletionTestCase {
|
||||
|
||||
private void doTest() throws Exception {
|
||||
configure();
|
||||
checkResultByFile(BASE_PATH + "/" + getTestName(false) + "-out.java");
|
||||
checkResult();
|
||||
}
|
||||
|
||||
public void testInheritorMembers() throws Throwable {
|
||||
configure();
|
||||
selectItem(myItems[0]);
|
||||
checkResult();
|
||||
}
|
||||
|
||||
public void testInheritorEnumMembers() throws Throwable {
|
||||
configure();
|
||||
selectItem(myItems[0]);
|
||||
checkResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+8
-1
@@ -287,7 +287,14 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
checkPreferredItems(0, "boo", "bar")
|
||||
}
|
||||
|
||||
|
||||
public void testPreferCollectionsEmptyList() throws Throwable {
|
||||
myFixture.addClass("package foo; public class FList<T> implements java.util.List<T> { public static <T> FList<T> emptyList() {} }");
|
||||
configureNoCompletion(getTestName(false) + ".java");
|
||||
myFixture.complete(CompletionType.SMART, 2);
|
||||
assertPreferredItems(0, "local", "local.subList", "emptyList", "singletonList", "unmodifiableList");
|
||||
assert 'Collections.emptyList' in lookup.items[2].allLookupStrings
|
||||
assert 'FList.emptyList' in lookup.items[5].allLookupStrings
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
|
||||
-2
@@ -1026,8 +1026,6 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testArrayInitializerBeforeVarargs() throws Throwable { doTest(); }
|
||||
public void testInheritorMembers() throws Throwable { doTest(); }
|
||||
public void testInheritorEnumMembers() throws Throwable { doTest(); }
|
||||
public void testDuplicateMembersFromSuperClass() throws Throwable { doTest(); }
|
||||
|
||||
public void testMemberImportStatically() {
|
||||
|
||||
@@ -29,12 +29,12 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class LookupItem<T> extends MutableLookupElement<T> implements Comparable
|
||||
private double myPriority;
|
||||
private Map<Object,Object> myAttributes = null;
|
||||
public static final LookupItem[] EMPTY_ARRAY = new LookupItem[0];
|
||||
private final Set<String> myAllLookupStrings = new THashSet<String>();
|
||||
private final Set<String> myAllLookupStrings = new HashSet<String>();
|
||||
private String myPresentable;
|
||||
private AutoCompletionPolicy myAutoCompletionPolicy = AutoCompletionPolicy.SETTINGS_DEPENDENT;
|
||||
|
||||
|
||||
+1
-1
@@ -218,7 +218,7 @@ public class GroovySmartCompletionContributor extends CompletionContributor {
|
||||
};
|
||||
PsiType type = info.getType();
|
||||
PsiType defType = info.getDefaultType();
|
||||
boolean searchInheritors = params.getInvocationCount() > 0;
|
||||
boolean searchInheritors = params.getInvocationCount() > 1;
|
||||
if (type instanceof PsiClassType) {
|
||||
new GroovyMembersGetter((PsiClassType)type, reference).processMembers(searchInheritors, consumer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user