Search code examples
javaaopaspectj

AspectJ pointcut to intercept a class


Guys I need a point cut that filter me the called function by a specific class.

public aspect intLogin {
    private capture c = new capture();
    pointcut login() : execution(public * login(..)) 
    before ():login(){
        c.print();
    }
}

This is my aspect, I want to know which class call login function. Can you help me?


Solution

  • I solved the problem using thisJoinPoint.getSourceLocation(). The code is:

    public aspect intLogin {
      private capture c = new capture();
      pointcut login(Object a) : call(public * login(..)) && (target(a)) && this(capture);
      before (Object x):login( spring.aop.so_52992365.intLogin) {
        String xString = x.toString();
        System.out.println("The class that is calling the function is:" + thisJoinPoint.getSourceLocation());
        c.print();
      }
    }