context.parameterName = "jso";
sw.print(params[0].getType().getQualifiedSourceName());
sw.print(" ");
sw.print(context.parameterName);
JClassType bindingType = null;
if (params.length == 2) {
// Infer the binding type from the second parameter of the binding
// method.
bindingType = params[1].getType().isClassOrInterface();
context.objRef = "obj";
sw.print(", ");
sw.print(bindingType.getQualifiedSourceName());
sw.print(" ");
sw.print(context.objRef);
} else if (bindingAnnotation != null
&& bindingAnnotation.value().length() > 0) {
// Use the binding type specified in the the gwt.binding annotation.
bindingType = typeOracle.findType(bindingAnnotation.value());
if (bindingType == null) {
logger.log(TreeLogger.ERROR, "Could not resolve binding type "
+ bindingType, null);
throw new UnableToCompleteException();
}
}
sw.println(") {");
sw.indent();
for (Task t : context.tasks) {
if (t.imported != null) {
String fieldName = t.getFieldName(logger);
sw.print("assert JSONWrapperUtil.hasField(");
sw.print(context.parameterName);
sw.print(", \"");
sw.print(fieldName);
sw.print("\") : \"Backing JSO missing imported function ");
sw.print(fieldName);
sw.println("\";");
}
}
sw.print(binding.getName());
sw.print("Native (");
sw.print(context.parameterName);
if (params.length == 2) {
sw.print(",");
sw.print(context.objRef);
}
sw.println(");");
sw.outdent();
sw.println("}");
// Write the native half to perform the actual binding operations
sw.print("public native void ");
sw.print(binding.getName());
sw.print("Native (");
sw.print(params[0].getType().getQualifiedSourceName());
sw.print(" ");
sw.print(context.parameterName);
if (params.length == 2) {
sw.print(", ");
sw.print(bindingType.getQualifiedSourceName());
sw.print(" ");
sw.print(context.objRef);
}
sw.println(") /*-{");
sw.indent();