diff options
-rw-r--r-- | tests/java5/ataspectj/annotationGen/DeclareAnnotationTest.aj | 36 | ||||
-rw-r--r-- | tests/java5/ataspectj/annotationGen/Deow.aj | 16 | ||||
-rw-r--r-- | tests/java5/ataspectj/annotationGen/ITDTest.aj | 66 | ||||
-rw-r--r-- | tests/java5/reflection/ReflectBilling.java | 52 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc150/ajc150.xml | 6 |
5 files changed, 138 insertions, 38 deletions
diff --git a/tests/java5/ataspectj/annotationGen/DeclareAnnotationTest.aj b/tests/java5/ataspectj/annotationGen/DeclareAnnotationTest.aj index 0c3e4608d..520c5eb96 100644 --- a/tests/java5/ataspectj/annotationGen/DeclareAnnotationTest.aj +++ b/tests/java5/ataspectj/annotationGen/DeclareAnnotationTest.aj @@ -16,11 +16,37 @@ public aspect DeclareAnnotationTest { AjType<DeclareAnnotationTest> myType = AjTypeSystem.getAjType(DeclareAnnotationTest.class); DeclareAnnotation[] decAs = myType.getDeclareAnnotations(); if (decAs.length != 4) throw new RuntimeException("Expecting 4 members, got " + decAs.length); - // should be in declaration order... - checkAtType(decAs[0]); - checkAtMethod(decAs[1]); - checkAtField(decAs[2]); - checkAtConstructor(decAs[3]); + + int atTypeIndex = -1; + int atMethodIndex = -1; + int atFieldIndex = -1; + int atConstructorIndex = -1; + + int index = 0; + for (DeclareAnnotation da : decAs) { + + switch (da.getKind()) { + case Field: + atFieldIndex = index++; + break; + case Method: + atMethodIndex = index++; + break; + case Constructor: + atConstructorIndex = index++; + break; + case Type: + atTypeIndex = index++; + break; + default: throw new RuntimeException ("unknown type"); + } + } + + + checkAtType(decAs[atTypeIndex]); + checkAtMethod(decAs[atMethodIndex]); + checkAtField(decAs[atFieldIndex]); + checkAtConstructor(decAs[atConstructorIndex]); } diff --git a/tests/java5/ataspectj/annotationGen/Deow.aj b/tests/java5/ataspectj/annotationGen/Deow.aj index b07e88355..063ac4200 100644 --- a/tests/java5/ataspectj/annotationGen/Deow.aj +++ b/tests/java5/ataspectj/annotationGen/Deow.aj @@ -9,8 +9,20 @@ public aspect Deow { AjType myType = AjTypeSystem.getAjType(Deow.class); DeclareErrorOrWarning[] deows = myType.getDeclareErrorOrWarnings(); if (deows.length != 2) throw new RuntimeException("Excepting 2 deows, got: " + deows.length); - if (deows[0].isError()) throw new RuntimeException("Expecting a warning"); - if (!deows[1].isError()) throw new RuntimeException("Expecting an error"); + int errorCount = 0; + int warningCount = 0; + if (deows[0].isError()) { + errorCount++; + } else { + warningCount++; + } + if (deows[1].isError()) { + errorCount++; + } else { + warningCount++; + } + if (errorCount != 1) { throw new RuntimeException("Expecting 1 declare error but found " + errorCount); } + if (warningCount != 1) { throw new RuntimeException("Expecting 1 declare warning but found " + warningCount); } if (!deows[0].getMessage().equals("dont call system methods")) throw new RuntimeException("Bad message"); if (!deows[1].getMessage().equals("dont call system methods")) throw new RuntimeException("Bad message"); if (!deows[0].getPointcutExpression().toString().equals("call(* java.lang.System.*(..))")) throw new RuntimeException("Bad pc: " + deows[0].getPointcutExpression()); diff --git a/tests/java5/ataspectj/annotationGen/ITDTest.aj b/tests/java5/ataspectj/annotationGen/ITDTest.aj index 26cdc4c2f..dc8089f70 100644 --- a/tests/java5/ataspectj/annotationGen/ITDTest.aj +++ b/tests/java5/ataspectj/annotationGen/ITDTest.aj @@ -35,17 +35,27 @@ public aspect ITDTest { private static void checkITDMs(AjType<?> itdTest) throws ClassNotFoundException { InterTypeMethodDeclaration[] itdms = itdTest.getDeclaredITDMethods(); assertEquals("expecting 3 declared methods, got: ",3,itdms.length); - assertEquals("expecting method name a, got: ","a",itdms[0].getName()); - assertEquals("expecting method name b, got: ","b",itdms[1].getName()); - assertEquals("expecting method name c, got: ","c",itdms[2].getName()); - assertEquals("expecting AjType<a.b.c.A>",AjTypeSystem.getAjType(A.class),itdms[0].getTargetType()); - assertEquals("expecting public method, got:",true,Modifier.isPublic(itdms[0].getModifiers())); - assertEquals("expecting private method, got:",true,Modifier.isPrivate(itdms[1].getModifiers())); - assertEquals("expecting non-public method, got:",false,Modifier.isPublic(itdms[2].getModifiers())); - assertEquals("one param, got: ",1,itdms[0].getParameterTypes().length); - assertEquals("expecting String, got: ",String.class,itdms[0].getParameterTypes()[0].getJavaClass()); - assertEquals("nothing thrown, but: ",0,itdms[1].getExceptionTypes().length); - assertEquals("expecting int, got: ",int.class,itdms[2].getReturnType().getJavaClass()); + InterTypeMethodDeclaration a = null,b = null,c = null; + for (int i = 0; i < itdms.length; i++) { + if (itdms[i].getName().equals("a")) { + a = itdms[i]; + } else if (itdms[i].getName().equals("b")) { + b = itdms[i]; + } else if (itdms[i].getName().equals("c")) { + c = itdms[i]; + } + } + assertNotNull("expecting method name a",a); + assertNotNull("expecting method name b",b); + assertNotNull("expecting method name c",c); + assertEquals("expecting AjType<a.b.c.A>",AjTypeSystem.getAjType(A.class),a.getTargetType()); + assertEquals("expecting public method, got:",true,Modifier.isPublic(a.getModifiers())); + assertEquals("expecting private method, got:",true,Modifier.isPrivate(b.getModifiers())); + assertEquals("expecting non-public method, got:",false,Modifier.isPublic(c.getModifiers())); + assertEquals("one param, got: ",1,a.getParameterTypes().length); + assertEquals("expecting String, got: ",String.class,a.getParameterTypes()[0].getJavaClass()); + assertEquals("nothing thrown, but: ",0,b.getExceptionTypes().length); + assertEquals("expecting int, got: ",int.class,c.getReturnType().getJavaClass()); itdms = itdTest.getITDMethods(); assertEquals("expecting 1 method, got: ",1,itdms.length); assertEquals("expecting method name a, got: ","a",itdms[0].getName()); @@ -62,23 +72,33 @@ public aspect ITDTest { private static void checkITDFs(AjType<?> itdTest) throws ClassNotFoundException { InterTypeFieldDeclaration[] itdfs = itdTest.getDeclaredITDFields(); assertEquals("expecting 3 declared fields, got: ",3, itdfs.length); - assertEquals("expecting field name f, got: ","f",itdfs[0].getName()); - assertEquals("expecting field name g, got: ","g",itdfs[1].getName()); - assertEquals("expecting field name h, got: ","h",itdfs[2].getName()); - assertEquals("expecting AjType<a.b.c.A>",AjTypeSystem.getAjType(A.class),itdfs[0].getTargetType()); - assertEquals("expecting public field, got:",true,Modifier.isPublic(itdfs[0].getModifiers())); - assertEquals("expecting private field, got:",true,Modifier.isPrivate(itdfs[1].getModifiers())); - assertEquals("expecting non-public field, got:",false,Modifier.isPublic(itdfs[2].getModifiers())); - assertEquals("expecting int, got: ",int.class,itdfs[2].getType().getJavaClass()); + InterTypeFieldDeclaration f = null,g = null,h = null; + for (int i = 0; i < itdfs.length; i++) { + if (itdfs[i].getName().equals("f")) { + f = itdfs[i]; + } else if (itdfs[i].getName().equals("g")) { + g = itdfs[i]; + } else if (itdfs[i].getName().equals("h")) { + h = itdfs[i]; + } + } + assertNotNull("expecting field name f",f); + assertNotNull("expecting field name g",g); + assertNotNull("expecting field name h",h); + assertEquals("expecting AjType<a.b.c.A>",AjTypeSystem.getAjType(A.class),f.getTargetType()); + assertEquals("expecting public field, got:",true,Modifier.isPublic(f.getModifiers())); + assertEquals("expecting private field, got:",true,Modifier.isPrivate(g.getModifiers())); + assertEquals("expecting non-public field, got:",false,Modifier.isPublic(h.getModifiers())); + assertEquals("expecting int, got: ",int.class,h.getType().getJavaClass()); itdfs = itdTest.getITDFields(); assertEquals("expecting 1 field, got: ",1, itdfs.length); assertEquals("expecting field name f, got: ","f",itdfs[0].getName()); try { - InterTypeFieldDeclaration f = itdTest.getDeclaredITDField("f",AjTypeSystem.getAjType(A.class)); + f = itdTest.getDeclaredITDField("f",AjTypeSystem.getAjType(A.class)); assertEquals("expecting f, got: ","f",f.getName()); } catch(NoSuchFieldException ex) { throw new RuntimeException("didn't find expected itdf"); } try { - InterTypeFieldDeclaration g = itdTest.getITDField("g",AjTypeSystem.getAjType(A.class)); + g = itdTest.getITDField("g",AjTypeSystem.getAjType(A.class)); throw new RuntimeException("Expected NoSuchFieldException not thrown"); } catch (NoSuchFieldException ex) { } } @@ -154,6 +174,10 @@ public aspect ITDTest { private static void assertEquals(String msg, Object expected, Object actual) { if (!expected.equals(actual)) throw new RuntimeException(msg + " " + actual.toString()); } + + private static void assertNotNull(String msg, Object obj) { + if (obj == null) throw new RuntimeException(msg); + } } diff --git a/tests/java5/reflection/ReflectBilling.java b/tests/java5/reflection/ReflectBilling.java index c93292cb1..1079417fb 100644 --- a/tests/java5/reflection/ReflectBilling.java +++ b/tests/java5/reflection/ReflectBilling.java @@ -1,3 +1,7 @@ +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; + import org.aspectj.lang.reflect.*; public class ReflectBilling { @@ -5,14 +9,48 @@ public class ReflectBilling { public static void main(String[] args) { AjType<Billing> billingType = AjTypeSystem.getAjType(Billing.class); InterTypeMethodDeclaration[] itdms = billingType.getDeclaredITDMethods(); - for(InterTypeMethodDeclaration itdm : itdms) { - System.out.println(itdm); - } + + Set s = new TreeSet(new Comparator<InterTypeMethodDeclaration>() { + public int compare(InterTypeMethodDeclaration m1, InterTypeMethodDeclaration m2) { + if (m1 == m2) return 0; + int vis = (m1.getModifiers() - m2.getModifiers()); + if (vis != 0) return vis; + int name = (m1.getName().compareTo(m2.getName())); + if (name != 0) return name; + try { + return ( + m1.getTargetType().getJavaClass().getName().compareTo( + m2.getTargetType().getJavaClass().getName()) + ); + } catch (ClassNotFoundException ex) { + throw new RuntimeException(ex); + } + } + }); + for (InterTypeMethodDeclaration itdm : itdms) { s.add(itdm); } + for (Object o : s) { System.out.println(o); } + InterTypeFieldDeclaration[] itdfs = billingType.getDeclaredITDFields(); - for(InterTypeFieldDeclaration itdf : itdfs) { - System.out.println(itdf); - } - } + + Set s2 = new TreeSet(new Comparator<InterTypeFieldDeclaration>() { + public int compare(InterTypeFieldDeclaration m1, InterTypeFieldDeclaration m2) { + if (m1 == m2) return 0; + int vis = (m1.getModifiers() - m2.getModifiers()); + if (vis != 0) return vis; + int name = (m1.getName().compareTo(m2.getName())); + if (name != 0) return name; + try { + return ( + m1.getTargetType().getJavaClass().getName().compareTo( + m2.getTargetType().getJavaClass().getName()) + ); + } catch (ClassNotFoundException ex) { + throw new RuntimeException(ex); + } + } + }); + for (InterTypeFieldDeclaration itdf : itdfs) { s2.add(itdf); } + for (Object o : s2) { System.out.println(o); } } }
\ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 7f8b62841..fb69bba97 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -318,10 +318,10 @@ <compile files="ReflectBilling.java,Billing.aj" options="-1.5"/> <run class="ReflectBilling"> <stdout> - <line text="public abstract long Connection.callRate()"/> - <line text="public long LongDistance.callRate()"/> - <line text="public long Local.callRate()"/> <line text="public void Customer.addCharge(long)"/> + <line text="public long Local.callRate()"/> + <line text="public long LongDistance.callRate()"/> + <line text="public abstract long Connection.callRate()"/> <line text="public Customer Connection.payer"/> <line text="public long Customer.totalCharge"/> </stdout> |