op.addField(fieldName, propertyType);
String managerField = op.addInjectedField("_$applicationStateManager",
ApplicationStateManager.class, _applicationStateManager);
BodyBuilder builder = new BodyBuilder();
// Accessor
builder.begin();
builder.addln("if ({0} == null)", fieldName);
builder.addln(" {0} = ({1}) {2}.get(\"{3}\");", new Object[] {
fieldName, ClassFabUtils.getJavaClassName(propertyType),
managerField, objectName });
builder.addln("return {0};", fieldName);
builder.end();
String methodName = op.getAccessorMethodName(propertyName);
MethodSignature sig = new MethodSignature(propertyType, methodName,
null, null);
op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location);
// Mutator
builder.clear();
builder.begin();
builder.addln("{0}.store(\"{1}\", $1);", managerField, objectName);
builder.addln("{0} = $1;", fieldName);
builder.end();
sig = new MethodSignature(void.class, EnhanceUtils
.createMutatorMethodName(propertyName),
new Class[] { propertyType }, null);
op.addMethod(Modifier.PUBLIC, sig, builder.toString(), location);
// Extend pageDetached() to clean out the cached field value.
op.extendMethodImplementation(PageDetachListener.class,
EnhanceUtils.PAGE_DETACHED_SIGNATURE, fieldName + " = null;");