}
private void generateInterface(final Class<?> type) {
checkType(type);
final Method[] methods = getMethods(type);
final MethodMapper methodMapper = methodMapperFactory.create(type);
generateType(type, new TypeGenerator() {
void generateInterface(final String name, final boolean proxy) {
tabsln("export interface %s {", name + (proxy ? "_PROXY" : ""));
inc();
for (final Method method : methods) {
tabs("%s(", method.getName());
int param = 0; // $todo: use Parameter.getName() in Java 8
for (final Type paramType : method.getGenericParameterTypes()) {
if (param != 0) {
print(", ");
}
print("param%s: %s", param++, type(paramType));
}
print("): ");
if (methodMapper.mapMethod(method).oneWay) {
print("void");
} else {
final String type = type(method.getGenericReturnType());
if (proxy) {
print("yass.Promise<%s>", type);
} else {
print(type);
}
}
println(";");
}
dec();
tabsln("}");
}
@Override public void generateType(final String name) {
generateInterface(name, false);
generateInterface(name, true);
tabs("export var %s_MAPPER = new yass.MethodMapper<%s>(", name, name);
inc();
boolean first = true;
for (final Method method : methods) {
if (!first) {
print(",");
}
first = false;
println();
final MethodMapper.Mapping mapping = methodMapper.mapMethod(method);
tabs("new yass.MethodMapping('%s', %s, %s)", mapping.method.getName(), mapping.id, mapping.oneWay);
}
println();
dec();
tabsln(");");