[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Re: thisJoinPoint.getThis() documentation



Are you using a "call()" join point? In which case "this" will always be
null in a static method. Perhaps you should be using "getTarget()" e.g.

public class Main {

      public void test () {
            System.out.println("? test()");
      }

      public void instanceMethod () {
            test();
      }

      public static void main(String[] args) {
            Main main = new Main();
            main.instanceMethod();
            main.test();
      }
}

public aspect Logging {

      pointcut callTest() :
            call(* test());

      before () : callTest () {
            System.out.println("? Logging.callTest() this=" + thisJoinPoint.getThis() + " target=" + thisJoinPoint.getTarget());
      }
}

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/