Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Weaving advice around methods defined by declare parents

Title: Weaving advice around methods defined by declare parents

Hi Mike,

 

It turns out your complaint is related to the problem using inter-type declarations that Eric Jain posted (see http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg01271.html). Eric's work around should work for you too: try using:

 

interface Apublic { void x(); }

 

aspect EnhanceX {

   interface Aprivate extends Apublic  {}

   declare parents: A implements Aprivate;

   void Aprivate.x() { ... }

...

}

 

I haven't had time to test, but according to Eric that should allow you to call A.x() normally, even from a pure java client (and this also means the bytecode to call A.x will be normal...)

 

I plan to submit a bug/enhancement request so ITD's can be called "normally" from pure java clients...

 

Ron

 

Ron Bodkin

Chief Technology Officer

New Aspects of Security

m: (415) 509-2895

 

 

------------Original Message------------

From: "Mike Pettypiece" <Mike.Pettypiece@xxxxxxxxxxxxxxx>

To: <aspectj-users@xxxxxxxxxxx>

Date: Mon, Dec-1-2003 6:46 AM

Subject: RE: [aspectj-users] Weaving advice around methods defined by declare parents

Actually I was wrong about your pointcut.  It was actually the declare parents statement which was (for some reason) changing the client code.  If I call:
 
A = new AImpl();
a.x();
 
When I decompile the code I see:
 

A a = new AImpl();

AspectA.ajc$interMethodDispatch1$a_AspectA$a_A$x(a);

 

 

 

-----Original Message-----
From: aspectj-users-admin@xxxxxxxxxxx [mailto:aspectj-users-admin@xxxxxxxxxxx]On Behalf Of Mike Pettypiece
Sent: Thursday, November 27, 2003 5:35 PM
To: aspectj-users@xxxxxxxxxxx
Subject: RE: [aspectj-users] Weaving advice around methods defined by declare parents

Hi Ron,
 
Thanks for your reply.  The problem with your pointcut is that it inserts advice into the client code and I'm trying to avoid that.
 
My example below was a possible solution to a problem I'm trying to solve, but maybe someone has already encountered this problem so I'll quickly sketch it out. 
 
I'm trying to create two different versions of some functionality; one that has been aspected and another that has not.  Ideally I would like to minimize the amount of code I have to maintain.  I plan on creating a Factory which would return either an aspected or unaspected object depending on some flag. 
 
Has anyone found a good solution to this?  One possible way I've though of is to have each aspected method call the corresponding unaspected method.  However that is not ideal considering the number of classes and methods on those classes that I'm going to have to maintain. 
 
I know running the advice all the time does not add too much overhead, but there are some situations where this is not acceptable.  It would be cool if there was some other solution to this problem.
 
Cheers,
 
Mike
-----Original Message-----
From: aspectj-users-admin@xxxxxxxxxxx [mailto:aspectj-users-admin@xxxxxxxxxxx]On Behalf Of Ron Bodkin
Sent: Thursday, November 27, 2003 2:50 PM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Weaving advice around methods defined by declare parents

Hi Mike,

 

Try either execution(void A.x()) or execution(void A.x()) && this(AImpl)

 

execution(void AImpl.x()) will only match methods named x that are defined on the AImpl type, not on inherited methods from supertypes.

 

Ron

 

Ron Bodkin

Chief Technology Officer

New Aspects of Security

m: (415) 509-2895

 

 

------------Original Message------------

From: "Mike Pettypiece" <Mike.Pettypiece@xxxxxxxxxxxxxxx>

To: <aspectj-users@xxxxxxxxxxx>

Date: Thu, Nov-27-2003 11:13 AM

Subject: [aspectj-users] Weaving advice around methods defined by declare parents

I'm wondering if something like the following is possible:

public aspect AspectA
{
    declare parents: AImpl implements A;  // A has one method, void x();
   
    // Implement A
    public void A.x() { System.out.println( "x()" ); }

    pointcut myPC() : execution( void AImpl.x() );
   
    Object around() : myPC()
    {
        System.out.println( "Before x()" );
        Object result = proceed();
        System.out.println( "After x()");
        return result;  
    }  
}


This is a simplified example of what I'm trying to do but it illustrates my problem.  What I would like to do is implement an interface using an aspect and then add advice around those methods that were implemented.  However AspectJ doesn't seem to be able to add advice in this fashion.

Any ideas how I can accomplish this?

Cheers,

Mike


Back to the top