public CtClass getSuperclass() throws NotFoundException { return pool.get(javaLangObject); }
private static Type lookupType(String name) { try { return new Type(ClassPool.getDefault().get(name)); } catch (NotFoundException e) { throw new RuntimeException(e); } }
public CtClass[] getInterfaces() throws NotFoundException { if (interfaces == null) { Class[] intfs = Object[].class.getInterfaces(); // java.lang.Cloneable and java.io.Serializable. // If the JVM is CLDC, intfs is empty. interfaces = new CtClass[intfs.length]; for (int i = 0; i < intfs.length; i++) interfaces[i] = pool.get(intfs[i].getName()); } return interfaces; }
/** * Main method. * * @param args <code>args[0]</code> is the class file name. */ public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java javassist.tools.framedump <fully-qualified class name>"); return; } ClassPool pool = ClassPool.getDefault(); CtClass clazz = pool.get(args[0]); System.out.println("Frame Dump of " + clazz.getName() + ":"); FramePrinter.print(clazz, System.out); } }
/** * Returns the class of the created object. */ private CtClass getCtClass() throws NotFoundException { return thisClass.getClassPool().get(newTypeName); }
public CtClass getCtClass() { CtClass clazz = component.getCtClass(); if (clazz == null) return null; ClassPool pool = clazz.getClassPool(); if (pool == null) pool = ClassPool.getDefault(); String name = arrayName(clazz.getName(), dims); try { return pool.get(name); } catch (NotFoundException e) { throw new RuntimeException(e); } }
/** * Inserts hooks for intercepting accesses to the fields declared * in reflective classes. */ public void onLoad(ClassPool pool, String classname) throws CannotCompileException, NotFoundException { CtClass clazz = pool.get(classname); clazz.instrument(converter); }
private CtClass toCtClass(Class rtclass) throws NotFoundException { String name; if (!rtclass.isArray()) name = rtclass.getName(); else { StringBuffer sbuf = new StringBuffer(); do { sbuf.append("[]"); rtclass = rtclass.getComponentType(); } while(rtclass.isArray()); sbuf.insert(0, rtclass.getName()); name = sbuf.toString(); } return classPool.get(name); }
public CtClass getComponentType() throws NotFoundException { String name = getName(); return pool.get(name.substring(0, name.length() - 2)); }
/** * Reads a class file and obtains a compile-time method. * * @param classname the class name * @param methodname the method name * @see CtClass#getDeclaredMethod(String) */ public CtMethod getMethod(String classname, String methodname) throws NotFoundException { CtClass c = get(classname); return c.getDeclaredMethod(methodname); }
/** * Returns the class of the target object, * which the method is called on. */ protected CtClass getCtClass() throws NotFoundException { return thisClass.getClassPool().get(getClassName()); }
private Type getType(String name) throws BadBytecode { try { return Type.get(classPool.get(name)); } catch (NotFoundException e) { throw new BadBytecode("Could not find class [pos = " + lastPos + "]: " + name); } }
public CtClass getSuperclass() throws NotFoundException { String supername = getClassFile2().getSuperclass(); if (supername == null) return null; else return classPool.get(supername); }
/** * Returns the class in which the field is declared. */ private CtClass getCtClass() throws NotFoundException { return thisClass.getClassPool().get(getClassName()); }
public CtClass[] getInterfaces() throws NotFoundException { String[] ifs = getClassFile2().getInterfaces(); int num = ifs.length; CtClass[] ifc = new CtClass[num]; for (int i = 0; i < num; ++i) ifc[i] = classPool.get(ifs[i]); return ifc; }
/** * Does the class implement Serializable? */ private static boolean isSerializable(CtClass clazz) throws NotFoundException { ClassPool pool = clazz.getClassPool(); return clazz.subtypeOf(pool.get("java.io.Serializable")); }
static String isField(ClassPool pool, ConstPool cp, CtClass fclass, String fname, boolean is_private, int index) { if (!cp.getFieldrefName(index).equals(fname)) return null; try { CtClass c = pool.get(cp.getFieldrefClassName(index)); if (c == fclass || (!is_private && isFieldInSuper(c, fclass, fname))) return cp.getFieldrefType(index); } catch (NotFoundException e) {} return null; }
/** * Obtains exceptions that this method/constructor may throw. * * @return a zero-length array if there is no throws clause. */ public CtClass[] getExceptionTypes() throws NotFoundException { String[] exceptions; ExceptionsAttribute ea = methodInfo.getExceptionsAttribute(); if (ea == null) exceptions = null; else exceptions = ea.getExceptions(); return declaringClass.getClassPool().get(exceptions); }
private Type createArray(Type rootComponent, int dims) { if (rootComponent instanceof MultiType) return new MultiArrayType((MultiType) rootComponent, dims); String name = arrayName(rootComponent.clazz.getName(), dims); Type type; try { type = Type.get(getClassPool(rootComponent).get(name)); } catch (NotFoundException e) { throw new RuntimeException(e); } return type; }
private Type resolveClassInfo(String info) throws BadBytecode { CtClass clazz = null; try { if (info.charAt(0) == '[') { clazz = Descriptor.toCtClass(info, classPool); } else { clazz = classPool.get(info); } } catch (NotFoundException e) { throw new BadBytecode("Could not find class in descriptor [pos = " + lastPos + "]: " + e.getMessage()); } if (clazz == null) throw new BadBytecode("Could not obtain type for descriptor [pos = " + lastPos + "]: " + info); return Type.get(clazz); }