Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Is there a common syntax for a compile time "if" pointcut?

Hi,

I'm trying to write an aspect that will declare either a warning or error,
depending on the value of some constant. However, the "if" pointcut
designator cannot be used with declare warning/error because it evaluates
at run time. I need something at compile time.

What I want is to be able to configure an aspect that will declare a
warning, error or ignore some condition like calls to System.out.

First, I define a set of constants in a class:

      /** This constant defines whether a static aspect should generate an
error */
      public static final String CFG_ERROR = "ERROR";
      /** This constant defines whether a static aspect should generate a
warning */
      public static final String CFG_WARN = "WARNING";
      /** This constant defines whether a static aspect should be ignored
*/
      public static final String CFG_IGNORE = "IGNORE";

      /** This constant configures whether to generate an error, warning or
ignore */
      public static final String CFG_STATIC_TEST_XYZ = CFG_ERROR;

Now I want to write aspects like this:

      /** This pointcut determines if the static test condition is found */
      public pointcut staticTestXYZ() : <<some pointcut, like writing to
System.out>> ;

      /** Declare an warning if configured to do so */
      declare warning : staticTestXYZ() &&
            <<need compile time test for CFG_STATIC_TEST_XYZ=CFG_WARN>> :
                  "I'm warning you not to do XYZ";

      /** Declare an error if configured to do so */
      declare error : staticTestXYZ() &&
            <<need compile time test for CFG_STATIC_TEST_XYZ=CFG_ERROR>> :
                  "You are not permitted to do XYZ";


Is there a standard syntax for doing things like this?


Thanks,

Scott.
_______________________________________________________
Scott Hayward
Advisory IT Specialist
IBM Canada Ltd., Pacific Development Centre
4611 Canada Way, Burnaby, BC, V5G 4X3 CANADA
Dir (604) 297-3096            Fax (604) 297-3030      4 / PA1 / 4611 / BURN
email:  shayward@xxxxxxxxxx    Web: http://www.can.ibm.com/pdc



Back to the top