[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Modifying the parameters of methods with arbitrarysignatures

Okay, more on this:

I'm not overthinking it; the construct I describe below does NOT work, it instead only joins methods with one argument, which is not what I want.

Chris Rose wrote:
That works for the purposes of getting them, but I need to feed them back into the proceed call, don't I?

Suppose I have two methods:

public String methodA (String s1, int value2, MyObject foo) {}

public boolean methodB (MyOtherObject bar) {}

I want to write _one_ aspect that can take in those values (note that the String s1 and int value2 in the first method are _immutable_ -- I have to somehow replace those values if I want to change them) and call proceed with the modified values. The key here is the desire for one aspect for both (and other) methods.

If I limit the changes to alterations of the objects in the input arguments, then I'm okay.

Or, am I overthinking it? Can I create a bit of advice like this? (note I've moved over to annotation-based aspects for some other reasons, although I could move back if necessary)

@Around ("myPointCut() && args(args) && target (delegate)")
public Object interceptor (ProceedingJoinPoint thisJoinPoint, Object[] args, MyDelegate delegate) {

  Object[] modifiedArgs = doSomethingToArgs (args);
  return thisJoinPoint.proceed (modifiedArgs, delegate);


Ron Bodkin wrote:
You will want to use thisJoinPoint.getArgs() to get the array of any number
of arguments at the current join point. See the AspectJ user guide (or a
good book like AspectJ in Action or Eclipse AspectJ) for more details.

-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Chris Rose
Sent: Wednesday, October 31, 2007 1:40 PM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Modifying the parameters of methods with

I want to use aspectj to provide a generic interceptor framework where we can plug in code at any point to modify input parameters to our methods.

Ideally, what I want is something like this, but I'm not sure how to accomplish it in aspectj (this uses a bastardization of the Java5 varargs syntax, below, for illustrative purposes).

around(Object... args): methodPointCut(args(args)) {
     newArgs = invokeHook (args);

Is there any way to do this without needing to enumerate the parameters in the aspect?

-- Chris Rose Developer Planet Consulting Group (780) 577-8433 crose@xxxxxxxxxxxx