Modify the value of an expression (method call/field access/new object creation).
When modifying the value (return value) of a method call, the target method must return a value and not be void.
Field values can be modified with field gets (
GETFIELD/
GETSTATIC) and field sets (
PUTFIELD/
PUTSTATIC).
New object creations can be modified with the
NEW target.
The transformer method must have the modified value type as the only parameter and return type.
If the transformer target method is static, the transformer method must be static as well.
Modify the return value of a method call:
@CModifyExpressionValue(method = "print", target = @CTarget(value = "INVOKE", target = "Ljava/lang/Object;toString()Ljava/lang/String;"))
public String modifyValue(String value) {
return value.toUpperCase();
}
Modify the value of a field access:
@CModifyExpressionValue(method = "print", target = @CTarget(value = "GETFIELD", target = "Ljava/lang/Integer;MAX_VALUE:I"))
public int modifyValue(int value) {
return Integer.MIN_VALUE;
}
Modify the value of a new object creation:
@CModifyExpressionValue(method = "print", target = @CTarget(value = "NEW", target = "java/lang/String"))
public String modifyValue(String value) {
return value.toUpperCase();
}