private void createSetterMethod(final FieldInfo fieldInfo,
final JClass jClass, final boolean useJava50) {
JMethod method = null;
JSourceCode jsc = null;
XMLInfoNature xmlNature = new XMLInfoNature(fieldInfo);
String mname = fieldInfo.getMethodSuffix();
XSType xsType = xmlNature.getSchemaType();
JType jType = xsType.getJType();
//-- create set method
/*
* fieldInfo.getWriteMethodName() will either prefix the method
* with 'add' (for multivalued fields) or 'set'!
* @see FieldInfo#getWriteMethodeName()
*/
method = new JMethod(fieldInfo.getWriteMethodName());
jClass.addMethod(method);
String paramName = fieldInfo.getName();
//-- make parameter name pretty,
//-- simply for aesthetic beauty
if (paramName.indexOf('_') == 0) {
String tempName = paramName.substring(1);
if (_javaNaming.isValidJavaIdentifier(tempName)) {
paramName = tempName;
}
}
method.addParameter(new JParameter(jType, paramName));
// if (useJava50) {
// Java5HacksHelper.addOverrideAnnotations(method.getSignature()); // DAB Java 5.0 hack
// }
createSetterComment(fieldInfo, method.getJDocComment());
jsc = method.getSourceCode();
String fieldName = fieldInfo.getName();
//-- bound properties
if (fieldInfo.isBound()) {
// save old value
jsc.add("java.lang.Object old");
jsc.append(mname);
jsc.append(" = ");
//-- 'this.' ensures this refers to the class member not the parameter
jsc.append(xsType.createToJavaObjectCode("this." + fieldName));
jsc.append(";");
}
//-- set new value
jsc.add("this.");
jsc.append(fieldName);
jsc.append(" = ");
jsc.append(paramName);
jsc.append(";");
if (fieldInfo.getFieldInfoReference() != null) {
jsc.add("this.");
jsc.append(fieldInfo.getFieldInfoReference().getName());
jsc.append(" = ");
JType referencedJType = new XMLInfoNature(fieldInfo.getFieldInfoReference()).getSchemaType().getJType();
if (referencedJType.isPrimitive()) {
jsc.append(paramName);
} else if (jType.isPrimitive()) {
JPrimitiveType primitive = (JPrimitiveType) jType;
jsc.append("new ");