I am very new to AspectJ...just started to learn.
Till now i am able to get the parameters of user defined method in my aspect and print the captured parameter in my pointcut.
Curiously i started to think to print the contents of System.out.println()
in my pointcut's advice and written the following simple code:
HelloClass.java:
public class HelloClass
{
public static void main(String a[])
{
System.out.println("hello sachin");
}
}
HelloAspect.java:
public aspect HelloAspect
{
pointcut callPointcut(String message ) :call(void java.lang.System.out.println(String))&& args(message);
before( String message) : callPointcut(message )
{
System.out.println("Fetced in point cut:"+message);
//System.out.println("In the advice attached to the call pointcut");
}
}
Then i compiled both the files using ajc HelloClass.java HelloAspect.java
It compiled successfully with one worning as follows:
and when i run program using java HelloClass
it Outputs as: Hello sachin
where it should be as Fetced in point cut:Hello sachin
.
So can anyone point out where i am going wrong or missing something . .Thank you in advance . .