// Foo createFoo( T1 a, T2 b, T3 c, ... ) throws JAXBException {
// return new FooImpl(a,b,c,...);
// }
JMethod m = objectFactory.method( JMod.PUBLIC,
cc.ref, "create" + cc.target.getSqueezedName() );
JInvocation inv = JExpr._new(cc.implRef);
m.body()._return(inv);
// let's not throw this exception.
// m._throws(codeModel.ref(JAXBException.class));
// add some jdoc to avoid javadoc warnings in jdk1.4
m.javadoc()
.append( "Create an instance of " )
.append( cc.ref )
.addThrows(JAXBException.class).append("if an error occurs");
// constructor
// [RESULT]
// FooImpl( T1 a, T2 b, T3 c, ... ) {
// }
JMethod c = cc.implClass.constructor(JMod.PUBLIC);
for( String fieldName : cons.fields ) {
CPropertyInfo field = cc.target.getProperty(fieldName);
if(field==null) {
outline.getErrorReceiver().error(cc.target.getLocator(),
Messages.ILLEGAL_CONSTRUCTOR_PARAM.format(fieldName));
continue;
}
fieldName = camelize(fieldName);
FieldOutline fo = outline.getField(field);
FieldAccessor accessor = fo.create(JExpr._this());
// declare a parameter on this factory method and set
// it to the field
inv.arg(m.param( fo.getRawType(), fieldName ));
JVar $var = c.param( fo.getRawType(), fieldName );
accessor.fromRawValue(c.body(),'_'+fieldName,$var);
}
}