mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-87104 Code completion should remember and prefer chosen variants
This commit is contained in:
+5
-19
@@ -52,28 +52,14 @@ public class JavaCompletionStatistician extends CompletionStatistician{
|
||||
if (item == null) return null;
|
||||
|
||||
PsiType qualifierType = JavaCompletionUtil.getQualifierType(item);
|
||||
if (qualifierType == null) {
|
||||
if (infos != null && infos.length > 0) {
|
||||
qualifierType = infos[0].getDefaultType();
|
||||
}
|
||||
}
|
||||
|
||||
final CompletionType type = location.getCompletionType();
|
||||
if (o instanceof PsiMember) {
|
||||
final boolean isClass = o instanceof PsiClass;
|
||||
if (qualifierType != null) {
|
||||
String context;
|
||||
if (isClass) {
|
||||
context = JavaStatisticsManager.getAfterNewKey(qualifierType);
|
||||
} else {
|
||||
context = JavaStatisticsManager.getMemberUseKey1(qualifierType);
|
||||
}
|
||||
return new StatisticsInfo(context, JavaStatisticsManager.getMemberUseKey2((PsiMember)o));
|
||||
}
|
||||
|
||||
if (isClass) {
|
||||
return JavaStatisticsManager.createInfo(qualifierType, (PsiMember)o);
|
||||
String key2 = JavaStatisticsManager.getMemberUseKey2((PsiMember)o);
|
||||
if (o instanceof PsiClass) {
|
||||
PsiType expectedType = infos != null && infos.length > 0 ? infos[0].getDefaultType() : null;
|
||||
return new StatisticsInfo(JavaStatisticsManager.getAfterNewKey(expectedType), key2);
|
||||
}
|
||||
return new StatisticsInfo(JavaStatisticsManager.getMemberUseKey2(((PsiMember)o).getContainingClass()), key2);
|
||||
}
|
||||
|
||||
if (qualifierType != null) return StatisticsInfo.EMPTY;
|
||||
|
||||
@@ -1186,11 +1186,11 @@ public class TypeConversionUtil {
|
||||
return PsiType.getJavaLangObject(typeParameter.getManager(), typeParameter.getResolveScope());
|
||||
}
|
||||
|
||||
public static PsiType erasure(PsiType type) {
|
||||
public static PsiType erasure(@Nullable PsiType type) {
|
||||
return erasure(type, PsiSubstitutor.EMPTY);
|
||||
}
|
||||
|
||||
public static PsiType erasure(final PsiType type, final PsiSubstitutor beforeSubstitutor) {
|
||||
public static PsiType erasure(@Nullable final PsiType type, final PsiSubstitutor beforeSubstitutor) {
|
||||
if (type == null) return null;
|
||||
return type.accept(new PsiTypeVisitor<PsiType>() {
|
||||
@Override
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import javax.swing.*;
|
||||
|
||||
public class MyFirstTestClassFoo {
|
||||
|
||||
void foo(JComponent c) {
|
||||
c.getCom<caret>x
|
||||
}
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import javax.swing.*;
|
||||
|
||||
public class MyFirstTestClassFoo {
|
||||
|
||||
void foo(JLabel l) {
|
||||
l.getCompo<caret>x
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -13,6 +13,7 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl
|
||||
import com.intellij.ide.ui.UISettings
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
|
||||
public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
private static final String BASE_PATH = "/codeInsight/completion/normalSorting";
|
||||
@@ -148,6 +149,32 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
assertPreferredItems(0, "FooBee", "FooBar");
|
||||
}
|
||||
|
||||
public void testSameStatsForDifferentQualifiers() throws Throwable {
|
||||
invokeCompletion("SameStatsForDifferentQualifiersJLabel.java");
|
||||
assertPreferredItems(0, "getComponent");
|
||||
incUseCount(getLookup(), myFixture.lookupElementStrings.indexOf('getComponents'));
|
||||
FileDocumentManager.instance.saveAllDocuments()
|
||||
|
||||
invokeCompletion("SameStatsForDifferentQualifiersJLabel.java");
|
||||
assertPreferredItems(1, "getComponent", "getComponents");
|
||||
|
||||
invokeCompletion("SameStatsForDifferentQualifiersJComponent.java");
|
||||
assertPreferredItems(1, "getComponent", "getComponents");
|
||||
}
|
||||
|
||||
public void testSameStatsForDifferentQualifiers2() throws Throwable {
|
||||
invokeCompletion("SameStatsForDifferentQualifiersJComponent.java");
|
||||
assertPreferredItems(0, "getComponent");
|
||||
incUseCount(getLookup(), myFixture.lookupElementStrings.indexOf('getComponents'));
|
||||
FileDocumentManager.instance.saveAllDocuments()
|
||||
|
||||
invokeCompletion("SameStatsForDifferentQualifiersJComponent.java");
|
||||
assertPreferredItems(1, "getComponent", "getComponents");
|
||||
|
||||
invokeCompletion("SameStatsForDifferentQualifiersJLabel.java");
|
||||
assertPreferredItems(1, "getComponent", "getComponents");
|
||||
}
|
||||
|
||||
public void testDispreferFinalize() throws Throwable {
|
||||
checkPreferredItems(0, "final", "finalize");
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public abstract class JavaStatisticsManager {
|
||||
}
|
||||
|
||||
@NonNls @NotNull
|
||||
public static String getMemberUseKey1(PsiType qualifierType) {
|
||||
public static String getMemberUseKey1(@Nullable PsiType qualifierType) {
|
||||
qualifierType = TypeConversionUtil.erasure(qualifierType);
|
||||
return "member#" + (qualifierType == null ? "" : qualifierType.getCanonicalText());
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public abstract class JavaStatisticsManager {
|
||||
return ArrayUtil.toStringArray(list);
|
||||
}
|
||||
|
||||
public static String getAfterNewKey(PsiType expectedType) {
|
||||
public static String getAfterNewKey(@Nullable PsiType expectedType) {
|
||||
return getMemberUseKey1(expectedType) + "###smartAfterNew";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user