Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ajdt-dev] Need help with an advice


Marco,

I think you need around call advice:

public aspect MyAspect {

        pointcut myMethod() :
        execution (* myMethod(..));
   
    pointcut retrieveCollection() :
        call (* com.Bean2.getItems(..))
          && within(MyBeanX);


   
    Object around() : retrieveCollection() {
        System.err.println("There you go.. intercepted as we were expecting..");
        return proceed();
    }
 
}

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/

Please respond to AspectJ Development Tools developer discussions <ajdt-dev@xxxxxxxxxxx>

Sent by:        ajdt-dev-bounces@xxxxxxxxxxx

To:        "AspectJ Development Tools developer discussions" <ajdt-dev@xxxxxxxxxxx>
cc:        
Subject:        [ajdt-dev] Need help with an advice


hello all,
i have to modify an existing code to respect some new business rules..
Although i have access to the existing code, i prefer to implement this functionality wiht an aspect (i hate
those if..else etc that just clutter my code..)

i have following situation though (this is just an excerpt, i need to do similar functionality
further later in same method

public class MyBeanX {
   ....

    private void myMethod(String args) {

       Collection items = bean2.getItems(..)
    }
    .....
}


what i need to do is to replace that   Collection items = bean2.getItems() with a different call that does something else (but
still return a collection)


i have thought to crete somethinglike this...

public aspect MyAspect {

pointcut myMethod() :
       execution (* com.BeanXmy.myMethod(..));
   
   pointcut retrieveCollection() :
       execution (* com.Bean2.getItems(..))
         && within(MyAspect);


   
   void around() : retrieveCollection() {
       System.err.println("There you go.. intercepted as we were expecting..");
   }



looking from cross-references in aspectJ,looks like  something is wrong since the around() advice does not intercept any methods...

can anyone tell me where my aspect code is wrong?

thanks and regards
marco

_______________________________________________
ajdt-dev mailing list
ajdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ajdt-dev


Back to the top