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

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

Introduction

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

Prototype

public void check(final int api) 

Source Link

Document

Checks that this class node is compatible with the given ASM API version.

Usage

From source file:io.awacs.plugin.springmvc.ServiceWrapper.java

License:Apache License

public void wrap(ClassNode cn) {
    cn.check(Opcodes.ASM5);
    List<MethodNode> methods = cn.methods;
    for (MethodNode method : methods) {
        List<AnnotationNode> annotationNodes = method.visibleAnnotations;
        if (annotationNodes != null) {
            for (AnnotationNode annotation : annotationNodes) {
                if (annotation.desc.equals("Lorg/springframework/web/bind/annotation/RequestMapping;")) {
                    appendedMethods.add(method);
                    break;
                }//  w ww .j a v  a 2 s.c om
            }
        }
    }
    for (MethodNode method : appendedMethods) {
        cn.methods.add(doProxy(cn, method));
    }
    //        cn.methods.addAll(appendedMethods.stream().map(method -> doProxy(cn, method))
    //                .collect(Collectors.toList()));
    appendedMethods.clear();
}

From source file:io.awacs.plugin.stacktrace.ClassTransformer.java

License:Apache License

public void visit(ClassNode cn) {
    cn.check(Opcodes.ASM5);
    //??/*from w  ww  .  ja va2 s.c o  m*/
    List<MethodNode> appended = new ArrayList<>(cn.methods.size());
    //??
    for (Object mn : cn.methods) {
        MethodNode src = (MethodNode) mn;
        //
        if (!filterMethod(cn, src)) {
            continue;
        }
        boolean terminated = isTerminatedMethod(src);

        if (terminated) {
            //copy exceptions
            String[] exceptions = null;
            if (src.exceptions != null) {
                exceptions = new String[src.exceptions.size()];
                for (int i = 0; i < src.exceptions.size(); i++) {
                    exceptions[i] = src.exceptions.get(i).toString();
                }
            }
            //declare method
            MethodNode proxy = new MethodNode(src.access, src.name, src.desc, src.signature, exceptions);
            appended.add(proxy);
            //copy method annotations
            List<AnnotationNode> methodAnns = null;
            if (src.visibleAnnotations != null) {
                methodAnns = new ArrayList<>(src.visibleAnnotations.size());
                methodAnns.addAll(src.visibleAnnotations);
            }
            proxy.visibleAnnotations = methodAnns;
            //copy parameter annotations
            List[] parameterAnns = null;
            if (src.visibleParameterAnnotations != null) {
                parameterAnns = new List[src.visibleParameterAnnotations.length];
                System.arraycopy(src.visibleParameterAnnotations, 0, parameterAnns, 0,
                        src.visibleParameterAnnotations.length);
            }
            proxy.visibleParameterAnnotations = parameterAnns;
            //clear origin method's annotation and change name
            int _slash = cn.name.lastIndexOf('/');
            //??
            src.name = src.name + "_origin_" + cn.name.substring(_slash + 1);
            src.access = src.access & ~Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE;
            src.visibleAnnotations = null;
            src.visibleLocalVariableAnnotations = null;
            transformTerminatedMethod(src, proxy, cn);
        } else {
            transformPlainMethod(src, cn);
        }
    }
    cn.methods.addAll(appended);
}