Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Concretize abstract pointcut with subtypes

Charles Zhang writes:
 > Hi, I wonder if this is intended or just wrongful usage:
 > class A implements some reusable functionality.
 > class B extends class A with some specific functionality.
 > My aspect defines an abstract pointcut:
 > abstract pointcut(A a);
 > which is concretized in a sub-aspect as follows:
 > pointcut(B b):call(* B.*(..))&&target(b);
 > 
 > The purpose is to reuse some of the advices involving the abstract
 > pointcut in the abstract aspect in concrete scenarios.
 > 
 > This is flagged as a compiler error.

How about this?  (untested)

 pointcut foo(A a): call(* B.*(..)) && target(B) && target(a);

This will make sure that the target is an instance of B, but you'll
have to cast down from A in the advice body.  Actually, I guess the
"target(B)" part is redundant in this case, since you have B as the
qualifying type in the call signature, but in the general case I think
this is what you'd need to do the right dynamic type testing while
also conforming to the pointcut signature.

--dougo@xxxxxxxxx


Back to the top