Example usage for org.objectweb.asm Opcodes ASM5

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

Introduction

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

Prototype

int ASM5

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

Click Source Link

Usage

From source file:org.apache.asterix.runtime.evaluators.staticcodegen.GatherEvaluatorCreationVisitor.java

License:Apache License

public GatherEvaluatorCreationVisitor(String ownerPrefix) {
    super(Opcodes.ASM5);
    this.ownerPrefix = ownerPrefix;
}

From source file:org.apache.asterix.runtime.evaluators.staticcodegen.GatherEvaluatorCreationVisitor.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if (!name.equals(METHOD_NAME)) {
        return null;
    }//ww w .ja v  a  2  s  .c om
    return new MethodVisitor(Opcodes.ASM5, null) {

        @Override
        public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
            if (opcode != Opcodes.INVOKESPECIAL) {
                return;
            }
            if (owner.startsWith(ownerPrefix)) {
                createdEvaluatorClassNames.add(owner);
            }
        }
    };

}

From source file:org.apache.asterix.runtime.evaluators.staticcodegen.GatherEvaluatorFactoryCreationVisitor.java

License:Apache License

public GatherEvaluatorFactoryCreationVisitor(String ownerPrefix) {
    super(Opcodes.ASM5);
    this.ownerPrefix = ownerPrefix;
}

From source file:org.apache.asterix.runtime.evaluators.staticcodegen.GatherEvaluatorFactoryCreationVisitor.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if (!name.equals(METHOD_NAME)) {
        return null;
    }//from ww w  .  java  2  s . co  m
    return new MethodVisitor(Opcodes.ASM5, null) {

        @Override
        public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
            if (opcode != Opcodes.INVOKESPECIAL) {
                return;
            }
            if (owner.startsWith(ownerPrefix)) {
                createdEvaluatorFactoryClassNames.add(owner);
            }
        }
    };
}

From source file:org.apache.asterix.runtime.evaluators.staticcodegen.GatherInnerClassVisitor.java

License:Apache License

public GatherInnerClassVisitor() {
    super(Opcodes.ASM5);
}

From source file:org.apache.asterix.runtime.evaluators.staticcodegen.RenameClassVisitor.java

License:Apache License

public RenameClassVisitor(ClassVisitor downStreamVisitor, List<Pair<String, String>> nameMapping) {
    super(Opcodes.ASM5, downStreamVisitor);
    this.nameMapping = nameMapping;
}

From source file:org.apache.asterix.runtime.evaluators.staticcodegen.RenameClassVisitor.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor mv = cv.visitMethod(access, name, applyMapping(desc), applyMapping(signature), exceptions);
    if (mv != null) {
        return new MethodVisitor(Opcodes.ASM5, mv) {

            @Override/*from   w  w w  .  j a  va2s.  c  o  m*/
            public void visitFieldInsn(int opcode, String owner, String name, String desc) {
                mv.visitFieldInsn(opcode, applyMapping(owner), applyMapping(name), applyMapping(desc));
            }

            @Override
            public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
                mv.visitMethodInsn(opcode, applyMapping(owner), name, applyMapping(desc), itf);
            }

            @Override
            public void visitLocalVariable(String name, String desc, String signature, Label start, Label end,
                    int index) {
                mv.visitLocalVariable(name, applyMapping(desc), applyMapping(signature), start, end, index);
            }

            @Override
            public void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack) {
                if (local != null) {
                    for (int index = 0; index < local.length; ++index) {
                        if (local[index] instanceof String) {
                            local[index] = applyMapping((String) local[index]);
                        }
                    }
                }
                mv.visitFrame(type, nLocal, local, nStack, stack);
            }

            @Override
            public void visitTypeInsn(int opcode, String type) {
                mv.visitTypeInsn(opcode, applyMapping(type));
            }

        };
    }
    return null;
}

From source file:org.apache.cassandra.cql3.functions.UDFByteCodeVerifier.java

License:Apache License

public Set<String> verify(byte[] bytes) {
    Set<String> errors = new TreeSet<>(); // it's a TreeSet for unit tests
    ClassVisitor classVisitor = new ClassVisitor(Opcodes.ASM5) {
        public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
            errors.add("field declared: " + name);
            return null;
        }// w w w  .  jav  a2  s. c  o  m

        public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                String[] exceptions) {
            if ("<init>".equals(name) && CTOR_SIG.equals(desc)) {
                if (Opcodes.ACC_PUBLIC != access)
                    errors.add("constructor not public");
                // allowed constructor - JavaUDF(TypeCodec returnCodec, TypeCodec[] argCodecs)
                return new ConstructorVisitor(errors);
            }
            if ("executeImpl".equals(name) && "(ILjava/util/List;)Ljava/nio/ByteBuffer;".equals(desc)) {
                if (Opcodes.ACC_PROTECTED != access)
                    errors.add("executeImpl not protected");
                // the executeImpl method - ByteBuffer executeImpl(int protocolVersion, List<ByteBuffer> params)
                return new ExecuteImplVisitor(errors);
            }
            if ("<clinit>".equals(name)) {
                errors.add("static initializer declared");
            } else {
                errors.add("not allowed method declared: " + name + desc);
                return new ExecuteImplVisitor(errors);
            }
            return null;
        }

        public void visit(int version, int access, String name, String signature, String superName,
                String[] interfaces) {
            if (!JAVA_UDF_NAME.equals(superName)) {
                errors.add("class does not extend " + JavaUDF.class.getName());
            }
            if (access != (Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER)) {
                errors.add("class not public final");
            }
            super.visit(version, access, name, signature, superName, interfaces);
        }

        public void visitInnerClass(String name, String outerName, String innerName, int access) {
            errors.add("class declared as inner class");
            super.visitInnerClass(name, outerName, innerName, access);
        }
    };

    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classVisitor, ClassReader.SKIP_DEBUG);

    return errors;
}

From source file:org.apache.commons.javaflow.providers.asm5.ContinuableClassVisitor.java

License:Apache License

public ContinuableClassVisitor(final ClassVisitor cv, final ContinuableClassInfoResolver cciResolver,
        final byte[] originalBytes) {
    super(Opcodes.ASM5, cv);
    this.cciResolver = cciResolver;
    this.originalBytes = originalBytes;
}

From source file:org.apache.commons.javaflow.providers.asm5.ContinuableMethodNode.java

License:Apache License

public ContinuableMethodNode(int access, String name, String desc, String signature, String[] exceptions,
        String className, ContinuableClassInfoResolver cciResolver, MethodVisitor mv) {
    super(Opcodes.ASM5, access, name, desc, signature, exceptions);
    this.className = className;
    this.cciResolver = cciResolver;
    this.mv = mv;
}