I know that I can retrieve the arguments sent to a method, but how could I get objects defined in that method? For example, this is my class:
public class Sample {
public static void sendMessage(String message) {
String x = "string x";
System.out.println(message);
}
public static void main(String[] args) {
sendMessage("my message");
}
}
And this is my aspect:
public aspect SampleAspect {
pointcut printMessage(String m) : call(void Sample.sendMessage(..)) && args(m);
before(String m) : printMessage(m) {
System.out.println("Before sending: " + m);
}
after(String m) : printMessage(m) {
System.out.println("After sending: " + m);
}
}
The outputs consist of the argument, because I wrote && args(m)
.
How could I get the another string, x, from sendMessage?