Example usage for org.objectweb.asm MethodVisitor visitParameterAnnotation

List of usage examples for org.objectweb.asm MethodVisitor visitParameterAnnotation

Introduction

In this page you can find the example usage for org.objectweb.asm MethodVisitor visitParameterAnnotation.

Prototype

public AnnotationVisitor visitParameterAnnotation(final int parameter, final String descriptor,
        final boolean visible) 

Source Link

Document

Visits an annotation of a parameter this method.

Usage

From source file:co.paralleluniverse.fibers.instrument.InstrumentMethod.java

License:Open Source License

private static void dumpParameterAnnotations(MethodVisitor mv, List[] parameterAnnotations, boolean visible) {
    for (int i = 0; i < parameterAnnotations.length; i++) {
        if (parameterAnnotations[i] != null) {
            for (Object o : parameterAnnotations[i]) {
                AnnotationNode an = (AnnotationNode) o;
                an.accept(mv.visitParameterAnnotation(i, an.desc, visible));
            }//w w  w  . j  ava  2  s .  com
        }
    }
}

From source file:com.facebook.buck.java.abi.AnnotationMirror.java

License:Apache License

public void appendTo(MethodVisitor method, int parameterIndex) {
    AnnotationVisitor visitor = method.visitParameterAnnotation(parameterIndex, desc, visible);
    visitValues(visitor);//from  www. j av  a  2  s.  c  o  m
    visitor.visitEnd();
}

From source file:com.facebook.presto.byteCode.AnnotationDefinition.java

License:Apache License

public void visitParameterAnnotation(int parameterIndex, MethodVisitor visitor) {
    AnnotationVisitor annotationVisitor = visitor.visitParameterAnnotation(parameterIndex, type.getType(),
            true);/* w w w. j av a2  s  .com*/
    visit(annotationVisitor);
    annotationVisitor.visitEnd();
}

From source file:com.googlecode.ddom.weaver.asm.MethodVisitorTee.java

License:Apache License

public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) {
    AnnotationVisitor result = null;// w w  w .  j  a va 2s .com
    for (MethodVisitor visitor : visitors) {
        result = AnnotationVisitorTee.mergeVisitors(result,
                visitor.visitParameterAnnotation(parameter, desc, visible));
    }
    return result;
}

From source file:egovframework.rte.itl.webservice.service.impl.EgovWebServiceClassLoaderImpl.java

License:Apache License

