Search in sources :

Example 1 with MethodVisitor

use of org.apache.tapestry5.internal.plastic.asm.MethodVisitor in project tapestry-5 by apache.

the class MethodNode method accept.

/**
 * Makes the given method visitor visit this method.
 *
 * @param methodVisitor a method visitor.
 */
public void accept(final MethodVisitor methodVisitor) {
    // Visit the parameters.
    if (parameters != null) {
        for (int i = 0, n = parameters.size(); i < n; i++) {
            parameters.get(i).accept(methodVisitor);
        }
    }
    // Visit the annotations.
    if (annotationDefault != null) {
        AnnotationVisitor annotationVisitor = methodVisitor.visitAnnotationDefault();
        AnnotationNode.accept(annotationVisitor, null, annotationDefault);
        if (annotationVisitor != null) {
            annotationVisitor.visitEnd();
        }
    }
    if (visibleAnnotations != null) {
        for (int i = 0, n = visibleAnnotations.size(); i < n; ++i) {
            AnnotationNode annotation = visibleAnnotations.get(i);
            annotation.accept(methodVisitor.visitAnnotation(annotation.desc, true));
        }
    }
    if (invisibleAnnotations != null) {
        for (int i = 0, n = invisibleAnnotations.size(); i < n; ++i) {
            AnnotationNode annotation = invisibleAnnotations.get(i);
            annotation.accept(methodVisitor.visitAnnotation(annotation.desc, false));
        }
    }
    if (visibleTypeAnnotations != null) {
        for (int i = 0, n = visibleTypeAnnotations.size(); i < n; ++i) {
            TypeAnnotationNode typeAnnotation = visibleTypeAnnotations.get(i);
            typeAnnotation.accept(methodVisitor.visitTypeAnnotation(typeAnnotation.typeRef, typeAnnotation.typePath, typeAnnotation.desc, true));
        }
    }
    if (invisibleTypeAnnotations != null) {
        for (int i = 0, n = invisibleTypeAnnotations.size(); i < n; ++i) {
            TypeAnnotationNode typeAnnotation = invisibleTypeAnnotations.get(i);
            typeAnnotation.accept(methodVisitor.visitTypeAnnotation(typeAnnotation.typeRef, typeAnnotation.typePath, typeAnnotation.desc, false));
        }
    }
    if (visibleAnnotableParameterCount > 0) {
        methodVisitor.visitAnnotableParameterCount(visibleAnnotableParameterCount, true);
    }
    if (visibleParameterAnnotations != null) {
        for (int i = 0, n = visibleParameterAnnotations.length; i < n; ++i) {
            List<AnnotationNode> parameterAnnotations = visibleParameterAnnotations[i];
            if (parameterAnnotations == null) {
                continue;
            }
            for (int j = 0, m = parameterAnnotations.size(); j < m; ++j) {
                AnnotationNode annotation = parameterAnnotations.get(j);
                annotation.accept(methodVisitor.visitParameterAnnotation(i, annotation.desc, true));
            }
        }
    }
    if (invisibleAnnotableParameterCount > 0) {
        methodVisitor.visitAnnotableParameterCount(invisibleAnnotableParameterCount, false);
    }
    if (invisibleParameterAnnotations != null) {
        for (int i = 0, n = invisibleParameterAnnotations.length; i < n; ++i) {
            List<AnnotationNode> parameterAnnotations = invisibleParameterAnnotations[i];
            if (parameterAnnotations == null) {
                continue;
            }
            for (int j = 0, m = parameterAnnotations.size(); j < m; ++j) {
                AnnotationNode annotation = parameterAnnotations.get(j);
                annotation.accept(methodVisitor.visitParameterAnnotation(i, annotation.desc, false));
            }
        }
    }
    // Visit the non standard attributes.
    if (visited) {
        instructions.resetLabels();
    }
    if (attrs != null) {
        for (int i = 0, n = attrs.size(); i < n; ++i) {
            methodVisitor.visitAttribute(attrs.get(i));
        }
    }
    // Visit the code.
    if (instructions.size() > 0) {
        methodVisitor.visitCode();
        // Visits the try catch blocks.
        if (tryCatchBlocks != null) {
            for (int i = 0, n = tryCatchBlocks.size(); i < n; ++i) {
                tryCatchBlocks.get(i).updateIndex(i);
                tryCatchBlocks.get(i).accept(methodVisitor);
            }
        }
        // Visit the instructions.
        instructions.accept(methodVisitor);
        // Visits the local variables.
        if (localVariables != null) {
            for (int i = 0, n = localVariables.size(); i < n; ++i) {
                localVariables.get(i).accept(methodVisitor);
            }
        }
        // Visits the local variable annotations.
        if (visibleLocalVariableAnnotations != null) {
            for (int i = 0, n = visibleLocalVariableAnnotations.size(); i < n; ++i) {
                visibleLocalVariableAnnotations.get(i).accept(methodVisitor, true);
            }
        }
        if (invisibleLocalVariableAnnotations != null) {
            for (int i = 0, n = invisibleLocalVariableAnnotations.size(); i < n; ++i) {
                invisibleLocalVariableAnnotations.get(i).accept(methodVisitor, false);
            }
        }
        methodVisitor.visitMaxs(maxStack, maxLocals);
        visited = true;
    }
    methodVisitor.visitEnd();
}
Also used : AnnotationVisitor(org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor)

