use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature in project intellij-community by JetBrains.
the class GrClosureSignatureUtil method generateAllSignaturesForMethod.
public static List<MethodSignature> generateAllSignaturesForMethod(GrMethod method, PsiSubstitutor substitutor) {
GrClosureSignature signature = createSignature(method, substitutor);
String name = method.getName();
PsiTypeParameter[] typeParameters = method.getTypeParameters();
final ArrayList<MethodSignature> result = new ArrayList<>();
generateAllMethodSignaturesByClosureSignature(name, signature, typeParameters, substitutor, result);
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature in project intellij-community by JetBrains.
the class GrClosureSignatureUtil method generateAllMethodSignaturesBySignature.
public static List<MethodSignature> generateAllMethodSignaturesBySignature(@NotNull final String name, @NotNull final GrSignature signature) {
final ArrayList<MethodSignature> result = new ArrayList<>();
signature.accept(new GrRecursiveSignatureVisitor() {
@Override
public void visitClosureSignature(GrClosureSignature signature) {
generateAllMethodSignaturesByClosureSignature(name, signature, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY, result);
}
});
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature in project intellij-community by JetBrains.
the class GrClosureSignatureUtil method mapArgumentsToParameters.
@Nullable
public static Map<GrExpression, Pair<PsiParameter, PsiType>> mapArgumentsToParameters(@NotNull GroovyResolveResult resolveResult, @NotNull PsiElement context, final boolean partial, final boolean eraseArgs, @NotNull final GrNamedArgument[] namedArgs, @NotNull final GrExpression[] expressionArgs, @NotNull GrClosableBlock[] closureArguments) {
final GrClosureSignature signature;
final PsiParameter[] parameters;
final PsiElement element = resolveResult.getElement();
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
if (element instanceof PsiMethod) {
signature = createSignature((PsiMethod) element, substitutor, eraseArgs);
parameters = ((PsiMethod) element).getParameterList().getParameters();
} else if (element instanceof GrClosableBlock) {
signature = eraseArgs ? createSignatureWithErasedParameterTypes((GrClosableBlock) element) : createSignature(((GrClosableBlock) element));
parameters = ((GrClosableBlock) element).getAllParameters();
} else {
return null;
}
final ArgInfo<PsiElement>[] argInfos = mapParametersToArguments(signature, namedArgs, expressionArgs, closureArguments, context, partial, eraseArgs);
if (argInfos == null) {
return null;
}
final HashMap<GrExpression, Pair<PsiParameter, PsiType>> result = new HashMap<>();
for (int i = 0; i < argInfos.length; i++) {
ArgInfo<PsiElement> info = argInfos[i];
if (info == null)
continue;
for (PsiElement arg : info.args) {
if (arg instanceof GrNamedArgument) {
arg = ((GrNamedArgument) arg).getExpression();
}
final GrExpression expression = (GrExpression) arg;
PsiType type = parameters[i].getType();
if (info.isMultiArg && type instanceof PsiArrayType) {
type = ((PsiArrayType) type).getComponentType();
}
result.put(expression, Pair.create(parameters[i], substitutor.substitute(type)));
}
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature in project intellij-community by JetBrains.
the class TypesUtil method getLeastUpperBound.
@Nullable
public static PsiType getLeastUpperBound(@NotNull PsiType type1, @NotNull PsiType type2, PsiManager manager) {
{
PsiType numericLUB = getNumericLUB(type1, type2);
if (numericLUB != null)
return numericLUB;
}
if (type1 instanceof GrTupleType && type2 instanceof GrTupleType) {
GrTupleType tuple1 = (GrTupleType) type1;
GrTupleType tuple2 = (GrTupleType) type2;
PsiType[] components1 = tuple1.getComponentTypes();
PsiType[] components2 = tuple2.getComponentTypes();
if (components1.length == 0)
return genNewListBy(type2, manager);
if (components2.length == 0)
return genNewListBy(type1, manager);
PsiType[] components3 = PsiType.createArray(Math.min(components1.length, components2.length));
for (int i = 0; i < components3.length; i++) {
PsiType c1 = components1[i];
PsiType c2 = components2[i];
if (c1 == null || c2 == null) {
components3[i] = null;
} else {
components3[i] = getLeastUpperBound(c1, c2, manager);
}
}
return new GrImmediateTupleType(components3, JavaPsiFacade.getInstance(manager.getProject()), tuple1.getScope().intersectWith(tuple2.getResolveScope()));
} else if (checkEmptyListAndList(type1, type2)) {
return genNewListBy(type2, manager);
} else if (checkEmptyListAndList(type2, type1)) {
return genNewListBy(type1, manager);
} else if (type1 instanceof GrMapType && type2 instanceof GrMapType) {
return GrMapType.merge(((GrMapType) type1), ((GrMapType) type2));
} else if (checkEmptyMapAndMap(type1, type2)) {
return genNewMapBy(type2, manager);
} else if (checkEmptyMapAndMap(type2, type1)) {
return genNewMapBy(type1, manager);
} else if (type1 instanceof GrClosureType && type2 instanceof GrClosureType) {
GrClosureType clType1 = (GrClosureType) type1;
GrClosureType clType2 = (GrClosureType) type2;
GrSignature signature1 = clType1.getSignature();
GrSignature signature2 = clType2.getSignature();
if (signature1 instanceof GrClosureSignature && signature2 instanceof GrClosureSignature) {
if (((GrClosureSignature) signature1).getParameterCount() == ((GrClosureSignature) signature2).getParameterCount()) {
final GrClosureSignature signature = GrImmediateClosureSignatureImpl.getLeastUpperBound(((GrClosureSignature) signature1), ((GrClosureSignature) signature2), manager);
if (signature != null) {
GlobalSearchScope scope = clType1.getResolveScope().intersectWith(clType2.getResolveScope());
final LanguageLevel languageLevel = ComparatorUtil.max(clType1.getLanguageLevel(), clType2.getLanguageLevel());
return GrClosureType.create(signature, scope, JavaPsiFacade.getInstance(manager.getProject()), languageLevel, true);
}
}
}
} else if (GroovyCommonClassNames.GROOVY_LANG_GSTRING.equals(getQualifiedName(type1)) && CommonClassNames.JAVA_LANG_STRING.equals(getQualifiedName(type2))) {
return type2;
} else if (GroovyCommonClassNames.GROOVY_LANG_GSTRING.equals(getQualifiedName(type2)) && CommonClassNames.JAVA_LANG_STRING.equals(getQualifiedName(type1))) {
return type1;
}
return GenericsUtil.getLeastUpperBound(type1, type2, manager);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature in project intellij-community by JetBrains.
the class PsiUtil method isRawClosureCall.
private static boolean isRawClosureCall(GrMethodCallExpression call, GroovyResolveResult result, GrClosureType returnType) {
final GrSignature signature = returnType.getSignature();
GrClosureSignature _signature;
if (signature instanceof GrClosureSignature) {
_signature = (GrClosureSignature) signature;
} else {
final PsiType[] types = getArgumentTypes(call.getInvokedExpression(), true);
final Trinity<GrClosureSignature, GrClosureSignatureUtil.ArgInfo<PsiType>[], GrClosureSignatureUtil.ApplicabilityResult> resultTrinity = types != null ? GrClosureSignatureUtil.getApplicableSignature(signature, types, call) : null;
_signature = resultTrinity != null ? resultTrinity.first : null;
}
if (_signature != null) {
return isRawType(_signature.getReturnType(), TypesUtil.composeSubstitutors(_signature.getSubstitutor(), result.getSubstitutor()));
}
return false;
}
Aggregations