Introduction

Java is an object-oriented programming language developed by Sun Microsystems that has proven itself in numerous projects. The Java Platform is hardware and operating system independent and comes in three editions: Micro Edition for PDAs and cell phones; Standard Edition for computer programs; and Enterprise Edition for distributed, transactional, and portable applications.

Monday, May 10th, 2004 at 3:17 pm

AOP: Compile-Time Checks

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:

  1. declare error : <pointcut> : <message>;

and warings using a similar one:

  1. 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:

  1. 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”

  1. ripcurlx

    Thx for your aop introduction simon - aop seems to be a great opportunity… I want to see more .. =)… Where is the next bookstore?! ;-)

  2. Simon Wacker

    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.