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().

2 Responses to “AOP: Compile-Time Checks”
Thx for your aop introduction simon - aop seems to be a great opportunity… I want to see more .. =)… Where is the next bookstore?!
Well, just ’round the corner.
I don’t know if I suggested a good AOP book somewhere in my entries. But I’d suggest you to buy AspectJ in Action from Ramnivas Laddad.