Declare Annotation

AspectJ 1.5 supports a new kind of declare statement, declare annotation. The general form of a declare annotation statement is:

  	declare annotation : 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.

declare annotation : org.xyz.model..* : @BusinessDomain ;

All types defined in a package with the prefix org.xyz.model have the @BusinessDomain annotation.

declare annotation : public * BankAccount+.*(..) : @Secured(role="supervisor")

All public methods in BankAccount and its subtypes have the annotation @Secured(role="supervisor").

declare annotation : * DAO+.* : @Persisted;

All fields defined in DAO or its subtypes have the @Persisted annotation.