AspectJ 5 supports a new kind of declare statement, declare annotation.
This takes different forms according to the recipient of the annotation:
declare @type for types, declare @method for methods,
declare @constructor for constructors, and declare @field
for fields. declare @package may be supported in a future release.
The general form is:
declare @<kind> : ElementPattern : Annotation ;
Where annotation is a regular annotation expression as defined in the Java 5 language. If the annotation has
the @Target meta-annotation, then the elements matched by ElementPattern
must be of the kind specified by the @Target annotation.
ElementPattern is defined as follows:
ElementPattern := TypePattern | MethodPattern | ConstructorPattern | FieldPattern
The following examples illustrate the use of declare annotation.
All types defined in a package with the prefix org.xyz.model
have the @BusinessDomain annotation.
All public methods in BankAccount and its subtypes have the
annotation @Secured(role="supervisor").
All constructors in BankAccount and its subtypes have the
annotation @Secured(role="supervisor").
All fields defined in DAO or its subtypes have the
@Persisted annotation.