mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
let class name completion statistics not depend on the expected type
once ContainerUtil is selected in one context, prefer it in others
This commit is contained in:
+6
-1
@@ -53,8 +53,13 @@ public class JavaCompletionStatistician extends CompletionStatistician{
|
||||
final ExpectedTypeInfo firstInfo = infos != null && infos.length > 0 ? infos[0] : null;
|
||||
String key2 = JavaStatisticsManager.getMemberUseKey2((PsiMember)o);
|
||||
if (o instanceof PsiClass) {
|
||||
if (PreferByKindWeigher.isInMethodTypeArg(position)) {
|
||||
return StatisticsInfo.EMPTY;
|
||||
}
|
||||
|
||||
PsiType expectedType = firstInfo != null ? firstInfo.getDefaultType() : null;
|
||||
return new StatisticsInfo(JavaStatisticsManager.getAfterNewKey(expectedType), key2);
|
||||
String context = JavaClassNameCompletionContributor.AFTER_NEW.accepts(position) ? JavaStatisticsManager.getAfterNewKey(expectedType) : "";
|
||||
return new StatisticsInfo(context, key2);
|
||||
}
|
||||
|
||||
PsiClass containingClass = ((PsiMember)o).getContainingClass();
|
||||
|
||||
@@ -269,12 +269,15 @@ public class PreferByKindWeigher extends LookupElementWeigher {
|
||||
}
|
||||
if (JavaKeywordCompletion.PRIMITIVE_TYPES.contains(keyword) || PsiKeyword.VOID.equals(keyword)) {
|
||||
boolean inCallArg = psiElement().withParents(PsiReferenceExpression.class, PsiExpressionList.class).accepts(myPosition);
|
||||
boolean inTypeArg = psiElement().inside(PsiReferenceParameterList.class).accepts(myPosition);
|
||||
return inCallArg || inTypeArg ? ThreeState.NO : ThreeState.UNSURE;
|
||||
return inCallArg || isInMethodTypeArg(myPosition) ? ThreeState.NO : ThreeState.UNSURE;
|
||||
}
|
||||
return ThreeState.UNSURE;
|
||||
}
|
||||
|
||||
static boolean isInMethodTypeArg(PsiElement position) {
|
||||
return psiElement().inside(PsiReferenceParameterList.class).accepts(position);
|
||||
}
|
||||
|
||||
private static boolean isOnTopLevelInVoidMethod(PsiStatement statement) {
|
||||
if (!(statement.getParent() instanceof PsiCodeBlock)) return false;
|
||||
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
public class Usage {
|
||||
{
|
||||
int a = ConUt<caret>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ConflictsUtil { static int foo() {} }
|
||||
class ContainerUtil { static int foo() {} }
|
||||
+9
@@ -758,4 +758,13 @@ class ContainerUtil extends ContainerUtilRt {
|
||||
assert LookupElementPresentation.renderElement(myFixture.lookupElements[0]).tailText.contains('java.lang')
|
||||
}
|
||||
|
||||
void testClassNameStatisticsDoesntDependOnExpectedType() {
|
||||
checkPreferredItems 0, 'ConflictsUtil', 'ContainerUtil'
|
||||
myFixture.lookup.currentItem = myFixture.lookupElements[1]
|
||||
myFixture.type('\n.foo();\nlong l = ConUt')
|
||||
myFixture.completeBasic()
|
||||
|
||||
assertPreferredItems 0, 'ContainerUtil', 'ConflictsUtil'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user