mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
IDEA-65583:
insert import when completing a class reference with existing generics on tab, replace the generics, if any
This commit is contained in:
@@ -4,6 +4,7 @@ import com.intellij.codeInsight.generation.GenerateMembersUtil;
|
||||
import com.intellij.codeInsight.generation.OverrideImplementUtil;
|
||||
import com.intellij.codeInsight.generation.PsiGenerationInfo;
|
||||
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.featureStatistics.FeatureUsageTracker;
|
||||
@@ -34,6 +35,8 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.ConstructorInsertHandler");
|
||||
public static final ConstructorInsertHandler SMART_INSTANCE = new ConstructorInsertHandler(true);
|
||||
public static final ConstructorInsertHandler BASIC_INSTANCE = new ConstructorInsertHandler(false);
|
||||
static final OffsetKey PARAM_LIST_START = OffsetKey.create("paramListStart");
|
||||
static final OffsetKey PARAM_LIST_END = OffsetKey.create("paramListEnd");
|
||||
private final boolean mySmart;
|
||||
|
||||
private ConstructorInsertHandler(boolean smart) {
|
||||
@@ -51,6 +54,15 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
|
||||
boolean withTail = item.getUserData(LookupItem.BRACKETS_COUNT_ATTR) == null && !inAnonymous;
|
||||
boolean isAbstract = ((PsiClass)item.getObject()).hasModifierProperty(PsiModifier.ABSTRACT);
|
||||
|
||||
if (Lookup.REPLACE_SELECT_CHAR == context.getCompletionChar()) {
|
||||
final int plStart = context.getOffset(PARAM_LIST_START);
|
||||
final int plEnd = context.getOffset(PARAM_LIST_END);
|
||||
if (plStart >= 0 && plEnd >= 0) {
|
||||
context.getDocument().deleteString(plStart, plEnd);
|
||||
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
|
||||
}
|
||||
}
|
||||
|
||||
insertParentheses(context, delegate, delegate.getObject(), withTail && isAbstract);
|
||||
|
||||
DefaultInsertHandler.addImportForItem(context, delegate);
|
||||
|
||||
@@ -79,13 +79,7 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
PsiElement parent = position.getParent();
|
||||
if (parent instanceof PsiJavaCodeReferenceElement) {
|
||||
final PsiJavaCodeReferenceElement ref = (PsiJavaCodeReferenceElement)parent;
|
||||
if (PsiTreeUtil.getParentOfType(position, PsiDocTag.class) != null) {
|
||||
if (ref.isReferenceTo(psiClass)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
final PsiReferenceParameterList parameterList = ref.getParameterList();
|
||||
if (parameterList != null && parameterList.getTextLength() > 0) {
|
||||
if (PsiTreeUtil.getParentOfType(position, PsiDocTag.class) != null && ref.isReferenceTo(psiClass)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -132,6 +126,15 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
|
||||
private static boolean shouldInsertParentheses(PsiClass psiClass, PsiElement position) {
|
||||
final PsiJavaCodeReferenceElement ref = PsiTreeUtil.getParentOfType(position, PsiJavaCodeReferenceElement.class);
|
||||
if (ref == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiReferenceParameterList parameterList = ref.getParameterList();
|
||||
if (parameterList != null && parameterList.getTextLength() > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final PsiElement prevElement = FilterPositionUtil.searchNonSpaceNonCommentBack(ref);
|
||||
if (prevElement != null && prevElement.getParent() instanceof PsiNewExpression) {
|
||||
|
||||
|
||||
@@ -536,6 +536,15 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
final PsiJavaCodeReferenceElement ref = PsiTreeUtil.findElementOfClassAtOffset(file, context.getStartOffset(), PsiJavaCodeReferenceElement.class, false);
|
||||
if (ref != null && !(ref instanceof PsiReferenceExpression)) {
|
||||
context.setDummyIdentifier(CompletionInitializationContext.DUMMY_IDENTIFIER.trim() + ";");
|
||||
|
||||
if (JavaSmartCompletionContributor.AFTER_NEW.accepts(ref)) {
|
||||
final PsiReferenceParameterList paramList = ref.getParameterList();
|
||||
if (paramList != null && paramList.getTextLength() > 0) {
|
||||
context.getOffsetMap().addOffset(ConstructorInsertHandler.PARAM_LIST_START, paramList.getTextRange().getStartOffset());
|
||||
context.getOffsetMap().addOffset(ConstructorInsertHandler.PARAM_LIST_END, paramList.getTextRange().getEndOffset());
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Foo {
|
||||
public static void main(String[] args) {
|
||||
List<Integer> set = new ArrayLis<caret>t<Integer>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Foo {
|
||||
public static void main(String[] args) {
|
||||
List<Integer> set = new ArrayList<Integer>(<caret>);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class Foo {
|
||||
public static void main(String[] args) {
|
||||
Set<caret><Integer>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import java.util.Set;
|
||||
|
||||
public class Foo {
|
||||
public static void main(String[] args) {
|
||||
Set<caret><Integer>
|
||||
}
|
||||
}
|
||||
@@ -676,6 +676,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
public void testReturningTypeVariable() throws Throwable { doTest(); }
|
||||
public void testReturningTypeVariable2() throws Throwable { doTest(); }
|
||||
public void testReturningTypeVariable3() throws Throwable { doTest(); }
|
||||
public void testImportInGenericType() throws Throwable { doTest(); }
|
||||
|
||||
public void testCaseTailType() throws Throwable { doTest(); }
|
||||
|
||||
@@ -808,6 +809,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
public void testClassNameWithInnersTab() throws Throwable { doTest('\t') }
|
||||
|
||||
public void testClassNameWithGenericsTab() throws Throwable {doTest('\t') }
|
||||
public void testClassNameWithGenericsTab2() throws Throwable {doTest('\t') }
|
||||
|
||||
public void testLiveTemplatePrefixTab() throws Throwable {doTest('\t') }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user