Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] identifying a call within a method and harves t the parameter

Title: RE: [aspectj-users] identifying a call within a method and harvest the parameter

I think this is a case for the wormhole pattern (from Ramnivas' great book AspectJ in Action). I am guessing the reason what you have doesn't match is because you want the args(_param) to match the withincode, but it is being applied to the call(createValue) which has no args. AFAIK, you cannot pick up args using withincode.

(I haven't tried this, YMMV but I think it should be close to what you want.) 

pointcut processingParam(Parameter _param):
        execution (public Result Processor.process(_param));
pointcut creatingValueWhileProcessing:
        call(public Value Processor.createValue()) &&
        withincode(public Result Processor.process(Parameter));
pointcut wormhole(Parameter _param): cflow(processingParam(_param)) &&
        creatingValueWhileProcessing();

Value around(Parameter _param): wormhole(Parameter) {
// advice code here
}

Check out Ramnivas' book www.manning.com/laddad for more on the wormhole pattern.
Elizabeth

-----Original Message-----
From: robert kuzelj [mailto:robert_kuzelj@xxxxxxxxx]
Sent: June 18, 2004 8:56 AM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] identifying a call within a method and harvest
the parameter


hi,

i want to weave something around a call to a
method where the result of the around advice is dependent
on a paramater value given to the calling method.

<code>
public class Processor
{
   public Result process(Parameter _param)
   {
     ...
     Value val = createValue();
     ...
   }

   public Value createValue()
   {
     return null;
   }
}
</code>

now i want to do something like this

<code>
public aspect ProcessCreation
{
    pointcut creation(Parameter _param):
       withincode(public Result Processor.process(Parameter))
    && args(_param)
    && call(public Value Processor.createValue());

    Value around(Parameter _param): creation(_param)
    {
       Value result = null;
       if (_param.getValue() == 0)
       {
          result = new Value("OK");
       }
       else
       {
          result = new Value("FAILED");
       }
       return result;
    }
}
</code>

the problem is that as soon as i try to harvest the parameter
from the surrounding method the advice gets not executed anymore
(meaning the pointcut is not matched of course).

anybody any idea?

ciao robertj
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top