mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
show the inferred groovy variable type in the completion type text
This commit is contained in:
+8
-7
@@ -346,16 +346,17 @@ public class GroovyCompletionUtil {
|
||||
|
||||
|
||||
private static LookupElementBuilder setTypeText(PsiElement element, LookupElementBuilder builder, PsiSubstitutor substitutor) {
|
||||
if (element instanceof PsiVariable) {
|
||||
builder = builder.setTypeText(substitutor.substitute(((PsiVariable)element).getType()).getPresentableText());
|
||||
PsiType type = null;
|
||||
if (element instanceof GrVariable) {
|
||||
type = ((GrVariable)element).getTypeGroovy();
|
||||
}
|
||||
else if (element instanceof PsiVariable) {
|
||||
type = ((PsiVariable)element).getType();
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
final PsiType type = substitutor.substitute(((PsiMethod)element).getReturnType());
|
||||
if (type != null) {
|
||||
builder = builder.setTypeText(type.getPresentableText());
|
||||
}
|
||||
type = substitutor.substitute(((PsiMethod)element).getReturnType());
|
||||
}
|
||||
return builder;
|
||||
return type != null ? builder.setTypeText(type.getPresentableText()) : builder;
|
||||
}
|
||||
|
||||
public static boolean hasConstructorParameters(@NotNull PsiClass clazz, @NotNull GroovyPsiElement place) {
|
||||
|
||||
+6
-2
@@ -69,7 +69,11 @@ public class GrKindWeigher extends CompletionWeigher {
|
||||
if (o instanceof PsiPackage) return NotQualifiedKind.aPackage;
|
||||
if (isLightElement(o)) return NotQualifiedKind.anImplicitGroovyMethod;
|
||||
if (o instanceof PsiMember) return NotQualifiedKind.aMember;
|
||||
if (o instanceof String) return NotQualifiedKind.aString;
|
||||
if (o instanceof String) {
|
||||
if ("for".equals(o)) return NotQualifiedKind.aKeyword;
|
||||
|
||||
return NotQualifiedKind.aString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (o instanceof PsiClass) return QualifiedKind.aClass;
|
||||
@@ -97,7 +101,7 @@ public class GrKindWeigher extends CompletionWeigher {
|
||||
}
|
||||
|
||||
static enum NotQualifiedKind {
|
||||
aPackage, aClass, anImplicitGroovyMethod, aMember, aLocal, aString
|
||||
aPackage, aClass, anImplicitGroovyMethod, aKeyword, aMember, aLocal, aString
|
||||
}
|
||||
|
||||
static enum QualifiedKind {
|
||||
|
||||
+9
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.lookup.LookupElement
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
import com.intellij.codeInsight.CodeInsightSettings
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
@@ -205,6 +206,14 @@ public class GroovyCompletionTest extends GroovyCompletionTestBase {
|
||||
myFixture.testCompletionVariants(getTestName(false) + ".groovy", "geteMail", "getePost");
|
||||
}
|
||||
|
||||
public void testInferredVariableType() throws Exception {
|
||||
myFixture.configureByText "a.groovy", "def foo = 'xxx'; fo<caret>"
|
||||
def presentation = new LookupElementPresentation()
|
||||
myFixture.completeBasic()[0].renderElement(presentation)
|
||||
assert presentation.itemText == 'foo'
|
||||
assert presentation.typeText == 'String'
|
||||
}
|
||||
|
||||
public void testIntCompletionInPlusMethod() {doBasicTest();}
|
||||
public void testIntCompletionInGenericParameter() {doBasicTest();}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user