use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature in project intellij-community by JetBrains.
the class GrClosureType method create.
public static GrClosureType create(GroovyResolveResult[] results, GroovyPsiElement context) {
List<GrClosureSignature> signatures = new ArrayList<>();
for (GroovyResolveResult result : results) {
if (result.getElement() instanceof PsiMethod) {
signatures.add(GrClosureSignatureUtil.createSignature((PsiMethod) result.getElement(), result.getSubstitutor()));
}
}
final GlobalSearchScope resolveScope = context.getResolveScope();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(context.getProject());
if (signatures.size() == 1) {
return create(signatures.get(0), resolveScope, facade, LanguageLevel.JDK_1_5, true);
} else {
return create(GrClosureSignatureUtil.createMultiSignature(signatures.toArray(new GrClosureSignature[signatures.size()])), resolveScope, facade, LanguageLevel.JDK_1_5, true);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature in project intellij-community by JetBrains.
the class GrClosureType method create.
public static GrClosureType create(@NotNull GrClosableBlock closure, boolean shouldInferTypeParameters) {
final GrClosureSignature signature = GrClosureSignatureUtil.createSignature(closure);
final GlobalSearchScope resolveScope = closure.getResolveScope();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(closure.getProject());
return create(signature, resolveScope, facade, LanguageLevel.JDK_1_5, shouldInferTypeParameters);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature in project intellij-community by JetBrains.
the class ArgumentInstruction method inferMixinType.
@Override
@Nullable
public PsiType inferMixinType() {
PsiElement element = getElement();
assert element != null;
GrCall call = findCall(element);
GrExpression[] arguments = call.getExpressionArguments();
boolean hasNamed = PsiImplUtil.hasNamedArguments(call.getArgumentList());
int index = ArrayUtil.indexOf(arguments, element) + (hasNamed ? 1 : 0);
GroovyResolveResult[] variants = call.getCallVariants((GrReferenceExpression) element);
PsiType result = null;
for (GroovyResolveResult variant : variants) {
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(variant);
if (signature == null)
continue;
if (GrClosureSignatureUtil.mapParametersToArguments(signature, call) != null && !haveNullParameters(call)) {
return null;
}
GrClosureParameter[] parameters = signature.getParameters();
if (index >= parameters.length)
continue;
result = TypesUtil.getLeastUpperBoundNullable(result, parameters[index].getType(), element.getManager());
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature in project intellij-community by JetBrains.
the class GrClosureSignatureUtil method generateSimpleSignatures.
public static List<GrClosureSignature> generateSimpleSignatures(@NotNull GrSignature signature) {
final List<GrClosureSignature> result = new ArrayList<>();
signature.accept(new GrRecursiveSignatureVisitor() {
@Override
public void visitClosureSignature(GrClosureSignature signature) {
final GrClosureParameter[] original = signature.getParameters();
final ArrayList<GrClosureParameter> parameters = new ArrayList<>(original.length);
for (GrClosureParameter parameter : original) {
parameters.add(new GrDelegatingClosureParameter(parameter) {
@Override
public boolean isOptional() {
return false;
}
@Nullable
@Override
public GrExpression getDefaultInitializer() {
return null;
}
});
}
final int pcount = signature.isVarargs() ? signature.getParameterCount() - 2 : signature.getParameterCount() - 1;
for (int i = pcount; i >= 0; i--) {
if (original[i].isOptional()) {
result.add(new GrImmediateClosureSignatureImpl(parameters.toArray(new GrClosureParameter[parameters.size()]), signature.getReturnType(), signature.isVarargs(), false));
parameters.remove(i);
}
}
result.add(new GrImmediateClosureSignatureImpl(parameters.toArray(new GrClosureParameter[parameters.size()]), signature.getReturnType(), signature.isVarargs(), false));
}
});
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature in project intellij-community by JetBrains.
the class GrClosureSignatureUtil method createSignature.
@Nullable
public static GrClosureSignature createSignature(GrCall call) {
if (call instanceof GrMethodCall) {
final GrExpression invokedExpression = ((GrMethodCall) call).getInvokedExpression();
final PsiType type = invokedExpression.getType();
if (type instanceof GrClosureType) {
final GrSignature signature = ((GrClosureType) type).getSignature();
final Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult> trinity = getApplicableSignature(signature, PsiUtil.getArgumentTypes(invokedExpression, true), call);
if (trinity != null) {
return trinity.first;
}
return null;
}
}
final GroovyResolveResult resolveResult = call.advancedResolve();
final PsiElement element = resolveResult.getElement();
if (element instanceof PsiMethod) {
return createSignature((PsiMethod) element, resolveResult.getSubstitutor());
}
return null;
}
Aggregations