private byte[] createServiceEndpointInterfaceClass(
        final ServiceEndpointInterfaceInfo serviceEndpointInterfaceInfo) throws ClassNotFoundException {
    // CHECKSTYLE:OFF
    String serviceEndpointInterfaceClassName = getServiceEndpointInterfaceClassName(
            serviceEndpointInterfaceInfo.getServiceName());

    String asmServiceEndpointInterfaceClassName = serviceEndpointInterfaceClassName.replace('.', '/');
    // CHECKSTYLE:ON
    // ClassWriter classWriter = new ClassWriter(false);
    ClassWriter classWriter = new ClassWriter(0);
    classWriter.visit(V1_5, // version
            ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, // access
            asmServiceEndpointInterfaceClassName, // name
            null, // signature
            "java/lang/Object", // superName
            null); // interfaces

    // Create Annotation
    AnnotationVisitor annotationVisitor = classWriter.visitAnnotation(DESC_OF_WEB_SERVICE, true);
    annotationVisitor.visit("targetNamespace", serviceEndpointInterfaceInfo.getNamespace());
    annotationVisitor.visitEnd();/*  w ww  .  j  a v a2 s. co  m*/
    annotationVisitor = classWriter.visitAnnotation(DESC_OF_SOAP_BINDING, true);
    annotationVisitor.visitEnum("parameterStyle", DESC_OF_SOAP_BINDING_PARAMETER_STYLE, "BARE");

    // Create Method
    ServiceParamInfo returnInfo = serviceEndpointInterfaceInfo.getReturnInfo();
    Collection<ServiceParamInfo> paramInfos = serviceEndpointInterfaceInfo.getParamInfos();

    StringBuffer desc = new StringBuffer("(");
    StringBuffer signature = new StringBuffer("(");

    for (ServiceParamInfo info : paramInfos) {
        Class<?> paramClass = loadClass(info.getType());
        org.objectweb.asm.Type paramType = org.objectweb.asm.Type.getType(paramClass);
        String paramSign = paramType.getDescriptor();
        if (info.getMode().equals(OUT) || info.getMode().equals(INOUT)) {
            if (paramClass.isPrimitive()) {
                paramClass = wrapperClasses.get(paramClass);
                paramType = org.objectweb.asm.Type.getType(paramClass);
                paramSign = paramType.getDescriptor();
            }
            paramClass = Holder.class;
            paramType = TYPE_OF_HOLDER;
            paramSign = "Ljavax/xml/ws/Holder<" + paramSign + ">;";
        }
        desc.append(paramType.getDescriptor());
        signature.append(paramSign);
    }
    desc.append(")");
    signature.append(")");
    // CHECKSTYLE:OFF
    org.objectweb.asm.Type returnType = (returnInfo == null ? returnType = org.objectweb.asm.Type.VOID_TYPE
            : org.objectweb.asm.Type.getType(loadClass(returnInfo.getType())));
    // CHECKSTYLE:ON
    desc.append(returnType.getDescriptor());
    signature.append(returnType.getDescriptor());

    MethodVisitor methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, // access
            serviceEndpointInterfaceInfo.getOperationName(), // name
            desc.toString(), // desc
            signature.toString(), // signature
            null); // exceptions

    // @WebMethod
    annotationVisitor = methodVisitor.visitAnnotation(DESC_OF_WEB_METHOD, true);
    annotationVisitor.visit("operationName", serviceEndpointInterfaceInfo.getOperationName());
    annotationVisitor.visitEnd();

    // @WebResult
    if (returnInfo != null) {
        annotationVisitor = methodVisitor.visitAnnotation(DESC_OF_WEB_RESULT, true);
        annotationVisitor.visit("name", returnInfo.getName());
        // annotationVisitor.visit("partName",
        // returnInfo.getName());
        annotationVisitor.visit("header", returnInfo.isHeader());
        annotationVisitor.visit("targetNamespace", serviceEndpointInterfaceInfo.getNamespace());
        annotationVisitor.visitEnd();
    }

    // @WebParam
    int index = 0;
    for (ServiceParamInfo info : serviceEndpointInterfaceInfo.getParamInfos()) {
        annotationVisitor = methodVisitor.visitParameterAnnotation(index, DESC_OF_WEB_PARAM, true);
        annotationVisitor.visit("name", info.getName());
        // annotationVisitor.visit("partName",
        // info.getName());
        annotationVisitor.visitEnum("mode", DESC_OF_WEB_PARAM_MODE, info.getMode().toString());
        annotationVisitor.visit("header", info.isHeader());
        annotationVisitor.visit("targetNamespace", serviceEndpointInterfaceInfo.getNamespace());
        annotationVisitor.visitEnd();
        index++;
    }
    methodVisitor.visitEnd();

    // Class finalize
    classWriter.visitEnd();

    // try
    // {
    // DataOutputStream dos = new DataOutputStream(
    // new FileOutputStream("EgovType" +
    // serviceInfo.getServiceName() + ".class"));
    // dos.write(classWriter.toByteArray());
    // dos.close();
    // }
    // catch (IOException e)
    // {
    // e.printStackTrace();
    // }

    return classWriter.toByteArray();
}

From source file:kilim.analysis.MethodFlow.java

License:Open Source License

@Override
/**/*  w  w  w . j ava 2  s. c om*/
 * Copied verbatim from MethodNode except for the instruction processing.
 * Unlike MethodNode, we don't keep LabelNodes inline, so we need to 
 * do visitLabel ourselves.
 * 
 * @param mv a method visitor.
 */
