Statement code = setter.getCode();
VariableExpression oldValue = new VariableExpression("$oldValue");
VariableExpression newValue = new VariableExpression("$newValue");
VariableExpression proposedValue = new VariableExpression(setter.getParameters()[0].getName());
BlockStatement block = new BlockStatement();
// create a local variable to hold the old value from the getter
block.addStatement(new ExpressionStatement(
new DeclarationExpression(oldValue,
Token.newSymbol(Types.EQUALS, 0, 0),
new MethodCallExpression(VariableExpression.THIS_EXPRESSION, getterName, ArgumentListExpression.EMPTY_ARGUMENTS))));
// add the fireVetoableChange method call
block.addStatement(new ExpressionStatement(new MethodCallExpression(
VariableExpression.THIS_EXPRESSION,
"fireVetoableChange",
new ArgumentListExpression(
new Expression[]{
new ConstantExpression(propertyName),
oldValue,
proposedValue}))));
// call the existing block, which will presumably set the value properly
block.addStatement(code);
if (bindable) {
// get the new value to emit in the event
block.addStatement(new ExpressionStatement(
new DeclarationExpression(newValue,
Token.newSymbol(Types.EQUALS, 0, 0),
new MethodCallExpression(VariableExpression.THIS_EXPRESSION, getterName, ArgumentListExpression.EMPTY_ARGUMENTS))));
// add the firePropertyChange method call
block.addStatement(new ExpressionStatement(new MethodCallExpression(
VariableExpression.THIS_EXPRESSION,
"firePropertyChange",
new ArgumentListExpression(
new Expression[]{
new ConstantExpression(propertyName),