From e87458179ab929aae2bc6966a6e092813bdd14a3 Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 16 Feb 2006 16:50:34 +0000 Subject: [PATCH] test and fix for 122370 (Andy & Helen) - code generated for @Decp busted. --- .../moody/AnnotationMoodImplementor.java | 5 +++++ .../moody/AnnotationMoodIndicator.java | 22 +++++++++++++++++++ tests/bugs151/pr122370/moody/MainClass.java | 17 ++++++++++++++ tests/bugs151/pr122370/moody/Mood.java | 5 +++++ .../systemtest/ajc151/Ajc151Tests.java | 4 ++++ .../org/aspectj/systemtest/ajc151/ajc151.xml | 11 ++++++++++ .../aspectj/weaver/bcel/BcelTypeMunger.java | 10 ++++++--- 7 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 tests/bugs151/pr122370/moody/AnnotationMoodImplementor.java create mode 100644 tests/bugs151/pr122370/moody/AnnotationMoodIndicator.java create mode 100644 tests/bugs151/pr122370/moody/MainClass.java create mode 100644 tests/bugs151/pr122370/moody/Mood.java diff --git a/tests/bugs151/pr122370/moody/AnnotationMoodImplementor.java b/tests/bugs151/pr122370/moody/AnnotationMoodImplementor.java new file mode 100644 index 000000000..008119bb6 --- /dev/null +++ b/tests/bugs151/pr122370/moody/AnnotationMoodImplementor.java @@ -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 index 000000000..be8cab5f6 --- /dev/null +++ b/tests/bugs151/pr122370/moody/AnnotationMoodIndicator.java @@ -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 index 000000000..82e4a9534 --- /dev/null +++ b/tests/bugs151/pr122370/moody/MainClass.java @@ -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 index 000000000..50d0e84f0 --- /dev/null +++ b/tests/bugs151/pr122370/moody/Mood.java @@ -0,0 +1,5 @@ +package moody; + +public enum Mood { + HAPPY, JOLLY +} diff --git a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java index 24b006fd2..95a246013 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java @@ -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 */ diff --git a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml index 46e8bc97d..c470c67bf 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml +++ b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml @@ -182,6 +182,17 @@ + + + + + + + + + + + diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index 0497f109a..e291cc3e3 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -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(), "", 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 -- 2.39.5