assert !exposedType.isPrimitive() && !implType.isPrimitive();
createField();
MethodWriter writer = context.createMethodWriter();
NameConverter nc = context.parent().getModel().getNameConverter();
// [RESULT]
// Type getXXX() {
// #ifdef default value
// if(value==null)
// return defaultValue;
// #endif
// return value;
// }
JExpression defaultValue = null;
if(prop.defaultValue!=null)
defaultValue = prop.defaultValue.compute(outline.parent());
// if Type is a wrapper and we have a default value,
// we can use the primitive type.
JType getterType;
if(defaultValue!=null || forcePrimitiveAccess)
getterType = exposedType.unboxify();
else
getterType = exposedType;
JMethod $get = writer.declareMethod( getterType,getGetterMethod() );
String javadoc = prop.javadoc;
if(javadoc.length()==0)
javadoc = Messages.DEFAULT_GETTER_JAVADOC.format(nc.toVariableName(prop.getName(true)));
writer.javadoc().append(javadoc);
if(defaultValue==null) {
$get.body()._return(ref());
} else {
JConditional cond = $get.body()._if(ref().eq(JExpr._null()));
cond._then()._return(defaultValue);
cond._else()._return(ref());
}
List<Object> possibleTypes = listPossibleTypes(prop);
writer.javadoc().addReturn()
.append("possible object is\n")
.append(possibleTypes);
// [RESULT]
// void setXXX(Type newVal) {
// this.value = newVal;
// }
JMethod $set = writer.declareMethod( codeModel.VOID, "set"+prop.getName(true) );
JType setterType = exposedType;
if(forcePrimitiveAccess) setterType = setterType.unboxify();
JVar $value = writer.addParameter( setterType, "value" );
JBlock body = $set.body();
body.assign(JExpr._this().ref(ref()),castToImplType($value));
// setter always get the default javadoc. See issue #381
writer.javadoc().append(Messages.DEFAULT_SETTER_JAVADOC.format(nc.toVariableName(prop.getName(true))));
writer.javadoc().addParam($value)
.append("allowed object is\n")
.append(possibleTypes);
}