Search in sources :

Example 1 with GrTypeParameterListOwner

use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterListOwner in project intellij-community by JetBrains.

the class GrDocParameterReferenceImpl method multiResolve.

@Override
@NotNull
public ResolveResult[] multiResolve(boolean incompleteCode) {
    final String name = getName();
    if (name == null)
        return ResolveResult.EMPTY_ARRAY;
    ArrayList<GroovyResolveResult> candidates = new ArrayList<>();
    final PsiElement owner = GrDocCommentUtil.findDocOwner(this);
    if (owner instanceof GrMethod) {
        final GrMethod method = (GrMethod) owner;
        final GrParameter[] parameters = method.getParameters();
        for (GrParameter parameter : parameters) {
            if (name.equals(parameter.getName())) {
                candidates.add(new GroovyResolveResultImpl(parameter, true));
            }
        }
        return candidates.toArray(new ResolveResult[candidates.size()]);
    } else {
        final PsiElement firstChild = getFirstChild();
        if (owner instanceof GrTypeParameterListOwner && firstChild != null) {
            final ASTNode node = firstChild.getNode();
            if (node != null && GroovyDocTokenTypes.mGDOC_TAG_VALUE_LT.equals(node.getElementType())) {
                final PsiTypeParameter[] typeParameters = ((PsiTypeParameterListOwner) owner).getTypeParameters();
                for (PsiTypeParameter typeParameter : typeParameters) {
                    if (name.equals(typeParameter.getName())) {
                        candidates.add(new GroovyResolveResultImpl(typeParameter, true));
                    }
                }
            }
        }
    }
    return ResolveResult.EMPTY_ARRAY;
}
Also used : ArrayList(java.util.ArrayList) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) GroovyResolveResultImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) ASTNode(com.intellij.lang.ASTNode) GrTypeParameterListOwner(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterListOwner) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GrTypeParameterListOwner

use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterListOwner in project intellij-community by JetBrains.

the class GrDocParameterReferenceImpl method getVariants.

@Override
@NotNull
public Object[] getVariants() {
    final PsiElement owner = GrDocCommentUtil.findDocOwner(this);
    final PsiElement firstChild = getFirstChild();
    if (owner instanceof GrTypeParameterListOwner && firstChild != null) {
        final ASTNode node = firstChild.getNode();
        if (node != null && GroovyDocTokenTypes.mGDOC_TAG_VALUE_LT.equals(node.getElementType())) {
            return ((PsiTypeParameterListOwner) owner).getTypeParameters();
        }
    }
    if (owner instanceof PsiMethod) {
        return ((PsiMethod) owner).getParameterList().getParameters();
    }
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
Also used : ASTNode(com.intellij.lang.ASTNode) GrTypeParameterListOwner(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterListOwner) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ASTNode (com.intellij.lang.ASTNode)2 NotNull (org.jetbrains.annotations.NotNull)2 GrTypeParameterListOwner (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterListOwner)2 ArrayList (java.util.ArrayList)1 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)1 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1 GroovyResolveResultImpl (org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl)1