Search in sources :

Example 1 with PsiSubstitutor

use of com.intellij.psi.PsiSubstitutor in project intellij-community by JetBrains.

the class GrSuperReferenceResolver method resolveSuperExpression.

@Nullable("null if ref is not 'super' reference")
public static GroovyResolveResult[] resolveSuperExpression(@NotNull GrReferenceExpression ref) {
    GrExpression qualifier = ref.getQualifier();
    if (qualifier == null) {
        final PsiElement parent = ref.getParent();
        if (parent instanceof GrConstructorInvocation) {
            return ((GrConstructorInvocation) parent).multiResolve(false);
        }
        PsiClass aClass = PsiUtil.getContextClass(ref);
        if (aClass != null) {
            return getSuperClass(aClass);
        }
    } else if (qualifier instanceof GrReferenceExpression) {
        GroovyResolveResult result = ((GrReferenceExpression) qualifier).advancedResolve();
        PsiElement resolved = result.getElement();
        if (resolved instanceof PsiClass) {
            PsiClass superClass = (PsiClass) resolved;
            GrTypeDefinition scopeClass = PsiTreeUtil.getParentOfType(ref, GrTypeDefinition.class, true);
            if (scopeClass != null && GrTraitUtil.isTrait(superClass) && scopeClass.isInheritor(superClass, false)) {
                PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, scopeClass, PsiSubstitutor.EMPTY);
                return new GroovyResolveResultImpl[] { new GroovyResolveResultImpl(superClass, null, null, superClassSubstitutor, true, true) };
            }
            if (PsiUtil.hasEnclosingInstanceInScope(superClass, ref, false)) {
                return getSuperClass(superClass);
            }
        }
    }
    return null;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrConstructorInvocation(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiClass(com.intellij.psi.PsiClass) PsiSubstitutor(com.intellij.psi.PsiSubstitutor) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement) GroovyResolveResultImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PsiSubstitutor

use of com.intellij.psi.PsiSubstitutor in project intellij-community by JetBrains.

the class AssignableToFilter method isAcceptable.

@Override
public boolean isAcceptable(Object element, PsiElement context) {
    if (element == null)
        return false;
    if (element instanceof PsiType)
        return myType.isAssignableFrom((PsiType) element);
    PsiSubstitutor substitutor = null;
    if (element instanceof CandidateInfo) {
        final CandidateInfo info = (CandidateInfo) element;
        substitutor = info.getSubstitutor();
        element = info.getElement();
    }
    PsiType typeByElement = FilterUtil.getTypeByElement((PsiElement) element, context);
    if (substitutor != null)
        typeByElement = substitutor.substitute(typeByElement);
    return typeByElement != null && typeByElement.isAssignableFrom(myType) && !typeByElement.equals(myType);
}
Also used : CandidateInfo(com.intellij.psi.infos.CandidateInfo) PsiSubstitutor(com.intellij.psi.PsiSubstitutor) PsiType(com.intellij.psi.PsiType)

Example 3 with PsiSubstitutor

use of com.intellij.psi.PsiSubstitutor in project intellij-community by JetBrains.

the class TraitMethodImplementor method createImplementationPrototypes.

@NotNull
@Override
public PsiMethod[] createImplementationPrototypes(PsiClass inClass, PsiMethod method) throws IncorrectOperationException {
    if (!(inClass instanceof GrTypeDefinition && method instanceof GrTraitMethod))
        return PsiMethod.EMPTY_ARRAY;
    final PsiClass containingClass = method.getContainingClass();
    PsiSubstitutor substitutor = inClass.isInheritor(containingClass, true) ? TypeConversionUtil.getSuperClassSubstitutor(containingClass, inClass, PsiSubstitutor.EMPTY) : PsiSubstitutor.EMPTY;
    return new GrMethod[] { GroovyOverrideImplementUtil.generateTraitMethodPrototype((GrTypeDefinition) inClass, (GrTraitMethod) method, substitutor) };
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiClass(com.intellij.psi.PsiClass) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) PsiSubstitutor(com.intellij.psi.PsiSubstitutor) GrTraitMethod(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrTraitMethod) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiSubstitutor (com.intellij.psi.PsiSubstitutor)3 PsiClass (com.intellij.psi.PsiClass)2 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)2 PsiElement (com.intellij.psi.PsiElement)1 PsiType (com.intellij.psi.PsiType)1 CandidateInfo (com.intellij.psi.infos.CandidateInfo)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)1 GrConstructorInvocation (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation)1 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1 GroovyResolveResultImpl (org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl)1 GrTraitMethod (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrTraitMethod)1