use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GrReferenceExpressionImpl method getNominalType.
@Nullable
private PsiType getNominalType(boolean forceRValue) {
final GroovyResolveResult resolveResult = PsiImplUtil.extractUniqueResult(multiResolve(false, forceRValue));
PsiElement resolved = resolveResult.getElement();
for (GrReferenceTypeEnhancer enhancer : GrReferenceTypeEnhancer.EP_NAME.getExtensions()) {
PsiType type = enhancer.getReferenceType(this, resolved);
if (type != null) {
return type;
}
}
IElementType dotType = getDotTokenType();
if (dotType == GroovyTokenTypes.mMEMBER_POINTER) {
return GrClosureType.create(multiResolve(false), this);
}
if (ResolveUtil.isDefinitelyKeyOfMap(this)) {
final PsiType type = getTypeFromMapAccess(this);
if (type != null) {
return type;
}
}
PsiType result = getNominalTypeInner(resolved);
if (result == null)
return null;
result = TypesUtil.substituteAndNormalizeType(result, resolveResult.getSubstitutor(), resolveResult.getSpreadState(), this);
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GrReferenceExpressionImpl method isReferenceTo.
@Override
public boolean isReferenceTo(PsiElement element) {
GroovyResolveResult[] results = multiResolve(false);
for (GroovyResolveResult result : results) {
if (!result.isValidResult())
continue;
PsiElement baseTarget = result.getElement();
if (baseTarget == null)
continue;
if (getManager().areElementsEquivalent(element, baseTarget)) {
return true;
}
PsiElement target = GroovyTargetElementEvaluator.correctSearchTargets(baseTarget);
if (target != baseTarget && getManager().areElementsEquivalent(element, target)) {
return true;
}
if (element instanceof PsiMethod && target instanceof PsiMethod) {
PsiMethod[] superMethods = ((PsiMethod) target).findSuperMethods(false);
//noinspection SuspiciousMethodCalls
if (Arrays.asList(superMethods).contains(element)) {
return true;
}
}
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GrReferenceExpressionImpl method doPolyResolve.
@NotNull
GroovyResolveResult[] doPolyResolve(boolean incompleteCode, boolean forceRValue) {
final PsiElement nameElement = getReferenceNameElement();
final String name = getReferenceName();
if (name == null || nameElement == null)
return GroovyResolveResult.EMPTY_ARRAY;
try {
ResolveProfiler.start();
boolean canBeMethod = ResolveUtil.canResolveToMethod(this);
if (!canBeMethod) {
if (ResolveUtil.isDefinitelyKeyOfMap(this))
return GroovyResolveResult.EMPTY_ARRAY;
final IElementType nameType = nameElement.getNode().getElementType();
if (nameType == GroovyTokenTypes.kTHIS) {
final GroovyResolveResult[] results = GrThisReferenceResolver.resolveThisExpression(this);
if (results != null)
return results;
} else if (nameType == GroovyTokenTypes.kSUPER) {
final GroovyResolveResult[] results = GrSuperReferenceResolver.resolveSuperExpression(this);
if (results != null)
return results;
}
}
final GroovyResolveResult[] results = resolveReferenceExpression(this, forceRValue, incompleteCode);
if (results.length == 0) {
return GroovyResolveResult.EMPTY_ARRAY;
} else if (!canBeMethod) {
if (!ResolveUtil.mayBeKeyOfMap(this)) {
return results;
} else {
//filter out all members from super classes. We should return only accessible members from map classes
final List<GroovyResolveResult> filtered = filterMembersFromSuperClasses(results);
return ContainerUtil.toArray(filtered, new GroovyResolveResult[filtered.size()]);
}
} else {
return results;
}
} finally {
final long time = ResolveProfiler.finish();
ResolveProfiler.write("ref", this, time);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GrReferenceExpressionImpl method filterMembersFromSuperClasses.
@NotNull
private static List<GroovyResolveResult> filterMembersFromSuperClasses(GroovyResolveResult[] results) {
List<GroovyResolveResult> filtered = new ArrayList<>();
for (GroovyResolveResult result : results) {
final PsiElement element = result.getElement();
if (element instanceof PsiMember) {
if (((PsiMember) element).hasModifierProperty(PsiModifier.PRIVATE))
continue;
final PsiClass containingClass = ((PsiMember) element).getContainingClass();
if (containingClass != null) {
if (!InheritanceUtil.isInheritor(containingClass, CommonClassNames.JAVA_UTIL_MAP))
continue;
final String name = containingClass.getQualifiedName();
if (name != null && name.startsWith("java."))
continue;
if (containingClass.getLanguage() != GroovyLanguage.INSTANCE && !InheritanceUtil.isInheritor(containingClass, GroovyCommonClassNames.GROOVY_OBJECT)) {
continue;
}
}
}
filtered.add(result);
}
return filtered;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult 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;
}
Aggregations