Skip to main content

[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

================================================


On 3/29/06, Andy Clement <andrew.clement@xxxxxxxxx > wrote:
Ok Scott ...

Are you able to download and try the latest AspectJ?  Fresh off the presses, from our download page or directly through this link:

  http://www.eclipse.org/downloads/download.php?file=/technology/aspectj/dev/aspectj-DEVELOPMENT-20060329133605.jar

This *will* fix your annotation problem.  It may also affect the other problem where you needed to create the proxy interface - are you able to try it in that situation too?

cheers,
Andy.

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top