I have a an annotation style aspect which is something like that:
//....
//somewhere in another class
//
@MyAnnotation
public void foo(){ \* does stuff *\}
/////////////////////
// in the aspect file
@Aspect("percflow(execution(@com.bla.MyAnnotation * *(..)))")
public class MyAspect {
public MyAspect(){
/* Here I'd like to access the name of the annotated function e.g: foo*/
}
/* more pointcuts and advice*/
}
I've tried capturing the object with this(Object)
but this didn't do any good.
I've also tried introducing a parameter to the constructor but that just caused an error.
Well, it is actually not necessary to do anything in the constructor. You can just declare the pointcut within
percflow()
as a stand-alone object and use it withinpercflow()
as well as in a@Before
advice which, as the instantiation model implies, will only be executed once and gives you all necessary information via the correspondingJoinPoint
object. You can now log or store the information as you fancy.BTW, idea of using a constructor is not so nice because within the constructor the aspect instance is not initialised yet (hen vs. egg problem) and will cause exceptions when trying to access it.
Console output: