/** * Returns the <code>CtClass</code> object representing the return * type specified by the given descriptor. * * @param desc descriptor * @param cp the class pool used for obtaining * a <code>CtClass</code> object. */ public static CtClass getReturnType(String desc, ClassPool cp) throws NotFoundException { int i = desc.indexOf(')'); if (i < 0) return null; else { CtClass[] type = new CtClass[1]; toCtClass(cp, desc, i + 1, type, 0); return type[0]; } }
/** * Returns the <code>CtClass</code> object representing the return * type specified by the given descriptor. * * @param desc descriptor * @param cp the class pool used for obtaining * a <code>CtClass</code> object. */ public static CtClass getReturnType(String desc, ClassPool cp) throws NotFoundException { int i = desc.indexOf(')'); if (i < 0) return null; CtClass[] type = new CtClass[1]; toCtClass(cp, desc, i + 1, type, 0); return type[0]; }
/** * Returns a <code>CtClass</code> object representing the type * specified by the given descriptor. * * <p>This method works even if the package-class separator is * not <code>/</code> but <code>.</code> (period). For example, * it accepts <code>Ljava.lang.Object;</code> * as well as <code>Ljava/lang/Object;</code>. * * @param desc descriptor. * @param cp the class pool used for obtaining * a <code>CtClass</code> object. */ public static CtClass toCtClass(String desc, ClassPool cp) throws NotFoundException { CtClass[] clazz = new CtClass[1]; int res = toCtClass(cp, desc, 0, clazz, 0); if (res >= 0) return clazz[0]; else { // maybe, you forgot to surround the class name with // L and ;. It violates the protocol, but I'm tolerant... return cp.get(desc.replace('/', '.')); } }
/** * Returns a <code>CtClass</code> object with the given name. * This is almost equivalent to <code>get(String)</code> except * that classname can be an array-type "descriptor" (an encoded * type name) such as <code>[Ljava/lang/Object;</code>. * * <p>Using this method is not recommended; this method should be * used only to obtain the <code>CtClass</code> object * with a name returned from <code>getClassInfo</code> in * <code>javassist.bytecode.ClassPool</code>. <code>getClassInfo</code> * returns a fully-qualified class name but, if the class is an array * type, it returns a descriptor. * * @param classname a fully-qualified class name or a descriptor * representing an array type. * @see #get(String) * @see javassist.bytecode.ConstPool#getClassInfo(int) * @see javassist.bytecode.Descriptor#toCtClass(String, ClassPool) * @since 3.8.1 */ public CtClass getCtClass(String classname) throws NotFoundException { if (classname.charAt(0) == '[') return Descriptor.toCtClass(classname, this); else return get(classname); }
/** * Returns a <code>CtClass</code> object representing the type * specified by the given descriptor. * * <p>This method works even if the package-class separator is * not <code>/</code> but <code>.</code> (period). For example, * it accepts <code>Ljava.lang.Object;</code> * as well as <code>Ljava/lang/Object;</code>. * * @param desc descriptor. * @param cp the class pool used for obtaining * a <code>CtClass</code> object. */ public static CtClass toCtClass(String desc, ClassPool cp) throws NotFoundException { CtClass[] clazz = new CtClass[1]; int res = toCtClass(cp, desc, 0, clazz, 0); if (res >= 0) return clazz[0]; // maybe, you forgot to surround the class name with // L and ;. It violates the protocol, but I'm tolerant... return cp.get(desc.replace('/', '.')); }
/** * Returns a <code>CtClass</code> object with the given name. * This is almost equivalent to <code>get(String)</code> except * that classname can be an array-type "descriptor" (an encoded * type name) such as <code>[Ljava/lang/Object;</code>. * * <p>Using this method is not recommended; this method should be * used only to obtain the <code>CtClass</code> object * with a name returned from <code>getClassInfo</code> in * <code>javassist.bytecode.ClassPool</code>. <code>getClassInfo</code> * returns a fully-qualified class name but, if the class is an array * type, it returns a descriptor. * * @param classname a fully-qualified class name or a descriptor * representing an array type. * @see #get(String) * @see javassist.bytecode.ConstPool#getClassInfo(int) * @see javassist.bytecode.Descriptor#toCtClass(String, ClassPool) * @since 3.8.1 */ public CtClass getCtClass(String classname) throws NotFoundException { if (classname.charAt(0) == '[') return Descriptor.toCtClass(classname, this); else return get(classname); }
/** * Returns the <code>CtClass</code> objects representing the parameter * types specified by the given descriptor. * * @param desc descriptor * @param cp the class pool used for obtaining * a <code>CtClass</code> object. */ public static CtClass[] getParameterTypes(String desc, ClassPool cp) throws NotFoundException { if (desc.charAt(0) != '(') return null; else { int num = numOfParameters(desc); CtClass[] args = new CtClass[num]; int n = 0; int i = 1; do { i = toCtClass(cp, desc, i, args, n++); } while (i > 0); return args; } }
/** * Returns the type of the field. */ public CtClass getType() throws NotFoundException { return Descriptor.toCtClass(fieldInfo.getDescriptor(), declaringClass.getClassPool()); }
/** * Returns the <code>CtClass</code> objects representing the parameter * types specified by the given descriptor. * * @param desc descriptor * @param cp the class pool used for obtaining * a <code>CtClass</code> object. */ public static CtClass[] getParameterTypes(String desc, ClassPool cp) throws NotFoundException { if (desc.charAt(0) != '(') return null; int num = numOfParameters(desc); CtClass[] args = new CtClass[num]; int n = 0; int i = 1; do { i = toCtClass(cp, desc, i, args, n++); } while (i > 0); return args; }
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); }
/** * Returns the type of the field. */ public CtClass getType() throws NotFoundException { return Descriptor.toCtClass(fieldInfo.getDescriptor(), declaringClass.getClassPool()); }
private Type typeFromDesc(String desc) throws BadBytecode { CtClass clazz = null; try { clazz = Descriptor.toCtClass(desc, classPool); } 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 + "]: " + desc); return Type.get(clazz); }
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); }
private Type typeFromDesc(String desc) throws BadBytecode { CtClass clazz = null; try { clazz = Descriptor.toCtClass(desc, classPool); } 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 + "]: " + desc); return Type.get(clazz); }
/** * Returns the type of array components. If the created array is * a two-dimensional array of <tt>int</tt>, * the type returned by this method is * not <tt>int[]</tt> but <tt>int</tt>. */ public CtClass getComponentType() throws NotFoundException { if (opcode == Opcode.NEWARRAY) { int atype = iterator.byteAt(currentPos + 1); return getPrimitiveType(atype); } else if (opcode == Opcode.ANEWARRAY || opcode == Opcode.MULTIANEWARRAY) { int index = iterator.u16bitAt(currentPos + 1); String desc = getConstPool().getClassInfo(index); int dim = Descriptor.arrayDimension(desc); desc = Descriptor.toArrayComponent(desc, dim); return Descriptor.toCtClass(desc, thisClass.getClassPool()); } else throw new RuntimeException("bad opcode: " + opcode); }
/** * Returns the type of array components. If the created array is * a two-dimensional array of <code>int</code>, * the type returned by this method is * not <code>int[]</code> but <code>int</code>. */ public CtClass getComponentType() throws NotFoundException { if (opcode == Opcode.NEWARRAY) { int atype = iterator.byteAt(currentPos + 1); return getPrimitiveType(atype); } else if (opcode == Opcode.ANEWARRAY || opcode == Opcode.MULTIANEWARRAY) { int index = iterator.u16bitAt(currentPos + 1); String desc = getConstPool().getClassInfo(index); int dim = Descriptor.arrayDimension(desc); desc = Descriptor.toArrayComponent(desc, dim); return Descriptor.toCtClass(desc, thisClass.getClassPool()); } else throw new RuntimeException("bad opcode: " + opcode); }
code.addReturn(Descriptor.toCtClass(fieldType, pool)); minfo.setCodeAttribute(code.toCodeAttribute()); cf.addMethod(minfo);
throw new RuntimeException("bad opcode: " + opcode); retType = Descriptor.toCtClass(desc, thisClass.getClassPool());
CtClass retType; CtClass fieldType = Descriptor.toCtClass(constPool.getFieldrefType(index), thisClass.getClassPool()); boolean read = isReader();