use of org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrRecursiveSignatureVisitor 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.GrRecursiveSignatureVisitor 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.GrRecursiveSignatureVisitor 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.GrRecursiveSignatureVisitor in project intellij-community by JetBrains.
the class GrClosureSignatureUtil method getSignatureApplicabilities.
private static List<Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult>> getSignatureApplicabilities(@NotNull GrSignature signature, @NotNull final PsiType[] args, @NotNull final PsiElement context) {
final List<Trinity<GrClosureSignature, ArgInfo<PsiType>[], ApplicabilityResult>> results = new ArrayList<>();
signature.accept(new GrRecursiveSignatureVisitor() {
@Override
public void visitClosureSignature(GrClosureSignature signature) {
ArgInfo<PsiType>[] map = mapArgTypesToParameters(signature, args, context, false);
if (map != null) {
results.add(new Trinity<>(signature, map, isSignatureApplicableInner(map, signature)));
return;
}
// check for the case foo([1, 2, 3]) if foo(int, int, int)
if (args.length == 1 && PsiUtil.isInMethodCallContext(context)) {
final GrClosureParameter[] parameters = signature.getParameters();
if (parameters.length == 1 && parameters[0].getType() instanceof PsiArrayType) {
return;
}
PsiType arg = args[0];
if (arg instanceof GrTupleType) {
PsiType[] _args = ((GrTupleType) arg).getComponentTypes();
map = mapArgTypesToParameters(signature, _args, context, false);
if (map != null) {
results.add(new Trinity<>(signature, map, isSignatureApplicableInner(map, signature)));
}
}
}
}
});
return results;
}
Aggregations