]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for @DeclareParents problem where the target was "@Coloured *" - fix...
authoraclement <aclement>
Wed, 29 Mar 2006 11:41:39 +0000 (11:41 +0000)
committeraclement <aclement>
Wed, 29 Mar 2006 11:41:39 +0000 (11:41 +0000)
tests/bugs151/atDecp/case1/MainClass.java [new file with mode: 0644]
tests/bugs151/atDecp/case2/MainClass.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
tests/src/org/aspectj/systemtest/ajc151/ajc151.xml
weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java

diff --git a/tests/bugs151/atDecp/case1/MainClass.java b/tests/bugs151/atDecp/case1/MainClass.java
new file mode 100644 (file)
index 0000000..ab58d8c
--- /dev/null
@@ -0,0 +1,44 @@
+package moody;
+
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.DeclareParents;
+
+enum Mood { HAPPY, SAD, JOLLY, GRUMPY }
+
+class AnnotationMoodImplementor { }
+
+
+
+@Aspect
+class AnnotationMoodIndicator {
+
+   public interface Moody {
+      Mood getMood();
+      void setMood(Mood mood);
+   }
+
+   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="moody.AnnotationMoodImplementor",defaultImpl=MoodyImpl.class)
+   private Moody implementedInterface;
+}
+
+
+
+public class MainClass {
+  public static void main(String[] args) {
+    AnnotationMoodImplementor ami0 = new AnnotationMoodImplementor();
+    AnnotationMoodImplementor ami1 = new AnnotationMoodImplementor();
+
+    System.err.println("ami0's mood is " + ((AnnotationMoodIndicator.Moody) ami0).getMood());
+    ((AnnotationMoodIndicator.Moody) ami1).setMood(Mood.JOLLY);
+    System.err.println("ami1's mood is now " + ((AnnotationMoodIndicator.Moody) ami1).getMood());
+    System.err.println("ami0's mood is still " + ((AnnotationMoodIndicator.Moody) ami0).getMood());
+  }
+}
+
diff --git a/tests/bugs151/atDecp/case2/MainClass.java b/tests/bugs151/atDecp/case2/MainClass.java
new file mode 100644 (file)
index 0000000..7f33bbf
--- /dev/null
@@ -0,0 +1,46 @@
+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 AnnotationMoodImplementor { }
+
+@Aspect
+class AnnotationMoodIndicator {
+
+   public interface Moody {
+      Mood getMood();
+      void setMood(Mood mood);
+   }
+
+   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) // Choosing types by annotation
+   private Moody implementedInterface;
+}
+
+
+
+public class MainClass {
+  public static void main(String[] args) {
+    AnnotationMoodImplementor ami0 = new AnnotationMoodImplementor();
+    AnnotationMoodImplementor ami1 = new AnnotationMoodImplementor();
+
+    System.err.println("ami0's mood is " + ((AnnotationMoodIndicator.Moody) ami0).getMood());
+    ((AnnotationMoodIndicator.Moody) ami1).setMood(Mood.JOLLY);
+    System.err.println("ami1's mood is now " + ((AnnotationMoodIndicator.Moody) ami1).getMood());
+    System.err.println("ami0's mood is still " + ((AnnotationMoodIndicator.Moody) ami0).getMood());
+  }
+}
+
index 383fc05b380e98bb7b824cdfbfeed724d098f298..a5447eaabd10e981208d3e81c994484127624029 100644 (file)
@@ -24,8 +24,12 @@ import org.aspectj.systemtest.ajc150.GenericsTests;
 import org.aspectj.testing.XMLBasedAjcTestCase;
 
 public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
+  // public void testItdOnInnerTypeOfGenericType_pr132349() { runTest("ITD on inner type of generic type");}
+
+  // Some @DeclareParents testing
+  public void testAtDecp_1() { runTest("atDecp - simple");}
+  public void testAtDecp_2() { runTest("atDecp - annotation");}
 
- // public void testItdOnInnerTypeOfGenericType_pr132349() { runTest("ITD on inner type of generic type");}
   public void testAnnotationsAndItds_pr98901() { runTest("annotations and itds");}
   public void testAnnotationsAndItds_pr98901_2() { runTest("annotations and itds - 2");}
   public void testCircularGenerics_pr133307() { runTest("circular generics");}
index d863a24b24dc9c1cbf6bf44cb7ecc35c77cbf610..a9ec5f59bb3f3201ef90a32f8a26cb60c71e3625 100644 (file)
@@ -3,6 +3,44 @@
 <!-- AspectJ v1.5.1 Tests -->
 <suite>
 
