[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Re: [NEWSDELIVER] Newbie set() pointcut question


Dave,

The clue is in the message. I assume "anInt" is an instance field. You have not provided a DlwDataObject instance reference. The advice where you refer to the field executes in the context of the aspect i.e. "this" is of type WatchAnIntAspect. I have made come changes to your example. You may want to use aspectj-users in future.

public aspect WatchAnIntAspect
{

     pointcut getAnInt() :
         get ( int com.ibm.wbpte.dlwester.aspects.DlwDataObject.anInt ) ;

     pointcut setAnInt( int newInt ) :
         set ( int com.ibm.wbpte.dlwester.aspects.DlwDataObject.anInt )
                 && args ( newInt ) ;

     before (com.ibm.wbpte.dlwester.aspects.DlwDataObject ddo, int newInt ) :
             set ( int com.ibm.wbpte.dlwester.aspects.DlwDataObject.anInt )
             && args ( newInt ) && target(ddo)
     {
         System.out.println( "setAnInt: Old value of anInt = "
            + ddo.anInt ) ;
         System.out.println( "          New value of anInt = "
                 + newInt ) ;
     }
}

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/

To:        undisclosed-recipients:;
cc:        
Subject:        [NEWSDELIVER] Newbie set() pointcut question



I'm getting an error on the following aspect, and I'm not sure why. I'm
using AspectJ 1.2 and AJDT 1.1.4 on IBM WSAD 5.1.x:

public aspect WatchAnIntAspect
{

    pointcut getAnInt() :
        get ( int com.ibm.wbpte.dlwester.aspects.DlwDataObject.anInt ) ;

    pointcut setAnInt( int newInt ) :
        set ( int com.ibm.wbpte.dlwester.aspects.DlwDataObject.anInt )
                && args ( newInt ) ;

    before ( int newInt ) :
            set ( int com.ibm.wbpte.dlwester.aspects.DlwDataObject.anInt )
            && args ( newInt )
    {
        System.out.println( "setAnInt: Old value of anInt = "
>>>>>           + com.ibm.wbpte.dlwester.aspects.DlwDataObject.anInt ) ;
        System.out.println( "          New value of anInt = "
                + newInt ) ;
    }


On the line indicated with ">>>>>", I am getting the following error:
Cannot make a static reference to the non-static field
com.ibm.wbpte.dlwester.aspects.DlwDataObject.anInt

Can anyone tell me what I am doing wrong? How do I access the contents
of a member variable of an object?

Thanks!
DLW