Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Issues with @DeclareParents and @DeclareMixin

Hi all. We have some existing aspects that use @DeclareParents to add an interface with a default implementation
to some classes. We have been using Spring to create proxies based on our aspects at runtime, however we have
hit some issues with code signing  (it's a Webstart app) so I'm trying to get compile-time weaving going instead.
 
I seem to be hitting some issues though. I'll leave the Eclipse AJDT issues aside for now, I'll just concentrate on
issues running the AspectJ compiler on its own.
 
Before I start - one odd thing I noticed is that when running both the 1.6.4 compiler and the the latest development
one (from aspectj-DEVELOPMENT-20090612201410.jar), the compiler reports as being version 1.6.3, I don't know if that's
a source of problems or not:
 
>\development\aspectj1.6.4\bin\ajc -version
AspectJ Compiler 1.6.3 (1.6.3 - Built: Tuesday Dec 23, 2008 at 17:12:30 GMT) - Eclipse Compiler 0.785_R33x, 3.3
 
I have a couple of test aspects and a target file that should get woven accordingly (imports omitted for brevity):
 
package aspects;
@Aspect
public class ParentsAspect {
 
    @DeclareParents(value = "test.Foo", defaultImpl = DebugDefault.class)
    public Runnable runnable;
 
    public static class DebugDefault implements Runnable {
        public void run() {
            System.out.println("hi there from ParentsAspect");
        }
    }
}
 
@Aspect
public class MixinAspect {
    @DeclareMixin(value = "test.Foo")
    public static Runnable foo(Object target) {
        return new DebugDefault();
    }
 
    public static class DebugDefault implements Runnable {
        public void run() {
            System.out.println("Hi there from MixinAspect");
        }
    }
}
 
package test;
public class Foo {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Foo().getClass().getInterfaces()));
        ((Runnable) new Foo()).run();
    }
}
 
When I try to apply the parents aspect, I get the following (no warnings about versions from the dev build btw, but otherwise the same results):
 
>\development\aspectj1.6.4\bin\ajc -outjar aspects.jar src\java\aspects\ParentsAspect.java -1.5
[warning] bad version number found in c:\Development\aspectj1.6.4\lib\aspectjrt.jar expected 1.6.3 found 1.6.4
 

1 warning
 
>\development\aspectj1.6.4\bin\ajc -aspectpath aspects.jar -outjar app.jar src\java\test\Foo.java -showWeaveInfo -1.5
[warning] bad version number found in c:\Development\aspectj1.6.4\lib\aspectjrt.jar expected 1.6.3 found 1.6.4
 
C:\Development\eclipse-workspace\e3.4.2\AspectJTestAspect\src\java\test\Foo.java:12 [error] The type Foo must implement
the inherited abstract method Runnable.run()
public class Foo {
             ^^
 
1 error, 1 warning
 
So it has picked up that Foo should implement Runnable, but hasn't supplied the implementation.
 
If I try the mixin aspect, I get no errors, no weave info and Foo has not had the aspect applied.
 
Interestingly, I get the first error for BOTH aspects in Eclipse using the AJDT, but only when Foo is in a different project to the aspects - when in the same project it works fine.
 
So, am I doing something fundamentally wrong? Am I using a dodgy compiler? (I downloaded the dev and 1.6.4 builds from eclipse.org yesterday) Something else strange going on?
 
Any help much appreciated.
 
Cheers
 
Tom

Back to the top