Example usage for org.objectweb.asm.tree ClassNode visitInnerClass

List of usage examples for org.objectweb.asm.tree ClassNode visitInnerClass

Introduction

In this page you can find the example usage for org.objectweb.asm.tree ClassNode visitInnerClass.

Prototype

@Override
    public void visitInnerClass(final String name, final String outerName, final String innerName,
            final int access) 

Source Link

Usage

From source file:me.qmx.jitescript.JiteClass.java

License:Apache License

/**
 * Convert this class representation to JDK bytecode
 *
 * @param version the desired JDK version
 * @return the bytecode representation of this class
 *//* w  w w.j ava2  s. c om*/
public byte[] toBytes(JDKVersion version) {
    ClassNode node = new ClassNode();
    node.version = version.getVer();
    node.access = this.access | ACC_SUPER;
    node.name = this.className;
    node.superName = this.superClassName;
    node.sourceFile = this.sourceFile;
    node.sourceDebug = this.sourceDebug;

    if (parentClassName != null) {
        node.visitOuterClass(parentClassName, null, null);
    }

    for (ChildEntry child : childClasses) {
        node.visitInnerClass(child.getClassName(), className, child.getInnerName(), child.getAccess());
    }

    if (!this.interfaces.isEmpty()) {
        node.interfaces.addAll(this.interfaces);
    }

    for (MethodDefinition def : methods) {
        node.methods.add(def.getMethodNode());
    }

    for (FieldDefinition def : fields) {
        node.fields.add(def.getFieldNode());
    }

    if (node.visibleAnnotations == null) {
        node.visibleAnnotations = new ArrayList<AnnotationNode>();
    }

    for (VisibleAnnotation a : annotations) {
        node.visibleAnnotations.add(a.getNode());
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    node.accept(cw);
    return cw.toByteArray();
}