Search in sources :

Example 1 with RemappingMethodAdapter

use of org.objectweb.asm.commons.RemappingMethodAdapter in project Galacticraft by micdoodle8.

the class MCStripTransformer method transform.

public static byte[] transform(byte[] bytes) {
    ClassNode cnode = ASMHelper.createClassNode(bytes, ClassReader.EXPAND_FRAMES);
    boolean changed = false;
    Iterator<MethodNode> it = cnode.methods.iterator();
    while (it.hasNext()) {
        MethodNode mnode = it.next();
        ReferenceDetector r = new ReferenceDetector();
        mnode.accept(new RemappingMethodAdapter(mnode.access, mnode.desc, new MethodVisitor(Opcodes.ASM4) {
        }, r));
        if (r.found) {
            it.remove();
            changed = true;
        }
    }
    if (changed) {
        bytes = ASMHelper.createBytes(cnode, 0);
    }
    return bytes;
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) MethodNode(org.objectweb.asm.tree.MethodNode) RemappingMethodAdapter(org.objectweb.asm.commons.RemappingMethodAdapter) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 2 with RemappingMethodAdapter

use of org.objectweb.asm.commons.RemappingMethodAdapter in project drill by axbaretto.

the class MergeAdapter method visitEnd.

@Override
public void visitEnd() {
    // add all the fields of the class we're going to merge.
    for (Iterator<?> it = classToMerge.fields.iterator(); it.hasNext(); ) {
        // Special handling for nested classes. Drill uses non-static nested
        // "inner" classes in some templates. Prior versions of Drill would
        // create the generated nested classes as static, then this line
        // would copy the "this$0" field to convert the static nested class
        // into a non-static inner class. However, that approach is not
        // compatible with plain-old Java compilation. Now, Drill generates
        // the nested classes as non-static inner classes. As a result, we
        // do not want to copy the hidden fields; we'll end up with two if
        // we do.
        FieldNode field = (FieldNode) it.next();
        if (!field.name.startsWith("this$")) {
            field.accept(this);
        }
    }
    // add all the methods that we to include.
    for (Iterator<?> it = classToMerge.methods.iterator(); it.hasNext(); ) {
        MethodNode mn = (MethodNode) it.next();
        if (mn.name.equals("<init>")) {
            continue;
        }
        String[] exceptions = new String[mn.exceptions.size()];
        mn.exceptions.toArray(exceptions);
        MethodVisitor mv = cv.visitMethod(mn.access | Modifier.FINAL, mn.name, mn.desc, mn.signature, exceptions);
        if (verifyBytecode) {
            mv = new CheckMethodVisitorFsm(api, mv);
        }
        mn.instructions.resetLabels();
        // mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, new
        // SimpleRemapper("org.apache.drill.exec.compile.ExampleTemplate", "Bunky")));
        ClassSet top = set;
        while (top.parent != null) {
            top = top.parent;
        }
        mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, new SimpleRemapper(top.precompiled.slash, top.generated.slash)));
    }
    super.visitEnd();
}
Also used : SimpleRemapper(org.objectweb.asm.commons.SimpleRemapper) FieldNode(org.objectweb.asm.tree.FieldNode) MethodNode(org.objectweb.asm.tree.MethodNode) ClassSet(org.apache.drill.exec.compile.ClassTransformer.ClassSet) RemappingMethodAdapter(org.objectweb.asm.commons.RemappingMethodAdapter) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 3 with RemappingMethodAdapter

use of org.objectweb.asm.commons.RemappingMethodAdapter in project CodeChickenLib by Chicken-Bones.

the class MCStripTransformer method transform.

public static byte[] transform(byte[] bytes) {
    ClassNode cnode = ASMHelper.createClassNode(bytes, ClassReader.EXPAND_FRAMES);
    boolean changed = false;
    Iterator<MethodNode> it = cnode.methods.iterator();
    while (it.hasNext()) {
        MethodNode mnode = it.next();
        ReferenceDetector r = new ReferenceDetector();
        mnode.accept(new RemappingMethodAdapter(mnode.access, mnode.desc, new MethodVisitor(Opcodes.ASM4) {
        }, r));
        if (r.found) {
            it.remove();
            changed = true;
        }
    }
    if (changed)
        bytes = ASMHelper.createBytes(cnode, 0);
    return bytes;
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) MethodNode(org.objectweb.asm.tree.MethodNode) RemappingMethodAdapter(org.objectweb.asm.commons.RemappingMethodAdapter) MethodVisitor(org.objectweb.asm.MethodVisitor)

Aggregations

MethodVisitor (org.objectweb.asm.MethodVisitor)3 RemappingMethodAdapter (org.objectweb.asm.commons.RemappingMethodAdapter)3 MethodNode (org.objectweb.asm.tree.MethodNode)3 ClassNode (org.objectweb.asm.tree.ClassNode)2 ClassSet (org.apache.drill.exec.compile.ClassTransformer.ClassSet)1 SimpleRemapper (org.objectweb.asm.commons.SimpleRemapper)1 FieldNode (org.objectweb.asm.tree.FieldNode)1