IDEA-89056 Strange 'xxx[]' item is shown in smart completion list

This commit is contained in:
peter
2012-07-19 16:11:04 +02:00
parent 457de6f2b1
commit 549da5f6df
5 changed files with 27 additions and 13 deletions
@@ -924,7 +924,7 @@ public class ExpectedTypesProvider {
}
}
final PsiExpression[] args = argumentList.getExpressions();
final PsiExpression[] args = argumentList.getExpressions().clone();
final int index = ArrayUtil.indexOf(args, argument);
LOG.assertTrue(index >= 0);
@@ -932,6 +932,9 @@ public class ExpectedTypesProvider {
if (index <= args.length - 1) {
leftArgs = new PsiExpression[index];
System.arraycopy(args, 0, leftArgs, 0, index);
if (forCompletion) {
args[index] = null;
}
}
else {
leftArgs = null;
@@ -945,7 +948,7 @@ public class ExpectedTypesProvider {
PsiSubstitutor substitutor;
if (candidateInfo instanceof MethodCandidateInfo) {
final MethodCandidateInfo info = (MethodCandidateInfo)candidateInfo;
substitutor = info.inferTypeArguments(policy);
substitutor = info.inferTypeArguments(policy, args);
if (!info.isStaticsScopeCorrect() && method != null && !method.hasModifierProperty(PsiModifier.STATIC)) continue;
}
else {
@@ -158,10 +158,6 @@ public class PsiTypeLookupItem extends LookupItem {
PsiTypeLookupItem item = doCreateItem(type, context, dim);
if (dim > 0) {
item.setAttribute(TAIL_TEXT_ATTR, " " + StringUtil.repeat("[]", dim));
item.setAttribute(TAIL_TEXT_SMALL_ATTR, "");
}
item.setAttribute(TYPE, original);
return item;
}
@@ -228,10 +224,9 @@ public class PsiTypeLookupItem extends LookupItem {
presentation.setItemText(((PsiType)object).getCanonicalText());
presentation.setItemTextBold(getAttribute(LookupItem.HIGHLIGHTED_ATTR) != null || object instanceof PsiPrimitiveType);
String tailText = (String)getAttribute(LookupItem.TAIL_TEXT_ATTR);
if (tailText != null) {
presentation.setTailText(tailText, getAttribute(LookupItem.TAIL_TEXT_SMALL_ATTR) != null);
}
}
if (myBracketsCount > 0) {
presentation.setTailText(StringUtil.repeat("[]", myBracketsCount) + presentation.getTailText(), true);
}
}
@@ -153,6 +153,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
if (parameters.length > 0) {
for (int j = 0; j < arguments.length; j++) {
PsiExpression argument = arguments[j];
if (argument == null) continue;
if (argument instanceof PsiMethodCallExpression && ourGuard.currentStack().contains(argument)) continue;
final PsiParameter parameter = parameters[Math.min(j, parameters.length - 1)];
@@ -0,0 +1,9 @@
import java.util.List;
class A {
public static <T> List<T> asList(T... a) { }
List<String> m() {
return asList(new <caret>);
}
}
@@ -6,7 +6,6 @@ import com.intellij.codeInsight.completion.impl.CamelHumpMatcher;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementPresentation;
import com.intellij.codeInsight.lookup.PsiTypeLookupItem;
import com.intellij.codeInsight.template.SmartCompletionContextType;
import com.intellij.codeInsight.template.Template;
import com.intellij.codeInsight.template.TemplateContextType;
@@ -602,8 +601,15 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testNewVararg() throws Throwable {
configureByTestName();
assertStringItems("Foo", "Foo");
assertEquals(0, myItems[0].as(PsiTypeLookupItem.class).getBracketsCount());
assertEquals(1, myItems[1].as(PsiTypeLookupItem.class).getBracketsCount());
assertEquals("{...} (default package)", LookupElementPresentation.renderElement(myItems[0]).getTailText());
assertEquals("[] (default package)", LookupElementPresentation.renderElement(myItems[1]).getTailText());
}
public void testNewVararg2() throws Throwable {
configureByTestName();
assertStringItems("String", "String");
assertEquals(" (java.lang)", LookupElementPresentation.renderElement(myItems[0]).getTailText());
assertEquals("[] (java.lang)", LookupElementPresentation.renderElement(myItems[1]).getTailText());
}
public void testInsideStringLiteral() throws Throwable { doAntiTest(); }