Example usage for org.objectweb.asm Opcodes ACC_PUBLIC

List of usage examples for org.objectweb.asm Opcodes ACC_PUBLIC

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ACC_PUBLIC.

Prototype

int ACC_PUBLIC

To view the source code for org.objectweb.asm Opcodes ACC_PUBLIC.

Click Source Link

Usage

From source file:com.tencent.tinker.build.auxiliaryclass.AuxiliaryClassGenerator.java

License:Open Source License

private static void generateClass(String dotClassName, File fileOut) throws IOException {
    final String classDesc = dotClassName.replace('.', '/');
    ClassWriter cw = new ClassWriter(0);
    cw.visit(Opcodes.V1_7, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, classDesc, null, "java/lang/Object", null);
    cw.visitSource(fileOut.getName(), null);
    {/*from ww  w .  ja  v a2 s . co  m*/
        MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    cw.visitEnd();
    byte[] classBytes = cw.toByteArray();

    OutputStream os = null;
    try {
        os = new BufferedOutputStream(new FileOutputStream(fileOut));
        os.write(classBytes);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (Exception e) {
                // Ignored.
            }
        }
    }
}

From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java

License:MIT License

/**
 * Generate a new method "boolean name()", which returns a constant value.
 *
 * @param clazz Class to add method to//from w w  w.  ja v a  2 s. c  o m
 * @param name Name of method
 * @param retval Return value of method
 */
public static void generateBooleanMethodConst(ClassNode clazz, String name, boolean retval) {
    MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()Z",
            null, null);
    InsnList code = method.instructions;

    code.add(ASMHelper.pushIntConstant(retval ? 1 : 0));
    code.add(new InsnNode(Opcodes.IRETURN));

    clazz.methods.add(method);
}

From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java

License:MIT License

/**
 * Generate a new method "int name()", which returns a constant value.
 *
 * @param clazz Class to add method to//from   w  w  w.  j  ava  2s .com
 * @param name Name of method
 * @param retval Return value of method
 */
public static void generateIntegerMethodConst(ClassNode clazz, String name, short retval) {
    MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()I",
            null, null);
    InsnList code = method.instructions;

    code.add(ASMHelper.pushIntConstant(retval));
    code.add(new InsnNode(Opcodes.IRETURN));

    clazz.methods.add(method);
}

From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java

License:MIT License

/**
 * Generate a forwarding method of the form
 * "T name() { return this.forward(); }".
 *
 * @param clazz Class to generate new method on
 * @param name Name of method to generate
 * @param forwardname Name of method to call
 * @param rettype Return type of method//from w w w. ja  va  2 s.  c om
 */
public static void generateSelfForwardingMethod(ClassNode clazz, String name, String forwardname,
        Type rettype) {
    MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name,
            "()" + rettype.getDescriptor(), null, null);

    ASMHelper.populateSelfForwardingMethod(method, forwardname, rettype, Type.getObjectType(clazz.name));

    clazz.methods.add(method);
}

From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java

License:MIT License

/**
 * Generate a forwarding method of the form
 * "static T name(S object) { return object.forward(); }".
 *
 * @param clazz Class to generate new method on
 * @param name Name of method to generate
 * @param forwardname Name of method to call
 * @param rettype Return type of method//  w ww  .  j a va 2  s.c o  m
 * @param argtype Argument type
 */
public static void generateStaticForwardingMethod(ClassNode clazz, String name, String forwardname,
        Type rettype, Type argtype) {
    MethodNode method = new MethodNode(Opcodes.ASM5,
            Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name,
            "()" + rettype.getDescriptor(), null, null);

    ASMHelper.populateSelfForwardingMethod(method, forwardname, rettype, argtype);

    clazz.methods.add(method);
}

From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java

License:MIT License

/**
 * Generate a forwarding method of the form
 * "T name() { return Class.forward(this); }".
 *
 * @param clazz Class to generate new method on
 * @param name Name of method to generate
 * @param forwardname Name of method to call
 * @param rettype Return type of method//from w  w  w. j  a v a2s  .c om
 * @param fowardtype Forward type
 */
public static void generateForwardingToStaticMethod(ClassNode clazz, String name, String forwardname,
        Type rettype, Type fowardtype) {
    MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name,
            "()" + rettype.getDescriptor(), null, null);

    ASMHelper.populateForwardingToStaticMethod(method, forwardname, rettype, Type.getObjectType(clazz.name),
            fowardtype);

    clazz.methods.add(method);
}

From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java

License:MIT License

/**
 * Generate a forwarding method of the form
 * "T name() { return Class.forward(this); }".
 *
 * @param clazz Class to generate new method on
 * @param name Name of method to generate
 * @param forwardname Name of method to call
 * @param rettype Return type of method/*from w w w  .  java  2 s . c  o m*/
 * @param fowardtype Forward type
 * @param thistype Type to treat 'this' as for overload searching purposes
 */
public static void generateForwardingToStaticMethod(ClassNode clazz, String name, String forwardname,
        Type rettype, Type fowardtype, Type thistype) {
    MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name,
            "()" + rettype.getDescriptor(), null, null);

    ASMHelper.populateForwardingToStaticMethod(method, forwardname, rettype, thistype, fowardtype);

    clazz.methods.add(method);
}

From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java

License:MIT License

/**
 * Generate a forwarding method of the form
 * "T name(S object) { return object.forward(); }".
 *
 * @param clazz Class to generate new method on
 * @param name Name of method to generate
 * @param forwardname Name of method to call
 * @param rettype Return type of method/*from w ww  .  j  ava2 s  . c o  m*/
 * @param argtype Type of object to call method on
 */
public static void generateForwardingMethod(ClassNode clazz, String name, String forwardname, Type rettype,
        Type argtype) {
    MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name,
            "()" + rettype.getDescriptor(), null, null);

    ASMHelper.populateForwardingMethod(method, forwardname, rettype, argtype, Type.getObjectType(clazz.name));

    clazz.methods.add(method);
}

From source file:com.xruby.compiler.codegen.CgUtil.java

License:BSD License

public static void createImplicitConstructor(ClassVisitor cv, Type superType) {
    GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, CONSTRUCTOR, null, null, cv);
    mg.visitCode();//from w  w w  . j a  va 2  s .  co m
    mg.loadThis();
    mg.invokeConstructor(superType, CONSTRUCTOR);
    mg.returnValue();
    mg.endMethod();
}

From source file:com.xruby.compiler.codegen.FieldManager.java

License:BSD License

private void addNewFieldToClass(String name) {
    FieldVisitor fv = cv_.visitField(Opcodes.ACC_PUBLIC, decorateName(name),
            Type.getDescriptor(Types.RUBY_VALUE_CLASS), null, null);
    fv.visitEnd();//from   w w w. j  ava2s  .  c o  m
}