[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Mixins with @DeclareParents (M5)
|
I am not sure about this, but the PersistentImpl shouldn't be declared as static?
About Eclipse/AJDT: if you want to use directly the ITDs, I think you should set the AJDT editor as
the default for all .java files.
However, I don't understand how this would look like:
[code]
For example, Test.java could not look as follows:
>> public Test {
>> long test { return getId(); }
>> }
[/code]
Haven't you missed something? (some paranthesis, I guess).
./alex
--
.w( the_mindstorm )p.
#: Brian Ericson changed the world a bit at a time by saying on 11/23/2005 7:30 AM :#
Some progress... Moving everything to a "test" package and changing the
declaration to:
@DeclareParents("@test.PersistentEntity test.*")
is enough to get AspectJ markers in Eclipse. However, an attempt to
construct an instance of Test fails with the following exception:
java.lang.VerifyError: (class: test/Test, method: setId signature: (J)V)
Register pair 0/1 contains wrong type
I also reworked the "moody" example (in the documentation and sited in a
thread below) using a Persistent interface and PersistentImpl
implementation outside of the aspect, allowing me to do the following:
package test;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareParents;
@Aspect
public class PersistentEntityAspect {
@DeclareParents("@test.PersistentEntity test.*")
public static Persistent introduced = new PersistentImpl();
}
This fails with the same exception above. What am I doing wrong? This
works for Adrian... (see
http://www-128.ibm.com/developerworks/java/library/j-aopwork8/ ).
Brian Ericson wrote:
I'm trying to implement mixins using the @Aspect/@DeclareParents
annotations. To begin with, the following works:
PersistentEntity.java:
public @interface PersistentEntity { }
PersistentEntityAspect.aj:
public aspect PersistentEntityAspect {
public interface Persistent {
long getId();
void setId(long id);
}
declare parents : @PersistentEntity * implements Persistent;
long Persistent.id = 0;
public long Persistent.getId() { return id; }
public void Persistent.setId(long id) { this.id = id; }
}
Test.java:
@PersistentEntity
public class Test { }
Using Jython, I can see that Test implements
PersistentEntityAspect.Persistent and can call both getId() and setId().
The following does not work (replacing PersistentEntityAspect.aj with
PersistentEntityAspect.java):
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareParents;
@Aspect
public class PersistentEntityAspect {
public interface Persistent {
long getId();
void setId(long id);
}
public class PersistentImpl implements Persistent {
long id;
public long getId() { return id; }
public void setId(long id) { this.id = id; }
}
@DeclareParents("@PersistentEntity *")
public static Persistent introduced = new
PersistentEntityAspect().new PersistentImpl();
}
Test is not advised and does not implement any interface. (I did use
the recent thread
http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg05032.html as
reference, but this neither compiled (... introduced = new
MoodyImpl();) nor did I get the advice bit working out. I must be
doing something simple wrong (maybe I need to post-compile the result
to weave it or use load-time weaving? I'm not sure how to do either
(more research!))...
Other questions... Eclipse/AJDT does not allow me to use methods
introduced by advice. For example, Test.java could not look as follows:
public Test {
long test { return getId(); }
}
This actually compiles and runs correctly using ajc, but won't get
compile in the IDE (The method getId() is undefined...).
Also, how're people using AspectJ with Maven 2? Confessing to be a
newbie to both AspectJ and Maven, I'm currently "tricking" it by using
ajc as my java compiler.
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users