1 22 package org.jboss.proxy.compiler; 23 24 import org.apache.bcel.Constants; 25 import org.apache.bcel.generic.BasicType; 26 import org.apache.bcel.generic.ObjectType; 27 import org.apache.bcel.generic.Type; 28 29 import org.jboss.util.UnreachableStatementException; 30 31 53 public abstract class Utility 54 extends org.apache.bcel.classfile.Utility 55 { 56 74 public static Type getType(Class clazz) { 75 if (clazz.isPrimitive()) { 76 if (clazz.equals(Boolean.TYPE) ) { 77 return Type.BOOLEAN; 78 } 79 else if (clazz.equals(Byte.TYPE) ) { 80 return Type.BYTE; 81 } 82 else if (clazz.equals(Character.TYPE) ) { 83 return Type.CHAR; 84 } 85 else if (clazz.equals(Double.TYPE) ) { 86 return Type.DOUBLE; 87 } 88 else if (clazz.equals(Float.TYPE) ) { 89 return Type.FLOAT; 90 } 91 else if (clazz.equals(Integer.TYPE) ) { 92 return Type.INT; 93 } 94 else if (clazz.equals(Long.TYPE) ) { 95 return Type.LONG; 96 } 97 else if (clazz.equals(Short.TYPE) ) { 98 return Type.SHORT; 99 } 100 else if (clazz.equals(Void.TYPE) ) { 101 return Type.VOID; 102 } 103 104 throw new UnreachableStatementException(); 106 } 107 108 String name = clazz.getName(); 110 111 if (clazz.isArray()) { 112 return Type.getType(name); 113 } 114 115 return new ObjectType(name); 116 } 117 118 124 public static Type[] getTypes(Class [] classes) { 125 Type[] types = new Type[classes.length]; 126 127 for (int i = 0; i < classes.length; i++) { 128 types[i] = getType(classes[i]); 129 } 130 131 return types; 132 } 133 134 150 public static String getObjectEquivalentClassName(BasicType t) { 151 switch (t.getType()) { 152 case Constants.T_INT: 153 return "java.lang.Integer"; 154 155 case Constants.T_SHORT: 156 return "java.lang.Short"; 157 158 case Constants.T_BOOLEAN: 159 return "java.lang.Boolean"; 160 161 case Constants.T_CHAR: 162 return "java.lang.Character"; 163 164 case Constants.T_BYTE: 165 return "java.lang.Byte"; 166 167 case Constants.T_FLOAT: 168 return "java.lang.Float"; 169 170 case Constants.T_DOUBLE: 171 return "java.lang.Double"; 172 173 case Constants.T_LONG: 174 return "java.lang.Long"; 175 176 default: 177 throw new IllegalArgumentException ("Unexpected Type: " + t); 178 } 179 } 180 181 } 182 | Popular Tags |