mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
don't always prefer common methods like Object#equals once they ever were chosen
choosing another method from a subclass now also affects all superclass methods statistics
This commit is contained in:
+15
-8
@@ -21,6 +21,10 @@ import com.intellij.codeInsight.lookup.LookupItem;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.statistics.JavaStatisticsManager;
|
||||
import com.intellij.psi.statistics.StatisticsInfo;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -48,18 +52,21 @@ public class JavaCompletionStatistician extends CompletionStatistician{
|
||||
return new StatisticsInfo(JavaStatisticsManager.getAfterNewKey(expectedType), key2);
|
||||
}
|
||||
|
||||
if (o instanceof PsiMethod) {
|
||||
o = RecursionWeigher.findDeepestSuper((PsiMethod)o);
|
||||
}
|
||||
|
||||
PsiClass containingClass = ((PsiMember)o).getContainingClass();
|
||||
if (containingClass != null) {
|
||||
if (o instanceof PsiMethod && "getClass".equals(((PsiMethod) o).getName()) &&
|
||||
CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) {
|
||||
return StatisticsInfo.EMPTY;
|
||||
String context = JavaStatisticsManager.getMemberUseKey2(containingClass);
|
||||
|
||||
if (o instanceof PsiMethod) {
|
||||
String memberValue = JavaStatisticsManager.getMemberUseKey2(RecursionWeigher.findDeepestSuper((PsiMethod)o));
|
||||
|
||||
List<StatisticsInfo> superMethodInfos = ContainerUtil.newArrayList(new StatisticsInfo(context, memberValue));
|
||||
for (PsiClass superClass : InheritanceUtil.getSuperClasses(containingClass)) {
|
||||
superMethodInfos.add(new StatisticsInfo(JavaStatisticsManager.getMemberUseKey2(superClass), memberValue));
|
||||
}
|
||||
return StatisticsInfo.createComposite(superMethodInfos);
|
||||
}
|
||||
|
||||
return new StatisticsInfo(JavaStatisticsManager.getMemberUseKey2(containingClass), key2);
|
||||
return new StatisticsInfo(context, key2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class Foo1 { boolean method1() {} }
|
||||
class Foo2 { boolean method2() {} }
|
||||
class Foo3 { boolean method3() {} }
|
||||
|
||||
public class MyFirstTestClassFoo {
|
||||
|
||||
void foo(Foo1 f1, Foo2 f2, Foo3 f3) {
|
||||
f1.<caret>
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -181,6 +181,27 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
assertPreferredItems(0, "getComponents", "getComponent");
|
||||
}
|
||||
|
||||
public void testAbandonSameStatsForDifferentQualifiers() throws Throwable {
|
||||
invokeCompletion(getTestName(false) + ".java");
|
||||
assertPreferredItems 0, "method1", "equals"
|
||||
myFixture.type('eq\n2);\nf2.')
|
||||
|
||||
myFixture.completeBasic();
|
||||
assertPreferredItems 0, "equals", "method2"
|
||||
myFixture.type('me\n);\n')
|
||||
|
||||
for (i in 0..StatisticsManager.OBLIVION_THRESHOLD) {
|
||||
myFixture.type('f2.')
|
||||
myFixture.completeBasic()
|
||||
assertPreferredItems 0, "method2", "equals"
|
||||
myFixture.type('me\n);\n')
|
||||
}
|
||||
|
||||
myFixture.type('f3.')
|
||||
myFixture.completeBasic()
|
||||
assertPreferredItems 0, "method3", "equals"
|
||||
}
|
||||
|
||||
public void testDispreferFinalize() throws Throwable {
|
||||
checkPreferredItems(0, "final", "finalize");
|
||||
}
|
||||
@@ -394,6 +415,8 @@ import java.lang.annotation.Target;
|
||||
public void testDoNotPreferGetClass() {
|
||||
checkPreferredItems 0, 'get', 'getClass'
|
||||
incUseCount(lookup, 1)
|
||||
assertPreferredItems 0, 'getClass', 'get'
|
||||
incUseCount(lookup, 1)
|
||||
assertPreferredItems 0, 'get', 'getClass'
|
||||
}
|
||||
|
||||
|
||||
@@ -191,14 +191,16 @@ public class StatisticsWeigher extends CompletionWeigher {
|
||||
}
|
||||
|
||||
public static StatisticsInfo composeStatsWithPrefix(StatisticsInfo info, final String fullPrefix, boolean forWriting) {
|
||||
ArrayList<StatisticsInfo> infos = new ArrayList<StatisticsInfo>(fullPrefix.length() + 3);
|
||||
if (forWriting) {
|
||||
infos.add(info);
|
||||
ArrayList<StatisticsInfo> infos = new ArrayList<StatisticsInfo>((fullPrefix.length() + 3) * info.getConjuncts().size());
|
||||
for (StatisticsInfo conjunct : info.getConjuncts()) {
|
||||
if (forWriting) {
|
||||
infos.add(conjunct);
|
||||
}
|
||||
for (int i = 0; i <= fullPrefix.length(); i++) {
|
||||
infos.add(composeWithPrefix(conjunct, fullPrefix.substring(0, i), forWriting));
|
||||
}
|
||||
infos.add(composeWithPrefix(conjunct, fullPrefix, !forWriting));
|
||||
}
|
||||
for (int i = 0; i <= fullPrefix.length(); i++) {
|
||||
infos.add(composeWithPrefix(info, fullPrefix.substring(0, i), forWriting));
|
||||
}
|
||||
infos.add(composeWithPrefix(info, fullPrefix, !forWriting));
|
||||
return StatisticsInfo.createComposite(infos);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user