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;
}
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);
}
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) };
}
Aggregations