sw.print(subContext.objRef);
sw.print(" = ");
Constructor constructorAnnotation = hasTag(logger, constructor,
Constructor.class);
Global globalAnnotation = hasTag(logger, constructor, Global.class);
if (constructorAnnotation != null) {
// If the imported method is acting as an invocation of a JavaScript
// constructor, use the new Foo() syntax, otherwise treat is an an
// invocation on a field on the underlying JSO.
sw.print("new ");
sw.print(constructorAnnotation.value());
// Write the invocation's parameter list
sw.print("(");
for (int i = 0; i < parameters.length; i++) {
// Create a sub-context to generate the wrap/unwrap logic
JType subType = parameters[i].getType();
FragmentGeneratorContext subParams = new FragmentGeneratorContext(
context);
subParams.returnType = subType;
subParams.parameterName = parameters[i].getName();
FragmentGenerator fragmentGenerator = context.fragmentGeneratorOracle.findFragmentGenerator(
logger, context.typeOracle, subType);
if (fragmentGenerator == null) {
logger.log(TreeLogger.ERROR, "No fragment generator for "
+ returnType.getQualifiedSourceName(), null);
throw new UnableToCompleteException();
}
fragmentGenerator.toJS(subParams);
if (i < parameters.length - 1) {
sw.print(", ");
}
}
sw.print(")");
} else if (globalAnnotation != null) {
sw.print(globalAnnotation.value());
} else {
logger.log(TreeLogger.ERROR,
"Writing a constructor, but no constructor-appropriate annotations",
null);