mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 21:41:24 +07:00
IDEA-73717 Completion after 'new' and generics
This commit is contained in:
@@ -26,10 +26,12 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.filters.FilterPositionUtil;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.containers.hash.HashSet;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -81,8 +83,12 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
}
|
||||
}
|
||||
|
||||
OffsetKey refEnd = context.trackOffset(context.getTailOffset(), false);
|
||||
|
||||
boolean fillTypeArgs = false;
|
||||
if (shouldInsertParentheses(psiClass, position)) {
|
||||
if (ConstructorInsertHandler.insertParentheses(context, item, psiClass, false)) {
|
||||
fillTypeArgs = psiClass.hasTypeParameters() && PsiUtil.getLanguageLevel(file).isAtLeast(LanguageLevel.JDK_1_5);
|
||||
AutoPopupController.getInstance(project).autoPopupParameterInfo(editor, null);
|
||||
}
|
||||
}
|
||||
@@ -118,6 +124,13 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
}
|
||||
}
|
||||
|
||||
if (fillTypeArgs) {
|
||||
int typeArgs = context.getOffset(refEnd);
|
||||
if (typeArgs >= 0) {
|
||||
context.getDocument().insertString(typeArgs, "<>");
|
||||
context.getEditor().getCaretModel().moveToOffset(typeArgs + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldInsertParentheses(PsiClass psiClass, PsiElement position) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
public class Driver {
|
||||
{
|
||||
new ArrayLi<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Driver {
|
||||
{
|
||||
new ArrayList<<caret>>()
|
||||
}
|
||||
}
|
||||
@@ -899,6 +899,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
public void testMethodSquareBracket() throws Throwable { doTest('[') }
|
||||
|
||||
public void testMethodParameterTypeDot() throws Throwable { doAntiTest() }
|
||||
public void testNewGenericClass() throws Throwable { doTest('\n') }
|
||||
|
||||
public void testSuperProtectedMethod() throws Throwable {
|
||||
myFixture.addClass """package foo;
|
||||
|
||||
@@ -83,7 +83,7 @@ public class GroovyClassNameInsertHandler implements InsertHandler<JavaPsiClassR
|
||||
GroovyPsiElement place = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), GroovyPsiElement.class, false);
|
||||
JavaCompletionUtil.insertParentheses(context, item, false, place != null && GroovyCompletionUtil.hasConstructorParameters(psiClass, place));
|
||||
|
||||
if (context.getCompletionChar() == '<') {
|
||||
if (context.getCompletionChar() == '<' || psiClass.hasTypeParameters()) {
|
||||
context.getDocument().insertString(identifierEnd, "<>");
|
||||
context.setAddCompletionChar(false);
|
||||
context.getEditor().getCaretModel().moveToOffset(identifierEnd + 1);
|
||||
|
||||
@@ -236,9 +236,9 @@ new Fxoo()<caret>\n"""
|
||||
}
|
||||
|
||||
public void testNewImportedClassName() {
|
||||
myFixture.configureByText("a.groovy", "new ArrayLi<caret>\n")
|
||||
myFixture.configureByText("a.groovy", "new ArrayIndexOut<caret>\n")
|
||||
myFixture.completeBasic()
|
||||
myFixture.checkResult "new ArrayList(<caret>)\n"
|
||||
myFixture.checkResult "new ArrayIndexOutOfBoundsException(<caret>)\n"
|
||||
}
|
||||
|
||||
public void testOnlyAnnotationsAfterAt() {
|
||||
|
||||
@@ -830,6 +830,10 @@ class X {
|
||||
doBasicTest()
|
||||
}
|
||||
|
||||
public void testNewClassGenerics() {
|
||||
checkSingleItemCompletion 'new ArrayLi<caret>', 'new ArrayList<<caret>>()'
|
||||
}
|
||||
|
||||
public void testPropertyBeforeAccessor() {
|
||||
doVariantableTest 'soSe', 'setSoSe'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user