context = new FragmentGeneratorContext(context);
context.parentLogger = logger;
SourceWriter sw = context.sw;
TypeOracle typeOracle = context.typeOracle;
Binding bindingAnnotation = JSWrapperGenerator.hasTag(logger, binding,
Binding.class);
// Write the java half to add assertions to the code. These will be elided
// in web mode, and the method become a pure delegation, allowing it to
// be removed completely
sw.print("public void ");
sw.print(binding.getName());
sw.print("(");
JParameter[] params = binding.getParameters();
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();
}