diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/PreferExpectedTypeWeigher.java b/java/java-impl/src/com/intellij/codeInsight/completion/PreferExpectedTypeWeigher.java index cb0ecbb0c436..1e9afded1304 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/PreferExpectedTypeWeigher.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/PreferExpectedTypeWeigher.java @@ -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; diff --git a/java/java-tests/testData/codeInsight/completion/normalSorting/PreferNewExpectedInner.java b/java/java-tests/testData/codeInsight/completion/normalSorting/PreferNewExpectedInner.java new file mode 100644 index 000000000000..bd9d0463e622 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/normalSorting/PreferNewExpectedInner.java @@ -0,0 +1,9 @@ +class Foooo { + interface Bar {} +} + +class Bar { + { + Foooo.Bar c = new Fooox + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java index 78e138459167..243ec1c0f180 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.java @@ -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());*/ + } + } \ No newline at end of file