Search in sources :

Example 1 with AnnotationVisitor

use of com.newrelic.agent.deps.org.objectweb.asm.AnnotationVisitor in project newrelic-java-agent by newrelic.

the class WeavingClassLoader method usesWeaver.

public static boolean usesWeaver(byte[] classBytes) {
    ClassReader reader = new ClassReader(classBytes);
    final boolean[] foundWeaveAnnotation = { false };
    reader.accept(new ClassVisitor(WeaveUtils.ASM_API_LEVEL) {

        @Override
        public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
            if (desc.equals(WeaveClassInfo.WEAVE_DESC) || desc.equals(WeaveClassInfo.SKIP_IF_PRESENT_DESC) || desc.equals(SCALA_WEAVE_DESC) || desc.equals(WeaveClassInfo.WEAVE_ANNOTATED_TYPE_DESC)) {
                foundWeaveAnnotation[0] = true;
            }
            return null;
        }

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
            return new MethodVisitor(WeaveUtils.ASM_API_LEVEL, mv) {

                @Override
                public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
                    if (desc.equals(WeaveClassInfo.WEAVE_ANNOTATED_TYPE_DESC)) {
                        foundWeaveAnnotation[0] = true;
                    }
                    return null;
                }
            };
        }
    }, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
    return foundWeaveAnnotation[0];
}
Also used : AnnotationVisitor(com.newrelic.agent.deps.org.objectweb.asm.AnnotationVisitor) ClassReader(com.newrelic.agent.deps.org.objectweb.asm.ClassReader) ClassVisitor(com.newrelic.agent.deps.org.objectweb.asm.ClassVisitor) MethodVisitor(com.newrelic.agent.deps.org.objectweb.asm.MethodVisitor)

Aggregations

AnnotationVisitor (com.newrelic.agent.deps.org.objectweb.asm.AnnotationVisitor)1 ClassReader (com.newrelic.agent.deps.org.objectweb.asm.ClassReader)1 ClassVisitor (com.newrelic.agent.deps.org.objectweb.asm.ClassVisitor)1 MethodVisitor (com.newrelic.agent.deps.org.objectweb.asm.MethodVisitor)1