1 29 30 package com.caucho.bytecode; 31 32 35 abstract public class JClass extends JAnnotationObject implements JType { 36 public static final JClass VOID = new JClassWrapper(void.class); 37 public static final JClass BOOLEAN = new JClassWrapper(boolean.class); 38 public static final JClass BYTE = new JClassWrapper(byte.class); 39 public static final JClass SHORT = new JClassWrapper(short.class); 40 public static final JClass INT = new JClassWrapper(int.class); 41 public static final JClass LONG = new JClassWrapper(long.class); 42 public static final JClass FLOAT = new JClassWrapper(float.class); 43 public static final JClass DOUBLE = new JClassWrapper(double.class); 44 public static final JClass CHAR = new JClassWrapper(char.class); 45 public static final JClass STRING = new JClassWrapper(String .class); 46 public static final JClass OBJECT = new JClassWrapper(Object .class); 47 48 51 abstract public String getName(); 52 53 56 public Class getJavaClass() 57 { 58 try { 59 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 60 61 return Class.forName(getName(), false, loader); 62 } catch (Exception e) { 63 throw new RuntimeException (e); 64 } 65 } 66 67 70 public JType []getActualTypeArguments() 71 { 72 return new JType[0]; 73 } 74 75 78 public JClass getRawType() 79 { 80 return this; 81 } 82 83 86 abstract public boolean isPrimitive(); 87 88 91 abstract public boolean isPublic(); 92 93 96 abstract public boolean isAbstract(); 97 98 101 abstract public boolean isFinal(); 102 103 106 abstract public boolean isInterface(); 107 108 111 abstract public JClass getSuperClass(); 112 113 116 abstract public JClass []getInterfaces(); 117 118 121 abstract public boolean isArray(); 122 123 126 public JClass getComponentType() 127 { 128 return null; 129 } 130 131 134 abstract public boolean isAssignableTo(Class cl); 135 136 139 abstract public boolean isAssignableFrom(Class cl); 140 141 144 abstract public boolean isAssignableFrom(JClass cl); 145 146 149 abstract public JMethod []getDeclaredMethods(); 150 151 154 abstract public JMethod []getMethods(); 155 156 159 abstract public JMethod []getConstructors(); 160 161 164 public JMethod getConstructor(JClass []param) 165 { 166 JMethod []ctors = getConstructors(); 167 168 loop: 169 for (int i = 0; i < ctors.length; i++) { 170 JClass []args = ctors[i].getParameterTypes(); 171 172 if (args.length != param.length) 173 continue loop; 174 175 for (int j = 0; j < args.length; j++) 176 if (! args[i].equals(param[j])) 177 continue loop; 178 179 return ctors[i]; 180 } 181 182 return null; 183 } 184 185 188 abstract public JMethod getMethod(String name, JClass []param); 189 190 193 abstract public JField []getDeclaredFields(); 194 195 198 abstract public JField []getFields(); 199 200 203 public String getPrintName() 204 { 205 if (isArray()) 206 return getComponentType().getPrintName() + "[]"; 207 else 208 return getName().replace('$', '.'); 209 } 210 211 214 public String getShortName() 215 { 216 if (isArray()) 217 return getComponentType().getShortName() + "[]"; 218 else { 219 String name = getName().replace('$', '.'); 220 221 int p = name.lastIndexOf('.'); 222 223 if (p >= 0) 224 return name.substring(p + 1); 225 else 226 return name; 227 } 228 } 229 230 233 public int hashCode() 234 { 235 return getName().hashCode(); 236 } 237 238 241 public boolean equals(Object o) 242 { 243 if (o == this) 244 return true; 245 else if (o == null || getClass() != o.getClass()) 246 return false; 247 248 JClass jClass = (JClass) o; 249 250 return getName().equals(jClass.getName()); 252 } 253 254 public String toString() 255 { 256 return "JClass[" + getName() + "]"; 257 } 258 } 259 | Popular Tags |