/** * Set the generic signature of the method. * It represents parameter types including type variables. * See {@link javassist.CtClass#setGenericSignature(String)} * for a code sample. * * @param sig a new generic signature. * @see javassist.bytecode.SignatureAttribute.MethodSignature#encode() * @since 3.17 */ public void setGenericSignature(String sig) { declaringClass.checkModify(); methodInfo.addAttribute(new SignatureAttribute(methodInfo.getConstPool(), sig)); }
/** * Adds an attribute. The attribute is saved in the class file. * * <p>Note that an attribute is a data block specified by * the class file format. It is not an annotation. * See {@link javassist.bytecode.AttributeInfo}. * * @param name attribute name * @param data attribute value */ public void setAttribute(String name, byte[] data) { declaringClass.checkModify(); methodInfo.addAttribute(new AttributeInfo(methodInfo.getConstPool(), name, data)); }
/** * Set the generic signature of the method. * It represents parameter types including type variables. * See {@link javassist.CtClass#setGenericSignature(String)} * for a code sample. * * @param sig a new generic signature. * @see javassist.bytecode.SignatureAttribute.MethodSignature#encode() * @since 3.17 */ @Override public void setGenericSignature(String sig) { declaringClass.checkModify(); methodInfo.addAttribute(new SignatureAttribute(methodInfo.getConstPool(), sig)); }
/** * Adds an attribute. The attribute is saved in the class file. * * <p>Note that an attribute is a data block specified by * the class file format. It is not an annotation. * See {@link javassist.bytecode.AttributeInfo}. * * @param name attribute name * @param data attribute value */ @Override public void setAttribute(String name, byte[] data) { declaringClass.checkModify(); methodInfo.addAttribute(new AttributeInfo(methodInfo.getConstPool(), name, data)); }
ctMethod.getMethodInfo().addAttribute(attr);
private static String addBodyMethod(CtClassType clazz, ClassFile classfile, CtMethod src) throws BadBytecode, CannotCompileException { Hashtable bodies = clazz.getHiddenMethods(); String bodyname = (String)bodies.get(src); if (bodyname == null) { do { bodyname = addedWrappedMethod + clazz.getUniqueNumber(); } while (classfile.getMethod(bodyname) != null); ClassMap map = new ClassMap(); map.put(src.getDeclaringClass().getName(), clazz.getName()); MethodInfo body = new MethodInfo(classfile.getConstPool(), bodyname, src.getMethodInfo2(), map); int acc = body.getAccessFlags(); body.setAccessFlags(AccessFlag.setPrivate(acc)); body.addAttribute(new SyntheticAttribute(classfile.getConstPool())); // a stack map is copied. rebuilding it is not needed. classfile.addMethod(body); bodies.put(src, bodyname); CtMember.Cache cache = clazz.hasMemberCache(); if (cache != null) cache.addMethod(new CtMethod(body, clazz)); } return bodyname; }
= new MethodInfo(cp, MethodInfo.nameInit, consDesc); minfo.setAccessFlags(0); minfo.addAttribute(new SyntheticAttribute(cp)); ExceptionsAttribute ea = orig.getExceptionsAttribute(); if (ea != null) minfo.addAttribute(ea.copy(cp, null));
mtd.getMethodInfo().addAttribute(attr);
= new MethodInfo(cp, accName, accDesc); minfo.setAccessFlags(AccessFlag.STATIC); minfo.addAttribute(new SyntheticAttribute(cp)); ExceptionsAttribute ea = orig.getExceptionsAttribute(); if (ea != null) minfo.addAttribute(ea.copy(cp, null));
private static String addBodyMethod(CtClassType clazz, ClassFile classfile, CtMethod src) throws BadBytecode, CannotCompileException { Map<CtMethod,String> bodies = clazz.getHiddenMethods(); String bodyname = bodies.get(src); if (bodyname == null) { do { bodyname = addedWrappedMethod + clazz.getUniqueNumber(); } while (classfile.getMethod(bodyname) != null); ClassMap map = new ClassMap(); map.put(src.getDeclaringClass().getName(), clazz.getName()); MethodInfo body = new MethodInfo(classfile.getConstPool(), bodyname, src.getMethodInfo2(), map); int acc = body.getAccessFlags(); body.setAccessFlags(AccessFlag.setPrivate(acc)); body.addAttribute(new SyntheticAttribute(classfile.getConstPool())); // a stack map is copied. rebuilding it is not needed. classfile.addMethod(body); bodies.put(src, bodyname); CtMember.Cache cache = clazz.hasMemberCache(); if (cache != null) cache.addMethod(new CtMethod(body, clazz)); } return bodyname; }
= new MethodInfo(cp, MethodInfo.nameInit, consDesc); minfo.setAccessFlags(0); minfo.addAttribute(new SyntheticAttribute(cp)); ExceptionsAttribute ea = orig.getExceptionsAttribute(); if (ea != null) minfo.addAttribute(ea.copy(cp, null));
= new MethodInfo(cp, accName, accDesc); minfo.setAccessFlags(AccessFlag.STATIC); minfo.addAttribute(new SyntheticAttribute(cp)); ExceptionsAttribute ea = orig.getExceptionsAttribute(); if (ea != null) minfo.addAttribute(ea.copy(cp, null));
minfo.addAttribute(new SyntheticAttribute(cp)); Bytecode code = new Bytecode(cp); if (is_static) {
minfo.addAttribute(new SyntheticAttribute(cp)); Bytecode code = new Bytecode(cp); int reg;
minfo.addAttribute(new SyntheticAttribute(cp)); Bytecode code = new Bytecode(cp); if (is_static) {
minfo.addAttribute(new SyntheticAttribute(cp)); Bytecode code = new Bytecode(cp); int reg;
newMethod.getMethodInfo().addAttribute((SignatureAttribute) attr);
public static void addSyntheticAttribute(MethodInfo info) { ConstPool cp = info.getConstPool(); info.addAttribute(new SyntheticAttribute(cp)); }
private void copySignature(MethodInfo src, MethodInfo dest) { SignatureAttribute attribute = (SignatureAttribute) src.getAttribute(SignatureAttribute.tag); if (attribute != null) { @SuppressWarnings("unchecked") HashMap map = new HashMap(); dest.addAttribute(attribute.copy(dest.getConstPool(), map)); } }
private void copySignature(CtMethod src, CtMethod dest) { javassist.bytecode.MethodInfo srcInfo = src.getMethodInfo2(); javassist.bytecode.MethodInfo destInfo = dest.getMethodInfo2(); SignatureAttribute sig = (SignatureAttribute)srcInfo.getAttribute(SignatureAttribute.tag); if (sig != null) { destInfo.addAttribute(sig.copy(destInfo.getConstPool(), EMPTY_HASHMAP)); } }