I would annotate a Java method in order to run some code before the method body is executed and before the method returns to the caller. I read about code generation at compile time using Java annotation.
The signature of the method I would annotate is as in the following example.
public Output process(Input arg0) {
// ...
// body that creates output object as processing result of arg0
// ...
return output;
}
I would annotate the above method in order to log the input argument before the method body is executed and to log the output data before the method returns to the caller.
I hypothesized an annotation like the following one.
@Log(input = "arg0", inputDest = "log1.txt", outputDest = "log2.txt")
The above annotation should generate (at compile time) some code like the following.
public Output process(Input arg0) {
SampleLogger.log(arg0, "log1.txt"); // <-- generated code
// ...
// body that creates Output object as processing result of arg0
// ...
SampleLogger.log(output, "log2.txt"); // <-- generated code
return output;
}
How to achieve this?