1 package net.sourceforge.pmd.util; 2 3 import java.math.BigDecimal ; 4 5 6 11 public class ClassUtil { 12 13 private ClassUtil() {}; 14 15 private static final TypeMap primitiveTypesByName = new TypeMap( new Class [] { 16 int.class, 17 byte.class, 18 long.class, 19 short.class, 20 float.class, 21 double.class, 22 char.class, 23 boolean.class, 24 }); 25 26 private static final TypeMap typesByNames = new TypeMap( new Class [] { 27 Integer .class, 28 Byte .class, 29 Long .class, 30 Short .class, 31 Float .class, 32 Double .class, 33 Character .class, 34 Boolean .class, 35 BigDecimal .class, 36 String .class, 37 Object .class, 38 }); 39 40 47 public static Class getPrimitiveTypeFor(String name) { 48 return primitiveTypesByName.typeFor(name); 49 } 50 51 57 public static Class getTypeFor(String shortName) { 58 59 Class type = typesByNames.typeFor(shortName); 60 if (type != null) return type; 61 62 type = primitiveTypesByName.typeFor(shortName); 63 if (type != null) return type; 64 65 return CollectionUtil.getCollectionTypeFor(shortName); 66 } 67 74 75 public static String withoutPackageName(String fullTypeName) { 76 77 int dotPos = fullTypeName.lastIndexOf('.'); 78 79 return dotPos > 0 ? 80 fullTypeName.substring(dotPos+1) : 81 fullTypeName; 82 } 83 } 84 | Popular Tags |