mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
constructor completion: insert the chosen constructor and position the caret accordingly (IDEA-CR-14717)
This commit is contained in:
+3
-1
@@ -214,9 +214,11 @@ public class ConstructorInsertHandler implements InsertHandler<LookupElementDeco
|
||||
return false;
|
||||
}
|
||||
|
||||
PsiMethod constructor = JavaConstructorCallElement.extractCalledConstructor(delegate);
|
||||
|
||||
final PsiElement place = context.getFile().findElementAt(context.getStartOffset());
|
||||
assert place != null;
|
||||
boolean hasParams = hasConstructorParameters(psiClass, place);
|
||||
boolean hasParams = constructor != null ? constructor.getParameterList().getParametersCount() > 0 : hasConstructorParameters(psiClass, place);
|
||||
|
||||
JavaCompletionUtil.insertParentheses(context, delegate, false, hasParams, forAnonymous);
|
||||
|
||||
|
||||
+6
-2
@@ -49,8 +49,6 @@ public class JavaConstructorCallElement extends LookupElementDecorator<LookupEle
|
||||
myConstructor = constructor;
|
||||
myType = type;
|
||||
mySubstitutor = myType.resolveGenerics().getSubstitutor();
|
||||
|
||||
markClassItemWrapped(classItem);
|
||||
}
|
||||
|
||||
private void markClassItemWrapped(@NotNull LookupElement classItem) {
|
||||
@@ -62,6 +60,12 @@ public class JavaConstructorCallElement extends LookupElementDecorator<LookupEle
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleInsert(InsertionContext context) {
|
||||
markClassItemWrapped(getDelegate());
|
||||
super.handleInsert(context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiMethod getObject() {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
class Foo{
|
||||
Foo(int arg) {
|
||||
}
|
||||
Foo(boolean arg) {
|
||||
}
|
||||
Foo() {
|
||||
}
|
||||
Foo(boolean arg) {
|
||||
}
|
||||
|
||||
{
|
||||
Foo f = new F<caret>
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class Foo{
|
||||
Foo(int arg) {
|
||||
}
|
||||
Foo() {
|
||||
}
|
||||
Foo(boolean arg) {
|
||||
}
|
||||
|
||||
{
|
||||
Foo f = new Foo();<caret>
|
||||
}
|
||||
}
|
||||
+5
@@ -18,6 +18,8 @@ package com.intellij.codeInsight.completion
|
||||
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
|
||||
*/
|
||||
@@ -64,6 +66,9 @@ class SignatureCompletionTest extends LightFixtureCompletionTestCase {
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
def items = myFixture.lookup.items
|
||||
assert items.size() == 3
|
||||
assert ((PsiMethod) items[0].object).parameterList.parametersCount == 0
|
||||
myFixture.type('\n')
|
||||
checkResult()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user