A cool mechanism AspectJ offers is to declare compile-time errors and warnings. You can use this mechanism to ensure that certain rules specified in a specification don’t get broken. For example Swing’s single-thread rule. You declare errors using the following syntax:
-
declare error : <pointcut> : <message>;
and warings using a similar one:
-
declare warning : <pointcut> : <message>;
Errors as well as warnings will be issued when the compiler detects a join point matching a given pointcut. Errors would abort the compilation process, while warnings would just be displayed.
Example:
-
declare error : callToHiddenCode() : "You are not allowed to call this code.";
This would produce an error if you’d call a join point captured by the pointcut callToHiddenCode().
