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

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

Introduction

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

Prototype

@Override
    public void visitOuterClass(final String owner, final String name, final String descriptor) 

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
 *//*from   w  ww  .  ja v a 2s.  c  o m*/
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();
}