+    <!-- atDecp begin -->
+   
+    <!-- something simple -->
+    <ajc-test dir="bugs151/atDecp/case1" title="atDecp - simple">
+      <compile files="MainClass.java" options="-1.5 -showWeaveInfo">
+        <message kind="weave" text="Extending interface set for type 'moody.AnnotationMoodImplementor' (MainClass.java) to include 'moody.AnnotationMoodIndicator$Moody' (MainClass.java)"/>
+           <message kind="weave" text="Type 'moody.AnnotationMoodImplementor' (MainClass.java) has intertyped method from 'moody.AnnotationMoodIndicator' (MainClass.java:'moody.Mood moody.AnnotationMoodIndicator$Moody.getMood()')"/>
+           <message kind="weave" text="Type 'moody.AnnotationMoodImplementor' (MainClass.java) has intertyped method from 'moody.AnnotationMoodIndicator' (MainClass.java:'void moody.AnnotationMoodIndicator$Moody.setMood(moody.Mood)')"/>
+      </compile>
+      <run class="moody.MainClass">
+         <stderr>
+           <line text="ami0's mood is HAPPY"/>
+           <line text="ami1's mood is now JOLLY"/>
+           <line text="ami0's mood is still HAPPY"/>
+         </stderr>
+      </run>
+    </ajc-test>
+    
+    <!-- applying parent based on annotation -->
+    <ajc-test dir="bugs151/atDecp/case2" title="atDecp - annotation">
+      <compile files="MainClass.java" options="-1.5 -showWeaveInfo">
+        <message kind="weave" text="Extending interface set for type 'moody.AnnotationMoodImplementor' (MainClass.java) to include 'moody.AnnotationMoodIndicator$Moody' (MainClass.java)"/>
+           <message kind="weave" text="Type 'moody.AnnotationMoodImplementor' (MainClass.java) has intertyped method from 'moody.AnnotationMoodIndicator' (MainClass.java:'moody.Mood moody.AnnotationMoodIndicator$Moody.getMood()')"/>
+           <message kind="weave" text="Type 'moody.AnnotationMoodImplementor' (MainClass.java) has intertyped method from 'moody.AnnotationMoodIndicator' (MainClass.java:'void moody.AnnotationMoodIndicator$Moody.setMood(moody.Mood)')"/>
+      </compile>
+      <run class="moody.MainClass">
+         <stderr>
+           <line text="ami0's mood is HAPPY"/>
+           <line text="ami1's mood is now JOLLY"/>
+           <line text="ami0's mood is still HAPPY"/>
+         </stderr>
+      </run>
+    </ajc-test>
+    
+    
+    <!-- atDecp end -->
+
+
     <ajc-test dir="bugs151/pr132349" title="ITD on inner type of generic type">
      <compile files="TopLevelType.java" options="-1.5"/>
     </ajc-test>
index d542571b6462791484eadbf636b470422bb20f94..397e8951c8ddf01495440b56eccb44096d2fe952 100644 (file)
@@ -55,10 +55,10 @@ import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.WeaverMessages;
 import org.aspectj.weaver.patterns.AndPointcut;
+import org.aspectj.weaver.patterns.Bindings;
 import org.aspectj.weaver.patterns.DeclareErrorOrWarning;
 import org.aspectj.weaver.patterns.DeclareParents;
 import org.aspectj.weaver.patterns.DeclarePrecedence;
-import org.aspectj.weaver.patterns.ExactTypePattern;
 import org.aspectj.weaver.patterns.FormalBinding;
 import org.aspectj.weaver.patterns.IScope;
 import org.aspectj.weaver.patterns.IdentityPointcutVisitor;
@@ -668,22 +668,20 @@ public class AtAjAttributes {
                 TypePattern typePattern = parseTypePattern(decpPattern, struct);
                 ResolvedType fieldType = UnresolvedType.forSignature(struct.field.getSignature()).resolve(struct.enclosingType.getWorld());
                 if (fieldType.isInterface()) {
-                    TypePattern parent = new ExactTypePattern(UnresolvedType.forSignature(struct.field.getSignature()), false, false);
-                    parent.resolve(struct.enclosingType.getWorld());
+                    TypePattern parent = parseTypePattern(fieldType.getName(),struct);
+                    FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
+                       IScope binding = new BindingScope(struct.enclosingType,struct.context,bindings);
                     // first add the declare implements like
                     List parents = new ArrayList(1); parents.add(parent);
-                    DeclareParents dp = new DeclareParents(
-                            typePattern,
-                            parents,
-                            false
-                        );
+                    DeclareParents dp = new DeclareParents(typePattern,parents,false);
+                    dp.resolve(binding); // resolves the parent and child parts of the decp
+                    
+                    // resolve this so that we can use it for the MethodDelegateMungers below.
+                    // eg. '@Coloured *' will change from a WildTypePattern to an 'AnyWithAnnotationTypePattern' after this resolution
+                    typePattern = typePattern.resolveBindings(binding, Bindings.NONE, false, false);
                     //TODO kick ISourceLocation sl = struct.bField.getSourceLocation();    ??
                     dp.setLocation(struct.context,0,0); // not ideal...
-                    struct.ajAttributes.add(
-                            new AjAttribute.DeclareAttribute(
-                                    dp
-                            )
-                    );
+                    struct.ajAttributes.add(new AjAttribute.DeclareAttribute(dp));
 
 
                     // do we have a defaultImpl=xxx.class (ie implementation)