Search in sources :

Example 76 with GrTypeDefinition

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.

the class GrMethodOverrideCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    final PsiElement position = parameters.getPosition();
    final GrTypeDefinition currentClass = PsiTreeUtil.getParentOfType(position, GrTypeDefinition.class);
    if (currentClass != null) {
        addSuperMethods(currentClass, result, false);
        addSuperMethods(currentClass, result, true);
    }
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)

Example 77 with GrTypeDefinition

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.

the class GrReferenceListWeigher method getPreferredCondition.

@Override
protected Preference getPreferredCondition(@NotNull final PsiElement position) {
    if (INSIDE_REFERENCE_LIST.accepts(position)) {
        GrReferenceList list = (GrReferenceList) position.getParent().getParent();
        PsiElement parent = list.getParent();
        if (parent instanceof GrTypeDefinition) {
            GrTypeDefinition cls = (GrTypeDefinition) parent;
            if (cls.isInterface() && list == cls.getExtendsClause() || list == cls.getImplementsClause()) {
                return Preference.Interfaces;
            }
            if (list == cls.getExtendsClause()) {
                return Preference.Classes;
            }
        }
        if (parent instanceof GrMethod && ((GrMethod) parent).getThrowsList() == list) {
            return Preference.Exceptions;
        }
    }
    return null;
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrReferenceList(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) PsiElement(com.intellij.psi.PsiElement)

Example 78 with GrTypeDefinition

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.

the class GroovyDocumentationProvider method getQuickNavigateInfo.

@Override
@Nullable
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
    if (element instanceof GrVariable || element instanceof GrImplicitVariable) {
        StringBuilder buffer = new StringBuilder();
        PsiVariable variable = (PsiVariable) element;
        if (originalElement instanceof GrVariableDeclaration && ((GrVariableDeclaration) originalElement).getVariables().length > 1) {
            for (GrVariable var : ((GrVariableDeclaration) originalElement).getVariables()) {
                generateVariableInfo(originalElement, buffer, var);
                buffer.append("\n\n");
            }
        } else {
            generateVariableInfo(originalElement, buffer, variable);
        }
        return buffer.toString();
    } else if (element instanceof PsiMethod) {
        StringBuilder buffer = new StringBuilder();
        PsiMethod method = (PsiMethod) element;
        if (method instanceof GrGdkMethod) {
            buffer.append("[GDK] ");
        } else {
            PsiClass hisClass = method.getContainingClass();
            if (hisClass != null) {
                String qName = hisClass.getQualifiedName();
                if (qName != null) {
                    buffer.append(qName).append("\n");
                }
            }
        }
        PsiSubstitutor substitutor = calcSubstitutor(originalElement);
        if (!method.isConstructor()) {
            final PsiType substituted = substitutor.substitute(PsiUtil.getSmartReturnType(method));
            PsiImplUtil.appendTypeString(buffer, substituted, originalElement);
            buffer.append(" ");
        }
        buffer.append(method.getName()).append(" ");
        buffer.append("(");
        PsiParameter[] parameters = method.getParameterList().getParameters();
        for (int i = 0; i < parameters.length; i++) {
            PsiParameter parameter = parameters[i];
            if (i > 0)
                buffer.append(", ");
            if (parameter instanceof GrParameter) {
                GroovyPresentationUtil.appendParameterPresentation((GrParameter) parameter, substitutor, TypePresentation.LINK, buffer);
            } else {
                PsiType type = parameter.getType();
                PsiImplUtil.appendTypeString(buffer, substitutor.substitute(type), originalElement);
                buffer.append(" ");
                buffer.append(parameter.getName());
            }
        }
        buffer.append(")");
        final PsiClassType[] referencedTypes = method.getThrowsList().getReferencedTypes();
        if (referencedTypes.length > 0) {
            buffer.append("\nthrows ");
            for (PsiClassType referencedType : referencedTypes) {
                PsiImplUtil.appendTypeString(buffer, referencedType, originalElement);
                buffer.append(", ");
            }
            buffer.delete(buffer.length() - 2, buffer.length());
        }
        return buffer.toString();
    } else if (element instanceof GrTypeDefinition) {
        return generateClassInfo((GrTypeDefinition) element);
    }
    return null;
}
Also used : GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) GrImplicitVariable(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrImplicitVariable) GrVariableDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration) GrGdkMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)78 PsiElement (com.intellij.psi.PsiElement)17 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)17 PsiClass (com.intellij.psi.PsiClass)16 NotNull (org.jetbrains.annotations.NotNull)15 Nullable (org.jetbrains.annotations.Nullable)14 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)9 PsiFile (com.intellij.psi.PsiFile)8 GroovyFileBase (org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase)8 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)8 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)8 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)8 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)7 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)7 Project (com.intellij.openapi.project.Project)6 ArrayList (java.util.ArrayList)6 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)6 Editor (com.intellij.openapi.editor.Editor)5 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4