I don't know if this is possible, but I am trying to write a pointcut which would match any method that returns an object implementing a specific interface.
Given the following:
public class User implements Auditable{
private int id;
private String name;
public String getName(){
return name;
}
}
and the interface Auditable:
public interface Auditable{
public String getName();
}
And some random class:
public class RandomClass{
public User getNewUser(){
User u = new User();
return u;
}
}
How can I write an "AfterReturning" pointcut that would catch any method called getNew* that implements Auditable?
The following works:
pointcut auditablePointcut(): call(public * *.getNew*(..))
however, that will match any returning type. The following does not work:
pointcut auditablePointcut(): call(public Auditable *.getNew*(..))
I presume I could write it using an if(), but that seems a little kludgy (I haven't tried it yet). Or is there a more elegant manner?
after () returning (Audible au) : call(public * *.getNew*(..))