@Override
public void parse(Element element, Function<TypeElement, Type> storage) {
final TypeElement typeElement = (TypeElement) element.getEnclosingElement();
final ExecutableElement method = (ExecutableElement) element;
final Functor annotation = method.getAnnotation(Functor.class);
final String defaultName = method.getSimpleName().toString();
final ClosureName delegate = new ClosureName(defaultName);
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) {