public abstract aspect Base<T> {
pointcut matchGetA() :
call(T *.*(..));
T around() : matchGetA() {
T result = proceed();
...
return result;
}
static aspect BaseA extends Base<A> {};
static aspect BaseB extends Base<B> {};
static aspect BaseC extends Base<C> {};
}
where B and C derive from A.
Adam
> Hi all,
>
> This is probably a beginner question.
> In the following code snippet I would like to
> catch all calls to methods that return an instance of class A
> and all derived classes, do some operations on the object
> and return it back.
>
> @Pointcut("call(A+ *.*(..))")
> void matchGetA() {};
>
> @Around("matchGetA()")
> public A processA(ProceedingJoinPoint thisJoinPoint) {
> try {
> A result = (A)thisJoinPoint.proceed();
> ...
> return result;
> } catch (Throwable e) {
> throw new Exception(e);
> }
> }
>
> This snippet does not compile when I have a method
> public B getB() {}
> and B is derived from A.
>
> The only option I can think of is to set the return type of processA () advice to Object.
> Does a better (more type save) method exist to build this kind of advices.
>
> Thanks,
> Adam