mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
IDEA-81966 Accepting completion variant for a generic type with < inserts duplicate angle brackets
This commit is contained in:
@@ -73,7 +73,7 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
|
||||
if (delegate instanceof PsiTypeLookupItem) {
|
||||
fillTypeArgs = !isRawTypeExpected(context, (PsiTypeLookupItem)delegate) &&
|
||||
psiClass.getTypeParameters().length > 0 &&
|
||||
((PsiTypeLookupItem)delegate).calcGenerics(position).isEmpty() &&
|
||||
((PsiTypeLookupItem)delegate).calcGenerics(position, context).isEmpty() &&
|
||||
context.getCompletionChar() != '(';
|
||||
delegate.handleInsert(context);
|
||||
PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting(context.getFile().getViewProvider());
|
||||
|
||||
@@ -942,6 +942,7 @@ public class JavaCompletionUtil {
|
||||
|
||||
context.getDocument().insertString(offset, "<>");
|
||||
context.getEditor().getCaretModel().moveToOffset(offset + 1);
|
||||
context.setAddCompletionChar(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class PsiTypeLookupItem extends LookupItem {
|
||||
|
||||
PsiElement position = context.getFile().findElementAt(context.getStartOffset());
|
||||
assert position != null;
|
||||
context.getDocument().insertString(context.getTailOffset(), calcGenerics(position));
|
||||
context.getDocument().insertString(context.getTailOffset(), calcGenerics(position, context));
|
||||
JavaCompletionUtil.shortenReference(context.getFile(), context.getStartOffset());
|
||||
|
||||
int tail = context.getTailOffset();
|
||||
@@ -95,13 +95,17 @@ public class PsiTypeLookupItem extends LookupItem {
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
|
||||
InsertHandler handler = getInsertHandler();
|
||||
if (handler != null && !(handler instanceof DefaultInsertHandler)) {
|
||||
if (handler != null && !(handler instanceof DefaultInsertHandler)) {
|
||||
//noinspection unchecked
|
||||
handler.handleInsert(context, this);
|
||||
}
|
||||
}
|
||||
|
||||
public String calcGenerics(@NotNull PsiElement context) {
|
||||
public String calcGenerics(@NotNull PsiElement context, InsertionContext insertionContext) {
|
||||
if (insertionContext.getCompletionChar() == '<') {
|
||||
return "";
|
||||
}
|
||||
|
||||
assert context.isValid();
|
||||
if (myDiamond) {
|
||||
return "<>";
|
||||
@@ -115,7 +119,7 @@ public class PsiTypeLookupItem extends LookupItem {
|
||||
for (PsiTypeParameter parameter : psiClass.getTypeParameters()) {
|
||||
PsiType substitute = substitutor.substitute(parameter);
|
||||
if (substitute == null ||
|
||||
(PsiUtil.resolveClassInType(substitute) == parameter &&
|
||||
(PsiUtil.resolveClassInType(substitute) == parameter &&
|
||||
resolveHelper.resolveReferencedClass(parameter.getName(), context) != CompletionUtil.getOriginalOrSelf(parameter))) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Zooooooo<T> { }
|
||||
|
||||
class Bar {
|
||||
{
|
||||
Zooooooo<String> z = new Zoooo<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class Zooooooo<T> { }
|
||||
|
||||
class Bar {
|
||||
{
|
||||
Zooooooo<String> z = new Zooooooo<<caret>>()
|
||||
}
|
||||
}
|
||||
@@ -1149,6 +1149,7 @@ public class ListUtils {
|
||||
}
|
||||
|
||||
public void testNewClassAngleBracket() throws Exception { doTest('<') }
|
||||
public void testNewClassAngleBracketExpected() throws Exception { doTest('<') }
|
||||
public void testNewClassSquareBracket() throws Exception { doTest('[') }
|
||||
|
||||
public void testMethodColon() throws Exception { doTest(':') }
|
||||
|
||||
Reference in New Issue
Block a user