Search in sources :

Example 1 with MethodRemapper

use of org.objectweb.asm.commons.MethodRemapper in project drill by apache.

the class MergeAdapter method visitEnd.

@Override
public void visitEnd() {
    // add all the fields of the class we're going to merge.
    // 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.
    classToMerge.fields.stream().filter(field -> !field.name.startsWith("this$")).forEach(field -> field.accept(this));
    // add all the methods that we to include.
    for (MethodNode mn : classToMerge.methods) {
        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 MethodRemapper(mv, new SimpleRemapper(top.precompiled.slash, top.generated.slash)));
    }
    super.visitEnd();
}
Also used : ClassWriter(org.objectweb.asm.ClassWriter) MethodVisitor(org.objectweb.asm.MethodVisitor) Remapper(org.objectweb.asm.commons.Remapper) Logger(org.slf4j.Logger) Collection(java.util.Collection) FieldVisitor(org.objectweb.asm.FieldVisitor) ClassSet(org.apache.drill.exec.compile.ClassTransformer.ClassSet) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) SignatureHolder(org.apache.drill.exec.compile.sig.SignatureHolder) HashSet(java.util.HashSet) MethodNode(org.objectweb.asm.tree.MethodNode) ValueHolderReplacementVisitor(org.apache.drill.exec.compile.bytecode.ValueHolderReplacementVisitor) ClassReader(org.objectweb.asm.ClassReader) Modifier(java.lang.reflect.Modifier) MethodRemapper(org.objectweb.asm.commons.MethodRemapper) SimpleRemapper(org.objectweb.asm.commons.SimpleRemapper) ClassNode(org.objectweb.asm.tree.ClassNode) ClassVisitor(org.objectweb.asm.ClassVisitor) ClassRemapper(org.objectweb.asm.commons.ClassRemapper) SimpleRemapper(org.objectweb.asm.commons.SimpleRemapper) MethodNode(org.objectweb.asm.tree.MethodNode) ClassSet(org.apache.drill.exec.compile.ClassTransformer.ClassSet) MethodRemapper(org.objectweb.asm.commons.MethodRemapper) MethodVisitor(org.objectweb.asm.MethodVisitor)

Aggregations

Modifier (java.lang.reflect.Modifier)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ClassSet (org.apache.drill.exec.compile.ClassTransformer.ClassSet)1 ValueHolderReplacementVisitor (org.apache.drill.exec.compile.bytecode.ValueHolderReplacementVisitor)1 SignatureHolder (org.apache.drill.exec.compile.sig.SignatureHolder)1 ClassReader (org.objectweb.asm.ClassReader)1 ClassVisitor (org.objectweb.asm.ClassVisitor)1 ClassWriter (org.objectweb.asm.ClassWriter)1 FieldVisitor (org.objectweb.asm.FieldVisitor)1 MethodVisitor (org.objectweb.asm.MethodVisitor)1 ClassRemapper (org.objectweb.asm.commons.ClassRemapper)1 MethodRemapper (org.objectweb.asm.commons.MethodRemapper)1 Remapper (org.objectweb.asm.commons.Remapper)1 SimpleRemapper (org.objectweb.asm.commons.SimpleRemapper)1 ClassNode (org.objectweb.asm.tree.ClassNode)1 MethodNode (org.objectweb.asm.tree.MethodNode)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1