]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 122370 (Andy & Helen) - code generated for @Decp busted.
authoraclement <aclement>
Thu, 16 Feb 2006 16:50:34 +0000 (16:50 +0000)
committeraclement <aclement>
Thu, 16 Feb 2006 16:50:34 +0000 (16:50 +0000)
tests/bugs151/pr122370/moody/AnnotationMoodImplementor.java [new file with mode: 0644]
tests/bugs151/pr122370/moody/AnnotationMoodIndicator.java [new file with mode: 0644]
tests/bugs151/pr122370/moody/MainClass.java [new file with mode: 0644]
tests/bugs151/pr122370/moody/Mood.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/BcelTypeMunger.java

diff --git a/tests/bugs151/pr122370/moody/AnnotationMoodImplementor.java b/tests/bugs151/pr122370/moody/AnnotationMoodImplementor.java
new file mode 100644 (file)
index 0000000..008119b
--- /dev/null
@@ -0,0 +1,5 @@
+package moody;
+
+public class AnnotationMoodImplementor {
+
+}
diff --git a/tests/bugs151/pr122370/moody/AnnotationMoodIndicator.java b/tests/bugs151/pr122370/moody/AnnotationMoodIndicator.java
new file mode 100644 (file)
index 0000000..be8cab5
--- /dev/null
@@ -0,0 +1,22 @@
+package moody;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.DeclareParents;
+
+@Aspect
+public 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;
+}
diff --git a/tests/bugs151/pr122370/moody/MainClass.java b/tests/bugs151/pr122370/moody/MainClass.java
new file mode 100644 (file)
index 0000000..82e4a95
--- /dev/null
@@ -0,0 +1,17 @@
+package moody;
+
+public class MainClass {
+
+       public static void main(String[] args) {
+               AnnotationMoodImplementor ami0 = new AnnotationMoodImplementor();
+               AnnotationMoodImplementor ami1 = new AnnotationMoodImplementor();
+
+               System.out.println("ami0's mood is " + ((AnnotationMoodIndicator.Moody) ami0).getMood());
+               ((AnnotationMoodIndicator.Moody) ami1).setMood(Mood.JOLLY);
+               System.out.println("ami1's mood is now " + ((AnnotationMoodIndicator.Moody) ami1).getMood());
+               System.out.println("ami0's mood is still " + ((AnnotationMoodIndicator.Moody) ami0).getMood());
+       }
+       
+
+       
+}
diff --git a/tests/bugs151/pr122370/moody/Mood.java b/tests/bugs151/pr122370/moody/Mood.java
new file mode 100644 (file)
index 0000000..50d0e84
--- /dev/null
@@ -0,0 +1,5 @@
+package moody;
+
+public enum Mood {
+        HAPPY, JOLLY 
+}
index 24b006fd2831cf7cc7e455ddf504aebea27a07c2..95a24601330c45ebbc20f9a4ce0535f4baa14d58 100644 (file)
@@ -164,6 +164,10 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
          runTest("@AJ without JoinPoint import");
   }
   
+  public void testAtAspectDeclareParentsRetainsFieldState_pr122370() {
+         runTest("@AJ declare parents retains field state");
+  }
+  
   /*
    * Load-time weaving bugs and enhancements
    */
index 46e8bc97ddcd0049b95862bcbbf69b5baa64dc24..c470c67bf16ed42d1c6268eca5427d896a684be5 100644 (file)
         </compile>
     </ajc-test>
 
+    <ajc-test dir="bugs151/pr122370" title="@AJ declare parents retains field state">
+        <compile files="moody/AnnotationMoodImplementor.java, moody/AnnotationMoodIndicator.java, moody/Mood.java, moody/MainClass.java" options="-1.5"/>
+       <run class="moody.MainClass">
+            <stdout>
+             <line text="ami0's mood is HAPPY"/>
+             <line text="ami1's mood is now JOLLY"/>
+             <line text="ami0's mood is still HAPPY"/>
+            </stdout>
+        </run>
+    </ajc-test>
+
     <!-- New features down here... when they arent big enough to have their own test file -->
     
     <ajc-test dir="features151/ptw" title="exposing withintype">
index 0497f109aa503d0e868bdbc62e050aba21b25250..e291cc3e3b05ec9d76cdb50d66f9f5d0815e5760 100644 (file)
@@ -1110,15 +1110,19 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
             // getfield
             body.append(InstructionConstants.ALOAD_0);
             body.append(Utility.createGet(fact, munger.getDelegate(weaver.getLazyClassGen().getType())));
-            BranchInstruction ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
+            BranchInstruction ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
             body.append(ifNonNull);
-            InstructionHandle ifNonNullElse = body.append(InstructionConstants.ALOAD_0);
+            
+            // Create and store a new instance
+               body.append(InstructionConstants.ALOAD_0);
             body.append(fact.createNew(munger.getImplClassName()));
             body.append(InstructionConstants.DUP);
             body.append(fact.createInvoke(munger.getImplClassName(), "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
             body.append(Utility.createSet(fact, munger.getDelegate(weaver.getLazyClassGen().getType())));
+            
+            // if not null use the instance we've got
+            InstructionHandle ifNonNullElse =  body.append(InstructionConstants.ALOAD_0);
             ifNonNull.setTarget(ifNonNullElse);
-            body.append(InstructionConstants.ALOAD_0);
             body.append(Utility.createGet(fact, munger.getDelegate(weaver.getLazyClassGen().getType())));
 
             //args