use of org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor in project intellij-community by JetBrains.
the class GrDocMethodReferenceImpl method resolve.
@Override
public PsiElement resolve() {
String name = getReferenceName();
GrDocReferenceElement holder = getReferenceHolder();
PsiElement resolved;
if (holder != null) {
GrCodeReferenceElement referenceElement = holder.getReferenceElement();
resolved = referenceElement != null ? referenceElement.resolve() : null;
} else {
resolved = PsiUtil.getContextClass(this);
}
if (resolved instanceof PsiClass) {
PsiType[] parameterTypes = getParameterList().getParameterTypes();
PsiType thisType = JavaPsiFacade.getInstance(getProject()).getElementFactory().createType((PsiClass) resolved, PsiSubstitutor.EMPTY);
MethodResolverProcessor processor = new MethodResolverProcessor(name, this, false, thisType, parameterTypes, PsiType.EMPTY_ARRAY);
resolved.processDeclarations(processor, ResolveState.initial(), resolved, this);
if (processor.hasApplicableCandidates()) {
return processor.getCandidates()[0].getElement();
}
MethodResolverProcessor constructorProcessor = new MethodResolverProcessor(name, this, true, thisType, parameterTypes, PsiType.EMPTY_ARRAY);
resolved.processDeclarations(constructorProcessor, ResolveState.initial(), resolved, this);
if (constructorProcessor.hasApplicableCandidates()) {
return constructorProcessor.getCandidates()[0].getElement();
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor in project intellij-community by JetBrains.
the class GrDocMethodReferenceImpl method multiResolveImpl.
@Override
protected ResolveResult[] multiResolveImpl() {
String name = getReferenceName();
GrDocReferenceElement holder = getReferenceHolder();
PsiElement resolved;
if (holder != null) {
GrCodeReferenceElement referenceElement = holder.getReferenceElement();
resolved = referenceElement != null ? referenceElement.resolve() : null;
} else {
resolved = PsiUtil.getContextClass(this);
}
if (resolved instanceof PsiClass) {
PsiType[] parameterTypes = getParameterList().getParameterTypes();
PsiType thisType = JavaPsiFacade.getInstance(getProject()).getElementFactory().createType((PsiClass) resolved, PsiSubstitutor.EMPTY);
MethodResolverProcessor processor = new MethodResolverProcessor(name, this, false, thisType, parameterTypes, PsiType.EMPTY_ARRAY);
MethodResolverProcessor constructorProcessor = new MethodResolverProcessor(name, this, true, thisType, parameterTypes, PsiType.EMPTY_ARRAY);
resolved.processDeclarations(processor, ResolveState.initial(), resolved, this);
resolved.processDeclarations(constructorProcessor, ResolveState.initial(), resolved, this);
return ArrayUtil.mergeArrays(processor.getCandidates(), constructorProcessor.getCandidates());
}
return ResolveResult.EMPTY_ARRAY;
}
use of org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor in project intellij-community by JetBrains.
the class PsiUtil method isRawIndexPropertyAccess.
private static boolean isRawIndexPropertyAccess(GrIndexProperty expr) {
final GrExpression qualifier = expr.getInvokedExpression();
final PsiType qualifierType = qualifier.getType();
if (qualifierType instanceof PsiClassType) {
if (InheritanceUtil.isInheritor(qualifierType, CommonClassNames.JAVA_UTIL_LIST)) {
return com.intellij.psi.util.PsiUtil.extractIterableTypeParameter(qualifierType, false) == null;
}
if (InheritanceUtil.isInheritor(qualifierType, CommonClassNames.JAVA_UTIL_MAP)) {
return com.intellij.psi.util.PsiUtil.substituteTypeParameter(qualifierType, CommonClassNames.JAVA_UTIL_MAP, 1, false) == null;
}
PsiClassType classType = (PsiClassType) qualifierType;
final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics();
GrExpression[] arguments = expr.getArgumentList().getExpressionArguments();
PsiType[] argTypes = PsiType.createArray(arguments.length);
for (int i = 0; i < arguments.length; i++) {
PsiType argType = arguments[i].getType();
if (argType == null)
argType = TypesUtil.getJavaLangObject(expr);
argTypes[i] = argType;
}
MethodResolverProcessor processor = new MethodResolverProcessor("getAt", expr, false, qualifierType, argTypes, PsiType.EMPTY_ARRAY);
final PsiClass qClass = resolveResult.getElement();
final ResolveState state = ResolveState.initial().put(PsiSubstitutor.KEY, PsiSubstitutor.EMPTY);
if (qClass != null) {
qClass.processDeclarations(processor, state, null, expr);
}
ResolveUtil.processNonCodeMembers(qualifierType, processor, qualifier, state);
final GroovyResolveResult[] candidates = processor.getCandidates();
PsiType type = null;
if (candidates.length == 1) {
final PsiElement element = candidates[0].getElement();
if (element instanceof PsiMethod) {
type = getSmartReturnType((PsiMethod) element);
}
}
return isRawType(type, resolveResult.getSubstitutor());
}
return false;
}
Aggregations