public void accept(final MethodVisitor mv) {
    // visits the method attributes
    int i, j, n;
    if (annotationDefault != null) {
        AnnotationVisitor av = mv.visitAnnotationDefault();
        acceptAnnotation(av, null, annotationDefault);
        av.visitEnd();
    }
    n = visibleAnnotations == null ? 0 : visibleAnnotations.size();
    for (i = 0; i < n; ++i) {
        AnnotationNode an = (AnnotationNode) visibleAnnotations.get(i);
        an.accept(mv.visitAnnotation(an.desc, true));
    }
    n = invisibleAnnotations == null ? 0 : invisibleAnnotations.size();
    for (i = 0; i < n; ++i) {
        AnnotationNode an = (AnnotationNode) invisibleAnnotations.get(i);
        an.accept(mv.visitAnnotation(an.desc, false));
    }
    n = visibleParameterAnnotations == null ? 0 : visibleParameterAnnotations.length;
    for (i = 0; i < n; ++i) {
        List<?> l = visibleParameterAnnotations[i];
        if (l == null) {
            continue;
        }
        for (j = 0; j < l.size(); ++j) {
            AnnotationNode an = (AnnotationNode) l.get(j);
            an.accept(mv.visitParameterAnnotation(i, an.desc, true));
        }
    }
    n = invisibleParameterAnnotations == null ? 0 : invisibleParameterAnnotations.length;
    for (i = 0; i < n; ++i) {
        List<?> l = invisibleParameterAnnotations[i];
        if (l == null) {
            continue;
        }
        for (j = 0; j < l.size(); ++j) {
            AnnotationNode an = (AnnotationNode) l.get(j);
            an.accept(mv.visitParameterAnnotation(i, an.desc, false));
        }
    }
    n = attrs == null ? 0 : attrs.size();
    for (i = 0; i < n; ++i) {
        mv.visitAttribute((Attribute) attrs.get(i));
    }
    // visits the method's code
    if (instructions.size() > 0) {
        mv.visitCode();
        // visits try catch blocks
        for (i = 0; i < tryCatchBlocks.size(); ++i) {
            ((TryCatchBlockNode) tryCatchBlocks.get(i)).accept(mv);
        }
        // visits instructions
        for (i = 0; i < instructions.size(); ++i) {
            Label l = getLabelAt(i);
            if (l != null) {
                mv.visitLabel(l);
            }
            ((AbstractInsnNode) instructions.get(i)).accept(mv);
        }
        Label l = getLabelAt(instructions.size());
        if (l != null) {
            mv.visitLabel(l);
        }
        // visits local variables
        n = localVariables == null ? 0 : localVariables.size();
        for (i = 0; i < n; ++i) {
            ((LocalVariableNode) localVariables.get(i)).accept(mv);
        }
        // visits line numbers
        /* TODO this was in ASM 2.3.3 but not 3.x or 4.0, find a substitute or remove
                    n = lineNumbers == null ? 0 : lineNumbers.size();
                    for (i = 0; i < n; ++i) {
        ((LineNumberNode) lineNumbers.get(i)).accept(mv);
                    }
        */
        // visits maxs
        mv.visitMaxs(maxStack, maxLocals);
    }
    mv.visitEnd();
}

From source file:kilim.analysis.MethodWeaver.java

License:Open Source License

private void visitAttrs(MethodVisitor mv) {
    MethodFlow mf = methodFlow;/* w ww  . ja va2 s.  c  o m*/
    // visits the method attributes
    int i, j, n;
    if (mf.annotationDefault != null) {
        AnnotationVisitor av = mv.visitAnnotationDefault();
        MethodFlow.acceptAnnotation(av, null, mf.annotationDefault);
        av.visitEnd();
    }
    n = mf.visibleAnnotations == null ? 0 : mf.visibleAnnotations.size();
    for (i = 0; i < n; ++i) {
        AnnotationNode an = (AnnotationNode) mf.visibleAnnotations.get(i);
        an.accept(mv.visitAnnotation(an.desc, true));
    }
    n = mf.invisibleAnnotations == null ? 0 : mf.invisibleAnnotations.size();
    for (i = 0; i < n; ++i) {
        AnnotationNode an = (AnnotationNode) mf.invisibleAnnotations.get(i);
        an.accept(mv.visitAnnotation(an.desc, false));
    }
    n = mf.visibleParameterAnnotations == null ? 0 : mf.visibleParameterAnnotations.length;
    for (i = 0; i < n; ++i) {
        List<?> l = mf.visibleParameterAnnotations[i];
        if (l == null) {
            continue;
        }
        for (j = 0; j < l.size(); ++j) {
            AnnotationNode an = (AnnotationNode) l.get(j);
            an.accept(mv.visitParameterAnnotation(i, an.desc, true));
        }
    }
    n = mf.invisibleParameterAnnotations == null ? 0 : mf.invisibleParameterAnnotations.length;
    for (i = 0; i < n; ++i) {
        List<?> l = mf.invisibleParameterAnnotations[i];
        if (l == null) {
            continue;
        }
        for (j = 0; j < l.size(); ++j) {
            AnnotationNode an = (AnnotationNode) l.get(j);
            an.accept(mv.visitParameterAnnotation(i, an.desc, false));
        }
    }
    n = mf.attrs == null ? 0 : mf.attrs.size();
    for (i = 0; i < n; ++i) {
        mv.visitAttribute((Attribute) mf.attrs.get(i));
    }
}

