IDEA-73345 Completion does not propose generic parameters of a method until the header is complete

This commit is contained in:
peter
2011-09-16 14:13:47 +02:00
parent 43eb3e6dc5
commit 367fcd17a8
9 changed files with 81 additions and 17 deletions
@@ -522,21 +522,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
result.addElement(createKeyword(position, PsiKeyword.CLASS));
}
final ProcessingContext context = new ProcessingContext();
if (psiElement().afterLeaf(
psiElement().withText(">").withParent(
psiElement(PsiTypeParameterList.class).withParent(PsiErrorElement.class).save("typeParameterList"))).accepts(position, context)) {
final PsiTypeParameterList list = (PsiTypeParameterList)context.get("typeParameterList");
PsiElement current = list.getParent().getParent();
if (current instanceof PsiField) {
current = current.getParent();
}
if (current instanceof PsiClass) {
for (PsiTypeParameter typeParameter : list.getTypeParameters()) {
result.addElement(new JavaPsiClassReferenceElement(typeParameter));
}
}
}
addUnfinishedMethodTypeParameters(position, result);
if (JavaSmartCompletionContributor.INSIDE_EXPRESSION.accepts(position) &&
!BasicExpressionCompletionContributor.AFTER_DOT.accepts(position) &&
@@ -553,6 +539,25 @@ public class JavaCompletionData extends JavaAwareCompletionData{
}
}
private static void addUnfinishedMethodTypeParameters(PsiElement position, CompletionResultSet result) {
final ProcessingContext context = new ProcessingContext();
if (psiElement().inside(
psiElement(PsiTypeElement.class).afterLeaf(
psiElement().withText(">").withParent(
psiElement(PsiTypeParameterList.class).withParent(PsiErrorElement.class).save("typeParameterList")))).accepts(position, context)) {
final PsiTypeParameterList list = (PsiTypeParameterList)context.get("typeParameterList");
PsiElement current = list.getParent().getParent();
if (current instanceof PsiField) {
current = current.getParent();
}
if (current instanceof PsiClass) {
for (PsiTypeParameter typeParameter : list.getTypeParameters()) {
result.addElement(new JavaPsiClassReferenceElement(typeParameter));
}
}
}
}
static boolean isAfterPrimitiveOrArrayType(PsiElement element) {
return psiElement().withParent(
psiReferenceExpression().withFirstChild(
@@ -74,7 +74,11 @@ public class JavaPsiClassReferenceElement extends LookupItem<Object> {
final JavaPsiClassReferenceElement that = (JavaPsiClassReferenceElement)o;
return Comparing.equal(myQualifiedName, that.myQualifiedName);
if (myQualifiedName != null) {
return myQualifiedName.equals(that.myQualifiedName);
}
return Comparing.equal(myClass, that.myClass);
}
public String getQualifiedName() {
@@ -0,0 +1,5 @@
import java.util.ArrayList;
class A {
public static <MyParameter, MySecondParameter> ArrayList<My<caret>>
}
@@ -0,0 +1,5 @@
import java.util.ArrayList;
class A {
public static <MyParameter, MySecondParameter> My<caret>>
}
@@ -917,7 +917,15 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
public void testMethodParameterTypeDot() throws Throwable { doAntiTest() }
public void testNewGenericClass() throws Throwable { doTest('\n') }
public void testNewGenericInterface() throws Throwable { doTest() }
//public void testUnfinishedMethodTypeParameter() throws Throwable { doTest() }
public void testUnfinishedMethodTypeParameter() throws Throwable {
configure()
assertStringItems("MyParameter", "MySecondParameter")
}
public void testUnfinishedMethodTypeParameter2() throws Throwable {
configure()
assertStringItems("MyParameter", "MySecondParameter")
}
public void testSuperProtectedMethod() throws Throwable {
myFixture.addClass """package foo;
@@ -61,6 +61,8 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAc
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod;
import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement;
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterList;
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils;
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
import org.jetbrains.plugins.groovy.refactoring.inline.InlineMethodConflictSolver;
@@ -287,6 +289,8 @@ public class GroovyCompletionContributor extends CompletionContributor {
suggestVariableNames(position, result);
addUnfinishedMethodTypeParameters(position, result);
final PsiElement parent = position.getParent();
if (parent instanceof GrReferenceElement) {
GrReferenceElement reference = (GrReferenceElement)parent;
@@ -339,6 +343,25 @@ public class GroovyCompletionContributor extends CompletionContributor {
}
private static void addUnfinishedMethodTypeParameters(PsiElement position, CompletionResultSet result) {
final ProcessingContext context = new ProcessingContext();
if (PsiJavaPatterns.psiElement().inside(
PsiJavaPatterns.psiElement(GrTypeElement.class).afterLeaf(
PsiJavaPatterns.psiElement().withText(">").withParent(
PsiJavaPatterns.psiElement(GrTypeParameterList.class).withParent(PsiErrorElement.class).save("typeParameterList")))).accepts(
position, context)) {
final GrTypeParameterList list = (GrTypeParameterList)context.get("typeParameterList");
PsiElement current = list.getParent().getParent();
if (current instanceof PsiField) {
current = current.getParent();
}
if (current instanceof GrTypeDefinitionBody) {
for (PsiTypeParameter typeParameter : list.getTypeParameters()) {
result.addElement(new JavaPsiClassReferenceElement(typeParameter));
}
}
}
}
@Override
public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) {
@@ -90,6 +90,14 @@ public class GroovyCompletionTest extends GroovyCompletionTestBase {
doVariantableTest("hahaha", "hohoho");
}
public void testUnfinishedMethodTypeParameter() throws Throwable {
doVariantableTest("MyParameter", "MySecondParameter");
}
public void testUnfinishedMethodTypeParameter2() throws Throwable {
doVariantableTest("MyParameter", "MySecondParameter");
}
public void testInstanceofHelpsDetermineType() throws Throwable {
doBasicTest();
}
@@ -0,0 +1,3 @@
class A {
public static <MyParameter, MySecondParameter> ArrayList<My<caret>>
}
@@ -0,0 +1,3 @@
class A {
public static <MyParameter, MySecondParameter> My<caret>
}