use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyPropertyUtils method findPropertySetter.
@Nullable
public static PsiMethod findPropertySetter(@Nullable PsiType type, String propertyName, @NotNull GroovyPsiElement context) {
final String setterName = getSetterName(propertyName);
if (type == null) {
final GrExpression fromText = GroovyPsiElementFactory.getInstance(context.getProject()).createExpressionFromText("this", context);
return findPropertySetter(fromText.getType(), propertyName, context);
}
final AccessorResolverProcessor processor = new AccessorResolverProcessor(setterName, propertyName, context, false);
ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), context);
final GroovyResolveResult[] setterCandidates = processor.getCandidates();
return PsiImplUtil.extractUniqueElement(setterCandidates);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class PsiUtil method isRawMethodCall.
public static boolean isRawMethodCall(GrMethodCallExpression call) {
final GroovyResolveResult result = call.advancedResolve();
final PsiElement element = result.getElement();
if (element == null)
return false;
if (element instanceof PsiMethod) {
PsiType returnType = getSmartReturnType((PsiMethod) element);
final GrExpression expression = call.getInvokedExpression();
if (expression instanceof GrReferenceExpression && result.isInvokedOnProperty()) {
if (returnType instanceof GrClosureType) {
return isRawClosureCall(call, result, (GrClosureType) returnType);
}
} else {
return isRawType(returnType, result.getSubstitutor());
}
}
if (element instanceof PsiVariable) {
GrExpression expression = call.getInvokedExpression();
final PsiType type = expression.getType();
if (type instanceof GrClosureType) {
return isRawClosureCall(call, result, (GrClosureType) type);
}
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class ClosureParameterEnhancer method findTypeFromIteratorMethod.
@Nullable
private static PsiType findTypeFromIteratorMethod(@Nullable PsiType type, PsiElement context) {
if (!(type instanceof PsiClassType))
return null;
final GroovyResolveResult[] candidates = ResolveUtil.getMethodCandidates(type, "iterator", context, PsiType.EMPTY_ARRAY);
final GroovyResolveResult candidate = PsiImplUtil.extractUniqueResult(candidates);
final PsiElement element = candidate.getElement();
if (!(element instanceof PsiMethod))
return null;
final PsiType returnType = org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.getSmartReturnType((PsiMethod) element);
final PsiType iteratorType = candidate.getSubstitutor().substitute(returnType);
return PsiUtil.substituteTypeParameter(iteratorType, JAVA_UTIL_ITERATOR, 0, false);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GrLightAnnotation method getNameReferenceElement.
@Override
public PsiJavaCodeReferenceElement getNameReferenceElement() {
final GroovyResolveResult resolveResult = myRef.advancedResolve();
final PsiElement resolved = resolveResult.getElement();
if (resolved instanceof PsiClass) {
return new LightClassReference(getManager(), getClassReference().getText(), (PsiClass) resolved, resolveResult.getSubstitutor());
} else {
return null;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class PsiUtil method isVoidMethodCall.
public static boolean isVoidMethodCall(@Nullable GrExpression expression) {
if (expression instanceof GrMethodCall && PsiType.NULL.equals(expression.getType())) {
final GroovyResolveResult resolveResult = ((GrMethodCall) expression).advancedResolve();
final PsiType[] args = getArgumentTypes(((GrMethodCall) expression).getInvokedExpression(), true);
return PsiType.VOID.equals(ResolveUtil.extractReturnTypeFromCandidate(resolveResult, expression, args));
}
return false;
}
Aggregations