aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/bugs151/atDecp/case1/MainClass.java44
-rw-r--r--tests/bugs151/atDecp/case2/MainClass.java46
-rw-r--r--tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java6
-rw-r--r--tests/src/org/aspectj/systemtest/ajc151/ajc151.xml38
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java24
5 files changed, 144 insertions, 14 deletions
diff --git a/tests/bugs151/atDecp/case1/MainClass.java b/tests/bugs151/atDecp/case1/MainClass.java
new file mode 100644
index 000000000..ab58d8c8a
--- /dev/null
+++ b/tests/bugs151/atDecp/case1/MainClass.java
@@ -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
index 000000000..7f33bbfae
--- /dev/null
+++ b/tests/bugs151/atDecp/case2/MainClass.java
@@ -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());
+ }
+}
+
diff --git a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
index 383fc05b3..a5447eaab 100644
--- a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
+++ b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
@@ -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");}
diff --git a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml
index d863a24b2..a9ec5f59b 100644
--- a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml
+++ b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml
@@ -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>
diff --git a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java
index d542571b6..397e8951c 100644
--- a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java
+++ b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java
@@ -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)