IDEA-81966 Accepting completion variant for a generic type with < inserts duplicate angle brackets

This commit is contained in:
peter
2012-02-29 23:38:56 +04:00
parent 5134881c2a
commit 413a6df237
6 changed files with 25 additions and 5 deletions

View File

@@ -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());

View File

@@ -942,6 +942,7 @@ public class JavaCompletionUtil {
context.getDocument().insertString(offset, "<>");
context.getEditor().getCaretModel().moveToOffset(offset + 1);
context.setAddCompletionChar(false);
return true;
}
}

View File

@@ -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 "";
}

View File

@@ -0,0 +1,7 @@
class Zooooooo<T> { }
class Bar {
{
Zooooooo<String> z = new Zoooo<caret>
}
}

View File

@@ -0,0 +1,7 @@
class Zooooooo<T> { }
class Bar {
{
Zooooooo<String> z = new Zooooooo<<caret>>()
}
}

View File

@@ -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(':') }