prefer the expected type even if it's inner

This commit is contained in:
peter
2011-01-26 18:52:55 +01:00
parent 87ed739bd5
commit 009015d5e5
3 changed files with 22 additions and 5 deletions
@@ -20,7 +20,6 @@ import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author peter
@@ -34,11 +33,12 @@ public class PreferExpectedTypeWeigher extends CompletionWeigher {
}
public MyResult weigh(@NotNull final LookupElement item, @NotNull final CompletionLocation location) {
if (location == null) {
return null;
}
if (location.getCompletionType() != CompletionType.BASIC) return MyResult.normal;
if (item.getObject() instanceof PsiClass) return MyResult.normal;
if (item.getObject() instanceof PsiClass) {
if (!JavaSmartCompletionContributor.AFTER_NEW.accepts(location.getCompletionParameters().getPosition())) {
return MyResult.normal;
}
}
ExpectedTypeInfo[] expectedInfos = JavaCompletionUtil.EXPECTED_TYPES.getValue(location);
if (expectedInfos == null) return MyResult.normal;
@@ -0,0 +1,9 @@
class Foooo {
interface Bar {}
}
class Bar {
{
Foooo.Bar c = new Fooo<caret>x
}
}
@@ -152,4 +152,12 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "final", "finalize");
}
public void testPreferNewExpectedInner() throws Throwable {
checkPreferredItems(0, "Foooo.Bar", "Foooo");
/*final LookupElementPresentation presentation = new LookupElementPresentation();
getLookup().getItems().get(0).renderElement(presentation);
assertEquals("Foooo.Bar", presentation.getItemText());*/
}
}