1 22 package org.jboss.aop.util; 23 24 import javassist.CtClass; 25 import javassist.CtConstructor; 26 import javassist.bytecode.Descriptor; 27 28 35 public class CtConstructorComparator implements java.util.Comparator { 36 37 private CtConstructorComparator() {} 38 39 public static final java.util.Comparator INSTANCE = new CtConstructorComparator(); 40 41 private int compare(CtConstructor m1, CtConstructor m2) { 42 try { 43 CtClass[] args1 = m1.getParameterTypes(); 44 CtClass[] args2 = m2.getParameterTypes(); 45 if (args1.length < args2.length) return -1; 46 if (args1.length > args2.length) return 1; 47 for (int i = 0; i < args1.length; i++) { 48 String name1 = 49 Descriptor.toJavaName(Descriptor.toJvmName(args1[i])); 50 String name2 = 51 Descriptor.toJavaName(Descriptor.toJvmName(args2[i])); 52 int result = name1.compareTo(name2); 53 if (result != 0) return result; 54 } 55 } 56 catch (Exception e) { 57 throw new RuntimeException (e); 58 } 59 60 throw new Error (); 62 } 63 64 public int compare(Object o1, Object o2) { 65 return compare((CtConstructor) o1, (CtConstructor) o2); 66 } 67 68 } 69 | Popular Tags |