From 1831c5332007636ab6341c86c1d217bb0ea774f3 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 19 Oct 2016 19:23:08 +0200 Subject: [PATCH] constructor completion: implement anonymous methods after arg live template (IDEA-CR-14717) --- .../completion/ConstructorInsertHandler.java | 31 ++++++++++++++++--- .../AnonymousNonDefaultConstructor.java | 2 ++ .../AnonymousNonDefaultConstructor_after.java | 2 ++ ...usNonDefaultConstructor_afterTemplate.java | 15 +++++++++ .../completion/SignatureCompletionTest.groovy | 9 ++++-- 5 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/signature/AnonymousNonDefaultConstructor_afterTemplate.java 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 2922cb2343ca..03369610d3c3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java @@ -12,6 +12,8 @@ import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupElementDecorator; import com.intellij.codeInsight.lookup.PsiTypeLookupItem; import com.intellij.codeInsight.template.*; +import com.intellij.codeInsight.template.impl.TemplateManagerImpl; +import com.intellij.codeInsight.template.impl.TemplateState; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; @@ -124,7 +126,7 @@ public class ConstructorInsertHandler implements InsertHandler } diff --git a/java/java-tests/testData/codeInsight/completion/signature/AnonymousNonDefaultConstructor_after.java b/java/java-tests/testData/codeInsight/completion/signature/AnonymousNonDefaultConstructor_after.java index 49dde1b89a5a..407a6ac4f477 100644 --- a/java/java-tests/testData/codeInsight/completion/signature/AnonymousNonDefaultConstructor_after.java +++ b/java/java-tests/testData/codeInsight/completion/signature/AnonymousNonDefaultConstructor_after.java @@ -2,6 +2,8 @@ abstract class Foo{ public Foo(int x) { } + abstract int foo(); + { Foo f = new Foo(x) {} } diff --git a/java/java-tests/testData/codeInsight/completion/signature/AnonymousNonDefaultConstructor_afterTemplate.java b/java/java-tests/testData/codeInsight/completion/signature/AnonymousNonDefaultConstructor_afterTemplate.java new file mode 100644 index 000000000000..ab5730c151b3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/signature/AnonymousNonDefaultConstructor_afterTemplate.java @@ -0,0 +1,15 @@ +abstract class Foo{ + public Foo(int x) { + } + + abstract int foo(); + + { + Foo f = new Foo(x) { + @Override + int foo() { + return 0; + } + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SignatureCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SignatureCompletionTest.groovy index b7b2fcb6dcf3..bed15ad0b482 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SignatureCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SignatureCompletionTest.groovy @@ -19,7 +19,6 @@ import com.intellij.JavaTestUtil import com.intellij.codeInsight.template.impl.TemplateManagerImpl import com.intellij.openapi.util.registry.Registry import com.intellij.psi.PsiMethod - /** * @author peter */ @@ -59,7 +58,13 @@ class SignatureCompletionTest extends LightFixtureCompletionTestCase { void testNonDefaultConstructor() { doFirstItemTest() } - void testAnonymousNonDefaultConstructor() { doFirstItemTest() } + void testAnonymousNonDefaultConstructor() { + configureByTestName() + myFixture.type('\n') + checkResult() + myFixture.type('\n') + checkResultByFile(getTestName(false) + "_afterTemplate.java") + } void testSeveralConstructors() { myFixture.configureByFile(getTestName(false) + ".java")