Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] passing an extra parameter to existing method s

AspectJ won't do that, but it's an interesting enough
subcase of proxying that you might want to submit it as
a compiler RFE in the bug database so it can be discussed
with other 1.2 language design issues.

But I'm less convinced that you want to add the methods
as you describe, particularly since they don't seem to
need to be visible to any clients other than the aspect.
Might you do the same with advice in the aspect?

-----
aspect A {

    pointcut someCalls(Context context) : {bind context}
       && execution({methods});

    Object around(Context context) : someCalls(context) {
       Object result = proceed();
       // do something with context
    }
}

-----

If you need to do things with the invoked instance, then
surface that as well:

    Object around(Context context, MyClass targ) :
           someCalls(context) && target(targ) {
       Object result = proceed();
       // do something with context and targ
    }

If the "do something with ..." code differs by type
or method, then it seems like you're back to specific
method delegate, which could be in the aspect or declared
in the target class.

Wes

Volkmann, Mark wrote:

I think what I want is a pattern-based form of method introduction ...
unless there is another approach that would provide this same thing.

-----Original Message-----
From: Volkmann, Mark Sent: Wednesday, July 09, 2003 2:11 PM
To: 'aspectj-users@xxxxxxxxxxx'
Subject: [aspectj-users] passing an extra parameter to existing methods



Is there a way I could do the following with AspectJ?
I want to add methods to several classes that wrap existing methods and add
an additional parameter. Then I want to use around advice to make calls to the original methods go to the new methods and add the new parameter. For example, the deposit method in my Account class looks like this. public void deposit(double amount) { balance += amount; } I want to add the following. public void deposit(Context context, double amount) { deposit(amount); // Do something with the context parameter here. } Then all calls to the original deposit method should go to the new one.
I know how to do this for individual methods, but I'm looking for a way to
do this to many methods in the Account class without having to write the
code for each of them in my aspect.



****************************************************************************
*******
WARNING: All e-mail sent to and from this address will be received or
otherwise recorded by the A.G. Edwards corporate e-mail system and is
subject to archival, monitoring or review by, and/or disclosure to,
someone other than the recipient.
****************************************************************************
********






Back to the top