Example 2 with MethodVisitor

use of org.apache.tapestry5.internal.plastic.asm.MethodVisitor in project tapestry-5 by apache.

the class ClassRemapper method visitMethod.

@Override
public MethodVisitor visitMethod(final int access, final String name, final String descriptor, final String signature, final String[] exceptions) {
    String remappedDescriptor = remapper.mapMethodDesc(descriptor);
    MethodVisitor methodVisitor = super.visitMethod(access, remapper.mapMethodName(className, name, descriptor), remappedDescriptor, remapper.mapSignature(signature, false), exceptions == null ? null : remapper.mapTypes(exceptions));
    return methodVisitor == null ? null : createMethodRemapper(methodVisitor);
}
Also used : MethodVisitor(org.apache.tapestry5.internal.plastic.asm.MethodVisitor)

Example 3 with MethodVisitor

use of org.apache.tapestry5.internal.plastic.asm.MethodVisitor in project tapestry-5 by apache.

the class RemappingClassAdapter method visitMethod.

@Override
public MethodVisitor visitMethod(final int access, final String name, final String descriptor, final String signature, final String[] exceptions) {
    String newDescriptor = remapper.mapMethodDesc(descriptor);
    MethodVisitor methodVisitor = super.visitMethod(access, remapper.mapMethodName(className, name, descriptor), newDescriptor, remapper.mapSignature(signature, false), exceptions == null ? null : remapper.mapTypes(exceptions));
    return methodVisitor == null ? null : createRemappingMethodAdapter(access, newDescriptor, methodVisitor);
}
Also used : MethodVisitor(org.apache.tapestry5.internal.plastic.asm.MethodVisitor)

Example 4 with MethodVisitor

use of org.apache.tapestry5.internal.plastic.asm.MethodVisitor in project tapestry-5 by apache.

the class ComponentInstantiatorSourceImplTest method createSynthComponentClass.

private void createSynthComponentClass(String name) throws Exception {
    ClassWriter cw = helper.createWriter(SYNTH_COMPONENT_CLASSNAME, BASIC_COMPONENT_CLASSNAME, Named.class.getName());
    helper.implementPublicConstructor(cw, BASIC_COMPONENT_CLASSNAME);
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getName", "()Ljava/lang/String;", null, null);
    mv.visitCode();
    mv.visitLdcInsn(name);
    mv.visitInsn(ARETURN);
    mv.visitEnd();
    cw.visitEnd();
    helper.writeFile(cw, SYNTH_COMPONENT_CLASSNAME);
}
Also used : ClassWriter(org.apache.tapestry5.internal.plastic.asm.ClassWriter) MethodVisitor(org.apache.tapestry5.internal.plastic.asm.MethodVisitor)

Example 5 with MethodVisitor

use of org.apache.tapestry5.internal.plastic.asm.MethodVisitor in project tapestry-5 by apache.

the class ReloadTests method createIndexClass.

private void createIndexClass(int number) throws Exception {
    String className = PACKAGE + ".Index";
    ClassWriter cw = helper.createWriter(className, "java.lang.Object");
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getNumber", "()I", null, null);
    mv.visitCode();
    mv.visitLdcInsn(number);
    mv.visitInsn(IRETURN);
    cw.visitEnd();
    cw.visitEnd();
    helper.writeFile(cw, className);
}
Also used : ClassWriter(org.apache.tapestry5.internal.plastic.asm.ClassWriter) MethodVisitor(org.apache.tapestry5.internal.plastic.asm.MethodVisitor)

Aggregations

MethodVisitor (org.apache.tapestry5.internal.plastic.asm.MethodVisitor)7 ClassWriter (org.apache.tapestry5.internal.plastic.asm.ClassWriter)2 AnnotationVisitor (org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor)1 JSRInlinerAdapter (org.apache.tapestry5.internal.plastic.asm.commons.JSRInlinerAdapter)1 ClassNode (org.apache.tapestry5.internal.plastic.asm.tree.ClassNode)1 TraceClassVisitor (org.apache.tapestry5.internal.plastic.asm.util.TraceClassVisitor)1