[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Applying @DeclareParents to annotated classes
|
Ok, let's see what's different, here is my application that now works perfectly:
==========8<==========
package moody;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareParents
;
import java.lang.annotation.*;
enum Mood { HAPPY, SAD, JOLLY, GRUMPY }
@Retention(RetentionPolicy.RUNTIME) @interface Coloured {}
@Coloured
class Victim { }
interface Moody {
Mood getMood();
void setMood(Mood mood);
}
@Aspect
class AnnotationMoodIndicator {
public static class MoodyImpl implements Moody {
private Mood mood = Mood.HAPPY;
public Mood getMood() { return mood; }
public void setMood(Mood mood) { this.mood = mood; }
}
@DeclareParents(value="@Coloured *",defaultImpl=MoodyImpl.class)
private Moody implementedInterface;
}
public class MainClass {
public static void main(String[] args) {
Victim _one_ = new Victim();
Victim two = new Victim();
System.err.println("one's mood is " + ((Moody)one).getMood());
((Moody)one).setMood(
Mood.JOLLY);
System.err.println("two's mood is now " + ((Moody)two).getMood());
System.err.println("one's mood is still " + ((Moody)one).getMood());
}
}
==========8<==========
>ajc -1.5 -showWeaveInfo -d . MainClass.java
Extending interface set for type 'moody.Victim' (MainClass.java) to include 'moody.Moody' (MainClass.java)
Type 'moody.Victim' (MainClass.java) has intertyped method from '
moody.AnnotationMoodIndicator' (MainClass.java:'moody.Mood moody.Moody.getMood()')
Type 'moody.Victim' (MainClass.java) has intertyped method from 'moody.AnnotationMoodIndicator' (MainClass.java:'void moody.Moody.setMood
(moody.Mood)')
>java moody.MainClass
one's mood is HAPPY
two's mood is HAPPY
two's mood is now JOLLY
one's mood is still HAPPY
- what is the retention policy on your annotation @Audit?
- if your annotation is not in the same package as the application, you will need to fully qualify the reference in the type pattern @DeclareParents(value="@
somepackage.Coloured *",defaultImpl=MoodyImpl.class)
On 30/03/06, Scott <aspectj-users@xxxxxxxxxxx
> wrote:Sorry for the late reply. I downloaded the latest code release from the
link you provided and replaced all the jars used in my build.
Unfortunately it appears as though it is still not working. When I take
the @Audit annotation off the pattern it starts working again.
-Scott
================================================
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users