diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java index 79fe32f1e62b..ed3c07767a2d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java @@ -7,6 +7,7 @@ import com.intellij.codeInsight.generation.PsiMethodMember; import com.intellij.codeInsight.lookup.Lookup; import com.intellij.codeInsight.lookup.LookupElementDecorator; import com.intellij.codeInsight.lookup.LookupItem; +import com.intellij.codeInsight.lookup.PsiTypeLookupItem; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.ide.util.MemberChooser; import com.intellij.openapi.application.ApplicationManager; @@ -16,6 +17,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.impl.source.PostprocessReformattingAspect; @@ -63,38 +65,67 @@ class ConstructorInsertHandler implements InsertHandler 0) { + TextRange range = paramList.getTextRange(); + context.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), "<>"); + editor.getCaretModel().moveToOffset(range.getStartOffset() + 1); + } + return; + } + } } } - if (mySmart) { - FeatureUsageTracker.getInstance().triggerFeatureUsed(JavaCompletionFeatures.AFTER_NEW); + } + + context.setLaterRunnable(generateAnonymousBody(editor, context.getFile())); + } + else { + final PsiNewExpression newExpression = + PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiNewExpression.class, false); + if (newExpression != null) { + final PsiJavaCodeReferenceElement classReference = newExpression.getClassOrAnonymousClassReference(); + if (classReference != null) { + CodeStyleManager.getInstance(context.getProject()).reformat(classReference); } } + if (mySmart) { + FeatureUsageTracker.getInstance().triggerFeatureUsed(JavaCompletionFeatures.AFTER_NEW); + } } } diff --git a/java/java-tests/testData/codeInsight/completion/smartType/UnboundTypeArgs-out.java b/java/java-tests/testData/codeInsight/completion/smartType/UnboundTypeArgs-out.java new file mode 100644 index 000000000000..e0f7ba5fcded --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/UnboundTypeArgs-out.java @@ -0,0 +1,10 @@ +interface Foo {} +interface FooEx extends Foo { + T foo(); +} + +class Bar { + { + Foo f = new FooEx<>() {}; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/smartType/UnboundTypeArgs.java b/java/java-tests/testData/codeInsight/completion/smartType/UnboundTypeArgs.java new file mode 100644 index 000000000000..aa2333d3906c --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/UnboundTypeArgs.java @@ -0,0 +1,10 @@ +interface Foo {} +interface FooEx extends Foo { + T foo(); +} + +class Bar { + { + Foo f = new FE + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index b32fd98fe38c..8f90525530a4 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -861,6 +861,8 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { doTest(); } + public void testUnboundTypeArgs() throws Exception { doTest(); } + public void testIDEADEV2668() throws Exception { doTest(); }