Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Re: Why is 'if' pointcut restricted to static members of aspect?



An "if()" poincut can only make references to static fields and methods
because it executes outside the context of an aspect instance. However you
can always use the "aspectOf()" method:

public aspect Aspect {

      pointcut testIf () :
            execution(* main(..)) && if(Aspect.aspectOf().isEnabled());

      before () : testIf () {
            System.err.println(thisJoinPointStaticPart);
      }

      private boolean enabled = true;

      public boolean isEnabled () {
            return enabled;
      }
}

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/



Back to the top