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());
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) { }
}
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);
+ }
}
+import java.util.Comparator;
+import java.util.Set;
+import java.util.TreeSet;
+
import org.aspectj.lang.reflect.*;
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