1 33 package net.sf.jga.parser; 34 35 import java.util.HashMap ; 36 import java.util.Map ; 37 38 45 46 public class ParserUtils { 47 private ParserUtils (){} 48 49 53 static private Map boxedTypes = new HashMap (); 54 static private Map unboxedTypes = new HashMap (); 55 static private Map boxFunctors = new HashMap (); 56 static private Map unboxFunctors = new HashMap (); 57 58 static { 59 boxedTypes.put(Boolean.TYPE, Boolean .class); 60 boxedTypes.put(Character.TYPE, Character .class); 61 boxedTypes.put(Byte.TYPE, Byte .class); 62 boxedTypes.put(Short.TYPE, Short .class); 63 boxedTypes.put(Integer.TYPE, Integer .class); 64 boxedTypes.put(Long.TYPE, Long .class); 65 boxedTypes.put(Float.TYPE, Float .class); 66 boxedTypes.put(Double.TYPE, Double .class); 67 boxedTypes.put(Void.TYPE, Object .class); 68 69 unboxedTypes.put(Boolean .class, Boolean.TYPE); 70 unboxedTypes.put(Character .class, Character.TYPE); 71 unboxedTypes.put(Byte .class, Byte.TYPE); 72 unboxedTypes.put(Short .class, Short.TYPE); 73 unboxedTypes.put(Integer .class, Integer.TYPE); 74 unboxedTypes.put(Long .class, Long.TYPE); 75 unboxedTypes.put(Float .class, Float.TYPE); 76 unboxedTypes.put(Double .class, Double.TYPE); 77 78 } 79 80 84 static public Class getBoxedType(Class type) { 85 Class c = (Class ) boxedTypes.get(type); 86 return (c == null) ? type : c; 87 } 88 89 90 94 static public Class getUnboxedType(Class type) { 95 Class c = (Class ) unboxedTypes.get(type); 96 return (c == null) ? type : c; 97 } 98 99 100 103 104 static public boolean isBoxedType(Class primitive, Class boxedType) { 105 return primitive.isPrimitive() && (primitive == getUnboxedType(boxedType)); 106 } 107 108 112 static public String getSimpleName(Class clasz) { 113 String hostName = ""; 114 String delim = "."; 115 116 Class host = clasz.getDeclaringClass(); 117 if (host != null) { 118 hostName += getSimpleName(host) + "."; 119 delim = "$"; 120 } 121 122 String name = clasz.getName(); 123 String simple = name.substring(name.lastIndexOf(delim)+1); 124 125 return hostName + simple; 126 } 127 } 128 | Popular Tags |