Since pointcut expressions in AspectJ 1.5 support join point matching based on annotations, this facility can be exploited when writing declare warning and declare error statements. For example:
declare warning : withincode(@PerformanceCritical * *(..)) && call(@ExpensiveOperation * *(..)) : "Expensive operation called from within performance critical section";
declare error : call(* (@DataLayer org.xyz..)*.*(..)) && within((@UI org.xyz..)*) : "User interface should not call the data layer directly";
The general form of a declare parents statement is:
declare parents : TypePattern extends Type; declare parents : TypePattern implements TypeList;
Since AspectJ 1.5 supports annotations as part of a type pattern specification, it is now possible to match types based on the presence of annotations with either class-file or runtime retention. For example:
All types with the @Secured annotation implement the SecuredObject inteface.
The subset of types drawn from the BankAccount type and any subtype of BankAccount, where the @SecuredAnnotation is present, implement the SecuredObject interface.
Every type in an @Secured package implements the SecuredObject interface.