mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
statically imported methods completion in groovy
This commit is contained in:
+8
-1
@@ -76,6 +76,13 @@ public class JavaGlobalMemberNameCompletionContributor extends CompletionContrib
|
||||
return;
|
||||
}
|
||||
|
||||
processStaticMethods(result, position, STATIC_METHOD_INSERT_HANDLER);
|
||||
}
|
||||
|
||||
public static void processStaticMethods(final CompletionResultSet result,
|
||||
final PsiElement position,
|
||||
final InsertHandler<LookupElement> insertHandler) {
|
||||
PrefixMatcher matcher = result.getPrefixMatcher();
|
||||
final Project project = position.getProject();
|
||||
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
|
||||
final PsiShortNamesCache namesCache = JavaPsiFacade.getInstance(project).getShortNamesCache();
|
||||
@@ -101,7 +108,7 @@ public class JavaGlobalMemberNameCompletionContributor extends CompletionContrib
|
||||
if (!JavaCompletionUtil.isInExcludedPackage(containingClass) && !StaticImportMethodFix.isExcluded(method)) {
|
||||
result.addElement(LookupElementDecorator.withInsertHandler(
|
||||
LookupElementDecorator.withRenderer(LookupElementBuilder.create(method), STATIC_METHOD_RENDERER),
|
||||
STATIC_METHOD_INSERT_HANDLER));
|
||||
insertHandler));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+31
-2
@@ -45,7 +45,6 @@ import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
@@ -98,6 +97,22 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
psiElement().withParent(psiElement(GrReferenceExpression.class).withParent(psiElement(GrArgumentList.class).withParent(GrCall.class)));
|
||||
|
||||
private static final String[] THIS_SUPER = {"this", "super"};
|
||||
private static final InsertHandler<LookupElement> STATIC_IMPORT_INSERT_HANDLER = new InsertHandler<LookupElement>() {
|
||||
@Override
|
||||
public void handleInsert(InsertionContext context, LookupElement item) {
|
||||
new GroovyInsertHandler().handleInsert(context, item);
|
||||
final PsiClass containingClass = ((PsiMethod)item.getObject()).getContainingClass();
|
||||
if (containingClass != null) {
|
||||
PsiDocumentManager.getInstance(containingClass.getProject()).commitDocument(context.getDocument());
|
||||
final GrReferenceExpression ref = PsiTreeUtil
|
||||
.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), GrReferenceExpression.class, false);
|
||||
if (ref != null) {
|
||||
ref.bindToElementViaStaticImport(containingClass);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public static boolean isReferenceInNewExpression(PsiElement reference) {
|
||||
if (!(reference instanceof GrCodeReferenceElement)) return false;
|
||||
@@ -303,7 +318,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
});
|
||||
|
||||
extend(CompletionType.BASIC, psiElement().withParent(GrReferenceElement.class), new CompletionProvider<CompletionParameters>() {
|
||||
extend(CompletionType.BASIC, psiElement().withParent(GrReferenceElement.class), new CompletionProvider<CompletionParameters>(false) {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters parameters,
|
||||
ProcessingContext context,
|
||||
@@ -323,6 +338,20 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
|
||||
}
|
||||
});
|
||||
extend(CompletionType.CLASS_NAME, psiElement().withParent(GrReferenceElement.class), new CompletionProvider<CompletionParameters>(false) {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters parameters,
|
||||
ProcessingContext context,
|
||||
@NotNull final CompletionResultSet result) {
|
||||
final PsiElement position = parameters.getPosition();
|
||||
if (((GrReferenceElement)position.getParent()).getQualifier() != null) return;
|
||||
|
||||
final String s = result.getPrefixMatcher().getPrefix();
|
||||
if (StringUtil.isEmpty(s) || !Character.isLowerCase(s.charAt(0))) return;
|
||||
|
||||
JavaGlobalMemberNameCompletionContributor.processStaticMethods(result, position, STATIC_IMPORT_INSERT_HANDLER);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void addPropertiesForClass(CompletionResultSet result,
|
||||
|
||||
@@ -107,4 +107,17 @@ public class GroovyClassNameCompletionTest extends LightCodeInsightFixtureTestCa
|
||||
myFixture.checkResult "a.FooBarGooDoo<caret>"
|
||||
}
|
||||
|
||||
public void testStaticMethod() throws Exception {
|
||||
myFixture.addFileToProject("b.groovy", """
|
||||
class Foo {
|
||||
static def abcmethod(int a) {}
|
||||
}""")
|
||||
myFixture.configureByText("a.groovy", "abcme<caret>")
|
||||
myFixture.complete(CompletionType.CLASS_NAME)
|
||||
myFixture.checkResult """import static Foo.abcmethod
|
||||
|
||||
abcmethod(<caret>)"""
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user