Search in sources :

Example 1 with GroovyMethodOverrideHandler

use of org.jetbrains.plugins.groovy.lang.completion.handlers.GroovyMethodOverrideHandler in project intellij-community by JetBrains.

the class GrMethodOverrideCompletionProvider method addSuperMethods.

private static void addSuperMethods(final GrTypeDefinition psiClass, CompletionResultSet completionResultSet, boolean toImplement) {
    final Collection<CandidateInfo> candidates = GroovyOverrideImplementExploreUtil.getMethodsToOverrideImplement(psiClass, toImplement);
    for (CandidateInfo candidateInfo : candidates) {
        final PsiMethod method = (PsiMethod) candidateInfo.getElement();
        if (method.isConstructor())
            continue;
        RowIcon icon = new RowIcon(2);
        icon.setIcon(method.getIcon(0), 0);
        icon.setIcon(toImplement ? AllIcons.Gutter.ImplementingMethod : AllIcons.Gutter.OverridingMethod, 1);
        PsiSubstitutor substitutor = candidateInfo.getSubstitutor();
        String parameters = PsiFormatUtil.formatMethod(method, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME);
        String visibility = VisibilityUtil.getVisibilityModifier(method.getModifierList());
        String modifiers = (visibility == PsiModifier.PACKAGE_LOCAL ? "" : visibility + " ");
        PsiType type = substitutor.substitute(method.getReturnType());
        String parentClassName = psiClass == null ? "" : psiClass.getName();
        String signature = modifiers + (type == null ? "" : type.getPresentableText() + " ") + method.getName();
        LookupElementBuilder lookupElement = LookupElementBuilder.create(method, signature).appendTailText(parameters, false).appendTailText("{...}", true).withTypeText(parentClassName).withIcon(icon).withInsertHandler(new GroovyMethodOverrideHandler(psiClass));
        completionResultSet.addElement(lookupElement);
    }
}
Also used : CandidateInfo(com.intellij.psi.infos.CandidateInfo) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) RowIcon(com.intellij.ui.RowIcon) GroovyMethodOverrideHandler(org.jetbrains.plugins.groovy.lang.completion.handlers.GroovyMethodOverrideHandler)

Aggregations

LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 CandidateInfo (com.intellij.psi.infos.CandidateInfo)1 RowIcon (com.intellij.ui.RowIcon)1 GroovyMethodOverrideHandler (org.jetbrains.plugins.groovy.lang.completion.handlers.GroovyMethodOverrideHandler)1