Search in sources :

Example 1 with GrRenameableLightElement

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrRenameableLightElement in project intellij-community by JetBrains.

the class GroovyTargetElementEvaluator method getElementByReference.

@Override
public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) {
    PsiElement sourceElement = ref.getElement();
    if (sourceElement instanceof GrCodeReferenceElement) {
        GrNewExpression newExpr;
        if (sourceElement.getParent() instanceof GrNewExpression) {
            newExpr = (GrNewExpression) sourceElement.getParent();
        } else if (sourceElement.getParent().getParent() instanceof GrNewExpression) {
            //anonymous class declaration
            newExpr = (GrNewExpression) sourceElement.getParent().getParent();
        } else {
            return null;
        }
        final PsiMethod constructor = newExpr.resolveMethod();
        final GrArgumentList argumentList = newExpr.getArgumentList();
        if (constructor != null && argumentList != null && PsiImplUtil.hasNamedArguments(argumentList) && !PsiImplUtil.hasExpressionArguments(argumentList)) {
            if (constructor.getParameterList().getParametersCount() == 0)
                return constructor.getContainingClass();
        }
        return constructor;
    }
    if (sourceElement instanceof GrReferenceExpression) {
        PsiElement resolved = ((GrReferenceExpression) sourceElement).resolve();
        if (resolved instanceof GrGdkMethod || !(resolved instanceof GrRenameableLightElement)) {
            return correctSearchTargets(resolved);
        }
        return resolved;
    }
    return null;
}
Also used : GrNewExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression) GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GrGdkMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod) PsiMethod(com.intellij.psi.PsiMethod) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrRenameableLightElement(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrRenameableLightElement) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 PsiMethod (com.intellij.psi.PsiMethod)1 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)1 GrNewExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1 GrGdkMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod)1 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)1 GrRenameableLightElement (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrRenameableLightElement)1