mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
local variables should be preferred over factory methods no matter the name end matching degree
This commit is contained in:
@@ -62,7 +62,6 @@ public class JavaCompletionSorting {
|
||||
afterPriority.add(new PreferDefaultTypeWeigher(expectedTypes, parameters));
|
||||
}
|
||||
ContainerUtil.addIfNotNull(afterPriority, recursion(parameters, expectedTypes));
|
||||
afterPriority.add(new PreferSimilarlyEnding(expectedTypes));
|
||||
|
||||
List<LookupElementWeigher> afterProximity = new ArrayList<LookupElementWeigher>();
|
||||
afterProximity.add(new PreferContainingSameWords(expectedTypes));
|
||||
@@ -86,10 +85,11 @@ public class JavaCompletionSorting {
|
||||
afterPrefix.add(new PreferExpected(false, expectedTypes));
|
||||
}
|
||||
afterPrefix.add(new PreferByKindWeigher(type, position));
|
||||
afterPrefix.add(new PreferSimilarlyEnding(expectedTypes));
|
||||
Collections.addAll(afterPrefix, new PreferNonGeneric(), new PreferAccessible(position), new PreferSimple(),
|
||||
new PreferEnumConstants(parameters));
|
||||
|
||||
|
||||
|
||||
|
||||
sorter = sorter.weighAfter("priority", afterPriority.toArray(new LookupElementWeigher[afterPriority.size()]));
|
||||
sorter = sorter.weighAfter("prefix", afterPrefix.toArray(new LookupElementWeigher[afterPrefix.size()]));
|
||||
sorter = sorter.weighAfter("proximity", afterProximity.toArray(new LookupElementWeigher[afterProximity.size()]));
|
||||
|
||||
+9
-5
@@ -16,6 +16,7 @@
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.ExpectedTypeInfo;
|
||||
import com.intellij.codeInsight.ExpectedTypeInfoImpl;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupItem;
|
||||
import com.intellij.psi.*;
|
||||
@@ -45,23 +46,26 @@ public class JavaCompletionStatistician extends CompletionStatistician{
|
||||
PsiType qualifierType = JavaCompletionUtil.getQualifierType(item);
|
||||
|
||||
if (o instanceof PsiMember) {
|
||||
final ExpectedTypeInfo[] infos = JavaCompletionUtil.EXPECTED_TYPES.getValue(location);
|
||||
final ExpectedTypeInfo firstInfo = infos != null && infos.length > 0 ? infos[0] : null;
|
||||
String key2 = JavaStatisticsManager.getMemberUseKey2((PsiMember)o);
|
||||
if (o instanceof PsiClass) {
|
||||
final ExpectedTypeInfo[] infos = JavaCompletionUtil.EXPECTED_TYPES.getValue(location);
|
||||
PsiType expectedType = infos != null && infos.length > 0 ? infos[0].getDefaultType() : null;
|
||||
PsiType expectedType = firstInfo != null ? firstInfo.getDefaultType() : null;
|
||||
return new StatisticsInfo(JavaStatisticsManager.getAfterNewKey(expectedType), key2);
|
||||
}
|
||||
|
||||
PsiClass containingClass = ((PsiMember)o).getContainingClass();
|
||||
if (containingClass != null) {
|
||||
String context = JavaStatisticsManager.getMemberUseKey2(containingClass);
|
||||
String expectedName = firstInfo instanceof ExpectedTypeInfoImpl ? ((ExpectedTypeInfoImpl)firstInfo).expectedName.compute() : null;
|
||||
String contextPrefix = expectedName == null ? "" : "expectedName=" + expectedName + "###";
|
||||
String context = contextPrefix + JavaStatisticsManager.getMemberUseKey2(containingClass);
|
||||
|
||||
if (o instanceof PsiMethod) {
|
||||
String memberValue = JavaStatisticsManager.getMemberUseKey2(RecursionWeigher.findDeepestSuper((PsiMethod)o));
|
||||
|
||||
List<StatisticsInfo> superMethodInfos = ContainerUtil.newArrayList(new StatisticsInfo(context, memberValue));
|
||||
List<StatisticsInfo> superMethodInfos = ContainerUtil.newArrayList(new StatisticsInfo(contextPrefix + context, memberValue));
|
||||
for (PsiClass superClass : InheritanceUtil.getSuperClasses(containingClass)) {
|
||||
superMethodInfos.add(new StatisticsInfo(JavaStatisticsManager.getMemberUseKey2(superClass), memberValue));
|
||||
superMethodInfos.add(new StatisticsInfo(contextPrefix + JavaStatisticsManager.getMemberUseKey2(superClass), memberValue));
|
||||
}
|
||||
return StatisticsInfo.createComposite(superMethodInfos);
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ public class AnotherTestClass {
|
||||
test(getnu<caret>);
|
||||
}
|
||||
|
||||
private static void test(int i, int j) {
|
||||
private static void test(int i) {
|
||||
}
|
||||
|
||||
public static NumberProvider getNumProvider() {
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
String myFoo;
|
||||
String myBar;
|
||||
|
||||
String getFoo() {
|
||||
return my<caret>
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
public class Aaaaaaa {
|
||||
void foo(ActionEvent e) {
|
||||
bar(<caret>);
|
||||
}
|
||||
|
||||
void bar(ActionEvent event) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ActionEvent {
|
||||
static ActionEvent createEvent() {
|
||||
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -533,7 +533,7 @@ import java.lang.annotation.Target;
|
||||
invokeCompletion(getTestName(false) + ".java")
|
||||
assertPreferredItems 0, 'getNumber', 'getNumProvider'
|
||||
lookup.currentItem = lookup.items[1]
|
||||
myFixture.type '\n, getn'
|
||||
myFixture.type '\n);\ntest(getnu'
|
||||
myFixture.completeBasic()
|
||||
assertPreferredItems 0, 'getNumProvider', 'getNumber'
|
||||
}
|
||||
|
||||
+6
-3
@@ -21,7 +21,7 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
}
|
||||
|
||||
public void testJComponentAdd() throws Throwable {
|
||||
checkPreferredItems(0, "name", "getName", "b", "fooBean239", "foo", "this");
|
||||
checkPreferredItems(0, "name", "b", "fooBean239", "foo", "this");
|
||||
}
|
||||
|
||||
public void testJComponentAddNew() throws Throwable {
|
||||
@@ -257,11 +257,11 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
assertPreferredItems(0, "bar", "foo", "equals", "false", "true");
|
||||
}
|
||||
|
||||
public void testFieldNameOutweighsStats() throws Throwable {
|
||||
public void testExpectedNameDependentStats() throws Throwable {
|
||||
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".java");
|
||||
assertPreferredItems(0, "myFoo", "myBar");
|
||||
incUseCount(lookup, 1); //myBar
|
||||
assertPreferredItems(0, "myFoo", "myBar");
|
||||
assertPreferredItems(0, "myBar", "myFoo");
|
||||
}
|
||||
|
||||
public void testPreferSameNamedMethods() {
|
||||
@@ -307,6 +307,9 @@ public class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
public void testPreferOtherGetterInSetterCall() {
|
||||
checkPreferredItems 0, 'color', 'getColor', 'getZooColor', 'hashCode'
|
||||
}
|
||||
public void testPreferLocalOverFactoryMatchingName() {
|
||||
checkPreferredItems 0, 'e', 'createEvent'
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
|
||||
Reference in New Issue
Block a user