1 19 20 package org.netbeans.api.java.comparators; 21 22 import org.openide.src.Type; 23 import java.util.Comparator ; 24 25 class TypeComparator extends JavaElementComparator { 26 27 private Comparator idComparator; 28 29 protected TypeComparator(int type) { 30 super(type); 31 } 32 33 private static final int T_BOOLEAN = 0x0001; 35 private static final int T_INT = 0x0002; 36 private static final int T_CHAR = 0x0003; 37 private static final int T_BYTE = 0x0004; 38 private static final int T_SHORT = 0x0005; 39 private static final int T_LONG = 0x0006; 40 private static final int T_FLOAT = 0x0007; 41 private static final int T_DOUBLE = 0x0008; 42 private static final int T_VOID = 0x0009; 43 44 private static final int T_CLASS = 0x0010; 45 private static final int T_ARRAY = 0x0020; 46 47 private int getKind(Type t) 48 { if (t.isArray()) 49 return T_ARRAY; 50 else if (t.isClass()) 51 return T_CLASS; 52 else if (t==Type.BOOLEAN) 53 return T_BOOLEAN; 54 else if (t==Type.BYTE) 55 return T_BYTE; 56 else if (t==Type.CHAR) 57 return T_CHAR; 58 else if (t==Type.DOUBLE) 59 return T_DOUBLE; 60 else if (t==Type.FLOAT) 61 return T_FLOAT; 62 else if (t==Type.INT) 63 return T_INT; 64 else if (t==Type.LONG) 65 return T_LONG; 66 else if (t==Type.SHORT) 67 return T_SHORT; 68 else if (t==Type.VOID) 69 return T_VOID; 70 return 0; } 72 73 public int compare(Object o1, Object o2) { 74 Type t1=(Type)o1; 75 Type t2=(Type)o2; 76 int t1_kind=getKind(t1); 77 int t2_kind=getKind(t2); 78 79 if (t1_kind!=t2_kind) { 80 if (t1_kind>t2_kind) return 1; 81 else return -1; 82 } 83 if (t1.isArray()) 84 return compare(t1.getElementType(),t2.getElementType()); 85 else if (t1.isClass()) { 86 if (idComparator == null) 87 idComparator=IdentifierComparator.createComparator(type); 88 return idComparator.compare(t1.getClassName(),t2.getClassName()); 89 } 90 else 91 return 0; 92 } 93 94 static Comparator createComparator(int type) { 95 return new TypeComparator(type); 96 } 97 98 } 99 100 | Popular Tags |