It is impossible to redefine advice. It is also impossible to advise an aspect's advice in order to modify an existing advice, at least not yet. The before-advice defined in SimpleTracing (Listing SimpleTracing.java) is frozen. Attempting to redefine the before-advice in a subaspect DoubleTracing (Listing DoubleTracing.java), for example,
(Listing DoubleTracing.java)
aspect DoubleTracing extends ExecutingObjectTracing { pointcut tracePoints(): execution(* *(..)); before(): !within(aspect..*) && tracePoints() { trace(thisJoinPoint); } }will (perhaps somewhat unexpectedly) result in the method tracebeing called twice for each join point. The two before-advice declarations in Listings SimpleTracing.java and DoubleTracing.java are identical, but in AspectJ they are considered unrelated and will be applied independently.
These examples indicate the sense in which aspects in AspectJ are not polymorphic. More can be learned by compiling the code with the -preprocess option. The abstract aspect SimpleTracingin Listing SimpleTracing.java is preprocessed into the abstract class SimpleTracing (Listing SimpleTracing.java). Note that the method is final. (Preprocessed SimpleTracing class)
abstract class SimpleTracing { public final void before0$ajc(JoinPoint thisJoinPoint) { this.trace(thisJoinPoint); } protected abstract void trace(JoinPoint jp); }
The concrete aspect PointTracing in Listing PointTracing.java is preprocessed into the concrete class PointTracing (Listing PointTracing.java). Note that this is a non-polymorphic implementation of a Singleton design pattern [12]. (Preprocessed PointTracing class)
public class PointTracing extends ExecutingObjectTracing { public static PointTracing aspectInstance; public static PointTracing aspectOf() { return PointTracing.aspectInstance; } static { PointTracing.aspectInstance = new PointTracing(); } }