Browse Source

test and fix for @DeclareParents problem where the target was "@Coloured *" - fix was to resolve the typepattern

tags/V1_5_1_final
aclement 18 years ago
parent
commit
e05ab26570

+ 44
- 0
tests/bugs151/atDecp/case1/MainClass.java View File

@@ -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());
}
}


+ 46
- 0
tests/bugs151/atDecp/case2/MainClass.java View File

@@ -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());
}
}


+ 5
- 1
tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java View 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");}

+ 38
- 0
tests/src/org/aspectj/systemtest/ajc151/ajc151.xml View 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>

+ 11
- 13
weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java View 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)

Loading…
Cancel
Save