Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] adding interface to classes in jars that already have interface implementation

Hi - 
I've got a bunch of generated classes across multiple jars that I cannot change the source on, nor can I change how they are generated.  These generated classes all implement interface "A"

I'd like to add another interface to all these generated classes to make use of a handful of other methods they all already implement.  Essentially I'd like to simply add in another "implements B" to their definitions at compile time.  I've defined "B" interface and my aspect looks like this:

public aspect ImplementBInterfaceAspect {

    declare parents : A+ implements B;

}

Does that look correct?  I wrote some code that I thought would correctly prove the new "implements B" was being weaved in correctly.  That code looks like:

// C implements A by source code definition, and should have be known to "implements B" due to weaving of the aspect defined above
C cInstance = new C();

// B is an interface, cInstance should be known to implements B if weaving is taking place
B refToCInstance = cInstance;

The code above doesn't compile.  Complaining that cInstance cannot be assigned to refToCInstance.  I'm now realizing that weaving must not happen until after all existing code is already compiled??  Sorry for my beginner's understanding of AspectJ.  What would be a better test to validate that my desired weaving is happening?  

Thank you any clarity you can provide.

Jason 

Back to the top