final ClosureName name = new ClosureName(annotation.name().isEmpty() ? defaultName : annotation.name());
final List<? extends VariableElement> parameters = method.getParameters();
final boolean isStatic = method.getModifiers().contains(Modifier.STATIC);
final Argument input;
if (isStatic) {
input = findInput(parameters);
} else {
input = new Argument(box(typeElement.asType()), "input");
}
final ClosureBuilder builder;
TypeMirror returnType = method.getReturnType();
if (returnType.getKind() == TypeKind.BOOLEAN) {
builder = new ClosureBuilder(input, delegate);
} else {
builder = new ClosureBuilder(input, delegate, new Name(box(returnType).toString()));
}
builder.withName(name);
builder.withStatic(isStatic);
builder.withGraceful(annotation.graceful());
builder.withNullTo(annotation.nullTo());
if (isStatic) {
builder.withDelegate(typeElement.getSimpleName().toString());
for (VariableElement parameter : parameters) {
final boolean isInput = parameter.getAnnotation(Input.class) != null;
final boolean isOnlyParameter = parameters.size() == 1;
builder.withArgument(new Argument(box(parameter.asType()), parameter, isInput || isOnlyParameter));
}
} else {
for (VariableElement parameter : parameters) {
builder.withArgument(new Argument(box(parameter.asType()), parameter));
}
}
final Closure closure = builder.build();