use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature in project intellij-community by JetBrains.
the class ResolveUtil method extractReturnTypeFromCandidate.
@Nullable
public static PsiType extractReturnTypeFromCandidate(GroovyResolveResult candidate, GrExpression expression, @Nullable PsiType[] args) {
final PsiElement element = candidate.getElement();
if (element instanceof PsiMethod && !candidate.isInvokedOnProperty()) {
return TypesUtil.substituteAndNormalizeType(org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.getSmartReturnType((PsiMethod) element), candidate.getSubstitutor(), candidate.getSpreadState(), expression);
}
final PsiType type;
if (element instanceof GrField) {
type = ((GrField) element).getTypeGroovy();
} else if (element instanceof PsiMethod) {
type = org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.getSmartReturnType((PsiMethod) element);
} else {
return null;
}
if (type instanceof GrClosureType) {
final GrSignature signature = ((GrClosureType) type).getSignature();
PsiType returnType = GrClosureSignatureUtil.getReturnType(signature, args, expression);
return TypesUtil.substituteAndNormalizeType(returnType, candidate.getSubstitutor(), candidate.getSpreadState(), expression);
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature in project intellij-community by JetBrains.
the class GrMethodConflictUtil method checkForClosurePropertySignatureOverload.
private static void checkForClosurePropertySignatureOverload(PsiClass clazz, GrMethod prototype, final GrMethod refactoredMethod, final MultiMap<PsiElement, String> conflicts, final List<MethodSignature> prototypeSignatures) {
final boolean isStatic = prototype.hasModifierProperty(PsiModifier.STATIC);
final String name = prototype.getName();
if (!GroovyPropertyUtils.isProperty(clazz, name, isStatic))
return;
final PsiMethod getter = GroovyPropertyUtils.findPropertyGetter(clazz, name, isStatic, true);
final PsiType returnType;
if (getter instanceof GrMethod) {
returnType = ((GrMethod) getter).getInferredReturnType();
} else if (getter instanceof GrAccessorMethod) {
returnType = ((GrAccessorMethod) getter).getInferredReturnType();
} else {
return;
}
if (!(returnType instanceof GrClosureType))
return;
final GrSignature signature = ((GrClosureType) returnType).getSignature();
signature.accept(new GrRecursiveSignatureVisitor() {
@Override
public void visitClosureSignature(GrClosureSignature signature) {
NextSignature: for (MethodSignature prototypeSignature : prototypeSignatures) {
final GrClosureParameter[] params = signature.getParameters();
final PsiType[] types = prototypeSignature.getParameterTypes();
if (types.length != params.length)
continue;
for (int i = 0; i < types.length; i++) {
if (!TypesUtil.isAssignableByMethodCallConversion(types[i], params[i].getType(), refactoredMethod.getParameterList())) {
continue NextSignature;
}
}
conflicts.putValue(getter, GroovyRefactoringBundle.message("refactored.method.will.cover.closure.property", name, RefactoringUIUtil.getDescription(getter.getContainingClass(), false)));
}
}
});
}
use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature in project intellij-community by JetBrains.
the class GdkMethodUtil method getTypeToMix.
@Nullable
private static Pair<GrSignature, String> getTypeToMix(GrAssignmentExpression assignment) {
GrExpression mixinRef = assignment.getRValue();
if (mixinRef == null)
return null;
final PsiType type = mixinRef.getType();
if (type instanceof GrClosureType) {
final GrSignature signature = ((GrClosureType) type).getSignature();
final GrExpression lValue = assignment.getLValue();
assert lValue instanceof GrReferenceExpression;
final String name = ((GrReferenceExpression) lValue).getReferenceName();
return Pair.create(signature, name);
}
return null;
}
Aggregations