From source file:org.adjective.stout.writer.ByteCodeWriter.java

License:Apache License

private void writeMethod(ClassVisitor cv, ClassDescriptor cls, MethodDescriptor method) {
    String[] exceptions = new String[method.getExceptions().length];
    for (int i = 0; i < exceptions.length; i++) {
        exceptions[i] = getInternalName(method.getExceptions()[i]);
    }//from ww w.  j a  va2 s .  c o  m

    String signature = null; // @TODO
    final MethodVisitor mv = visitMethod(cv, method, exceptions, signature);

    for (AnnotationDescriptor annotation : method.getAnnotations()) {
        AnnotationVisitor av = mv.visitAnnotation(Type.getDescriptor(annotation.getType()),
                annotation.isRuntime());
        processAnnotation(annotation, av);
    }

    Parameter[] parameters = method.getParameters();
    for (int i = 0; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        AnnotationDescriptor[] annotations = parameter.getAnnotations();
        for (AnnotationDescriptor annotation : annotations) {
            AnnotationVisitor av = mv.visitParameterAnnotation(i, Type.getDescriptor(annotation.getType()),
                    annotation.isRuntime());
            processAnnotation(annotation, av);
        }
    }

    Code body = method.getBody();
    if (method.getModifiers().contains(ElementModifier.ABSTRACT)) {
        if (body != null) {
            throw new IllegalStateException("The abstract method " + method + " cannot have a body");
        }
    } else {
        if (body == null) {
            throw new IllegalStateException(
                    "The method " + method + " is not abstract, but does not have a body");
        }
        mv.visitCode();

        CodeStack stack = new CodeStack(cls, method, mv);
        Block block = stack.pushBlock();
        if (!isStatic(method)) {
            block.declareVariable(new Variable("#this", cls));
        }

        for (Parameter parameter : parameters) {
            block.declareVariable(new Variable(parameter.getName(), parameter.getType()));
        }

        InstructionCollector collector = new AbstractInstructionCollector() {
            private int _line;

            public void add(Instruction instruction, int line) {
                if (line != 0 && line != _line) {
                    _line = line;
                    Label label = new Label();
                    mv.visitLabel(label);
                    mv.visitLineNumber(line, label);
                }
                instruction.accept(mv);
            }
        };
        try {
            body.getInstructions(stack, collector);
        } catch (StoutException e) {
            throw new WriterException("In class " + cls.getPackage() + "." + cls.getName()
                    + ", cannot write method " + method.getName(), e);
        }
        stack.popBlock(block);
        stack.declareVariableInfo();
    }

    mv.visitMaxs(0, 0);
    mv.visitEnd();
}

From source file:org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.AnnotationPlayback.java

License:Apache License

public void accept(final MethodVisitor visitor, final int index) {
    AnnotationVisitor av = visitor.visitParameterAnnotation(index, m_annotationType.getDescriptor(), true);
    if (av != null) {
        accept(av);//from  w  w w  .  ja  v a 2  s  . co m
    }
}

From source file:org.apache.felix.ipojo.manipulator.metadata.annotation.model.parser.replay.AnnotationVisitorPlayback.java

License:Apache License

public void accept(final MethodVisitor visitor, int index) {
    AnnotationVisitor av = visitor.visitParameterAnnotation(index, m_desc, m_visible);
    if (av != null) {
        accept(av);/*from  w  w  w. j  a va  2 s. c  o  m*/
    }
}