Package javassist.bytecode

Examples of javassist.bytecode.Bytecode.toCodeAttribute()


                MethodInfo m = new MethodInfo(file.getConstPool(), Constants.ADDED_STATIC_METHOD_NAME, Constants.ADDED_STATIC_METHOD_DESCRIPTOR);
                m.setAccessFlags(AccessFlag.PUBLIC | AccessFlag.STATIC | AccessFlag.SYNTHETIC);
                b = new Bytecode(file.getConstPool(), 0, 3);
                b.add(Bytecode.ACONST_NULL);
                b.add(Bytecode.ARETURN);
                staticCodeAttribute = b.toCodeAttribute();
                m.setCodeAttribute(staticCodeAttribute);
                file.addMethod(m);

                m = new MethodInfo(file.getConstPool(), "<init>", Constants.ADDED_CONSTRUCTOR_DESCRIPTOR);
                m.setAccessFlags(AccessFlag.PUBLIC | AccessFlag.SYNTHETIC);
View Full Code Here


                m = new MethodInfo(file.getConstPool(), "<init>", Constants.ADDED_CONSTRUCTOR_DESCRIPTOR);
                m.setAccessFlags(AccessFlag.PUBLIC | AccessFlag.SYNTHETIC);
                b = new Bytecode(file.getConstPool(), 0, 4);
                if (ManipulationUtils.addBogusConstructorCall(file, b)) {
                    constructorCodeAttribute = b.toCodeAttribute();
                    m.setCodeAttribute(constructorCodeAttribute);
                    constructorCodeAttribute.setMaxLocals(6);
                    file.addMethod(m);
                }
            }
View Full Code Here

        MethodInfo method = new MethodInfo(proxy.getConstPool(), PROXY_METHOD_NAME, "(" + sb.toString() + ")V");
        Bytecode b = new Bytecode(proxy.getConstPool());
        b.add(Opcode.RETURN);
        method.setAccessFlags(AccessFlag.PUBLIC);
        method.setCodeAttribute(b.toCodeAttribute());
        method.getCodeAttribute().setMaxLocals(paramCount + 1);
        AttributeInfo an = annotations.copy(proxy.getConstPool(), Collections.EMPTY_MAP);
        method.addAttribute(an);

        try {
View Full Code Here

        } else {
            proxyBytecode.addInvokevirtual(className, Constants.ADDED_METHOD_NAME, "(I[Ljava/lang/Object;)Ljava/lang/Object;");
        }
        // cast it to the appropriate type and return it
        ManipulationUtils.MethodReturnRewriter.addReturnProxyMethod(mInfo.getDescriptor(), proxyBytecode);
        CodeAttribute ca = proxyBytecode.toCodeAttribute();
        ca.setMaxLocals(locals);

        ca.computeMaxStack();
        nInfo.setCodeAttribute(ca);
View Full Code Here

                    }
                } else {
                    b.add(Opcode.ACONST_NULL);
                    b.add(Opcode.ARETURN);
                }
                method.setCodeAttribute(b.toCodeAttribute());
                method.getCodeAttribute().computeMaxStack();
                method.getCodeAttribute().setMaxLocals(locals);
            }

            copyMethodAttributes(mInfo, method);
View Full Code Here

        Bytecode b = new Bytecode(file.getConstPool(), 5, 3);
        b.addNew("java.lang.NoSuchMethodError");
        b.add(Opcode.DUP);
        b.addInvokespecial("java.lang.NoSuchMethodError", "<init>", "()V");
        b.add(Bytecode.ATHROW);
        CodeAttribute ca = b.toCodeAttribute();
        m.setCodeAttribute(ca);

        try {
            ca.computeMaxStack();
            file.addMethod(m);
View Full Code Here

        b.add(Opcode.ALOAD_0);
        b.addInvokespecial("java.lang.Object", "<init>", "()V");
        b.add(Opcode.RETURN);
        MethodInfo method = new MethodInfo(proxy.getConstPool(), mInfo.getName(), mInfo.getDescriptor());
        method.setAccessFlags(mInfo.getAccessFlags());
        method.setCodeAttribute(b.toCodeAttribute());
        method.getCodeAttribute().computeMaxStack();
        method.getCodeAttribute().setMaxLocals(types.length + 1);

        copyMethodAttributes(mInfo, method);
View Full Code Here

        code.addExceptionHandler(125, 128, 23, 0);
        code.addExceptionHandler(60, 69, 69, 0);
        code.addExceptionHandler(111, 114, 69, 0);
        code.addExceptionHandler(79, 88, 88, 0);
        code.addExceptionHandler(106, 109, 88, 0);
        info.setCodeAttribute(code.toCodeAttribute());
        clazz.addMethod(method);
        clazz.writeFile("/tmp");
    }

    private static void addJump(Bytecode code, int opcode, int pos) {
View Full Code Here

    int field_index = cp.addFieldrefInfo(this_class_index,
                                         HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
    code.addIndex(field_index);
    // areturn // return the value of the field
    code.addOpcode(Opcode.ARETURN);
    minfo.setCodeAttribute(code.toCodeAttribute());
    minfo.setAccessFlags(AccessFlag.PUBLIC);
    classfile.addMethod(minfo);
  }

  private void addSetFieldHandlerMethod(ClassFile classfile)
View Full Code Here

    int field_index = cp.addFieldrefInfo(this_class_index,
                                         HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
    code.addIndex(field_index);
    // return
    code.addOpcode(Opcode.RETURN);
    minfo.setCodeAttribute(code.toCodeAttribute());
    minfo.setAccessFlags(AccessFlag.PUBLIC);
    classfile.addMethod(minfo);
  }

  private void addFieldHandledInterface(ClassFile classfile) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.