Example usage for org.objectweb.asm MethodVisitor visitAttribute

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

Introduction

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

Prototype

public void visitAttribute(final Attribute attribute) 

Source Link

Document

Visits a non standard attribute of this method.

Usage

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

License:Apache License

public void visitAttribute(Attribute attr) {
    for (MethodVisitor visitor : visitors) {
        visitor.visitAttribute(attr);
    }
}

From source file:kilim.analysis.MethodFlow.java

License:Open Source License

@Override
/**/*www . jav a 2 s  . c o m*/
 * 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;/*www  . ja  v  a  2s .co  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.codehaus.aspectwerkz.transform.inlining.weaver.MethodExecutionVisitor.java

License:Open Source License

/**
 * Visits the methods.//from   ww  w. j a  va2  s . c om
 *
 * @param access
 * @param name
 * @param desc
 * @param signature
 * @param exceptions
 * @return
 */
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature,
        final String[] exceptions) {

    if (INIT_METHOD_NAME.equals(name) || CLINIT_METHOD_NAME.equals(name) || name.startsWith(ASPECTWERKZ_PREFIX)
            || name.startsWith(SYNTHETIC_MEMBER_PREFIX) || name.startsWith(WRAPPER_METHOD_PREFIX)
            || (AdvisableImpl.ADD_ADVICE_METHOD_NAME.equals(name)
                    && AdvisableImpl.ADD_ADVICE_METHOD_DESC.equals(desc))
            || (AdvisableImpl.REMOVE_ADVICE_METHOD_NAME.equals(name)
                    && AdvisableImpl.REMOVE_ADVICE_METHOD_DESC.equals(desc))) {
        return cv.visitMethod(access, name, desc, signature, exceptions);
    }

    int hash = AsmHelper.calculateMethodHash(name, desc);
    MethodInfo methodInfo = m_classInfo.getMethod(hash);
    if (methodInfo == null) {
        System.err.println("AW::WARNING " + "metadata structure could not be build for method ["
                + m_classInfo.getName().replace('/', '.') + '.' + name + ':' + desc + ']');
        // bail out
        return cv.visitMethod(access, name, desc, signature, exceptions);
    }

    ExpressionContext ctx = new ExpressionContext(PointcutType.EXECUTION, methodInfo, methodInfo);

    if (methodFilter(m_ctx.getDefinitions(), ctx, methodInfo)) {
        return cv.visitMethod(access, name, desc, signature, exceptions);
    } else {
        String prefixedOriginalName = TransformationUtil.getPrefixedOriginalMethodName(name,
                m_declaringTypeName);
        if (m_addedMethods.contains(AlreadyAddedMethodAdapter.getMethodKey(prefixedOriginalName, desc))) {
            return cv.visitMethod(access, name, desc, signature, exceptions);
        }

        m_ctx.markAsAdvised();

        // create the proxy for the original method
        final MethodVisitor proxyMethod = createProxyMethod(access, name, desc, signature, exceptions,
                methodInfo);

        int modifiers = ACC_SYNTHETIC;
        if (Modifier.isStatic(access)) {
            modifiers |= ACC_STATIC;
        }
        // prefix the original method and make sure we copy method annotations to the proxyMethod
        // while keeping the body for the prefixed method
        return new MethodAdapter(cv.visitMethod(modifiers, prefixedOriginalName, desc, signature, exceptions)) {
            public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
                return new AsmCopyAdapter.CopyAnnotationAdapter(super.visitAnnotation(desc, visible),
                        proxyMethod.visitAnnotation(desc, visible));
            }

            public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) {
                return new AsmCopyAdapter.CopyAnnotationAdapter(
                        super.visitParameterAnnotation(parameter, desc, visible),
                        proxyMethod.visitParameterAnnotation(parameter, desc, visible));
            }

            public void visitAttribute(Attribute attr) {
                super.visitAttribute(attr);
                proxyMethod.visitAttribute(attr);
            }
        };
    }
}

From source file:org.jephyr.activeobject.instrument.ActiveObjectClassAdapter.java

License:Open Source License

private static void acceptAllBeforeCode(MethodNode methodNode, MethodVisitor mv) {
    if (methodNode.parameters != null) {
        for (ParameterNode node : methodNode.parameters) {
            node.accept(mv);/*  w w  w. j a v  a 2s  . co  m*/
        }
    }

    if (methodNode.annotationDefault != null) {
        AnnotationVisitor av = mv.visitAnnotationDefault();
        if (av != null) {
            acceptAnnotation(av, null, methodNode.annotationDefault);
            av.visitEnd();
        }
    }

    if (methodNode.visibleAnnotations != null) {
        for (AnnotationNode node : methodNode.visibleAnnotations) {
            node.accept(mv.visitAnnotation(node.desc, true));
        }
    }

    if (methodNode.invisibleAnnotations != null) {
        for (AnnotationNode node : methodNode.invisibleAnnotations) {
            node.accept(mv.visitAnnotation(node.desc, false));
        }
    }

    if (methodNode.visibleTypeAnnotations != null) {
        for (TypeAnnotationNode node : methodNode.visibleTypeAnnotations) {
            node.accept(mv.visitTypeAnnotation(node.typeRef, node.typePath, node.desc, true));
        }
    }

    if (methodNode.invisibleTypeAnnotations != null) {
        for (TypeAnnotationNode node : methodNode.invisibleTypeAnnotations) {
            node.accept(mv.visitTypeAnnotation(node.typeRef, node.typePath, node.desc, false));
        }
    }

    if (methodNode.visibleParameterAnnotations != null) {
        int parameter = 0;
        for (List<AnnotationNode> nodes : methodNode.visibleParameterAnnotations) {
            if (nodes != null) {
                for (AnnotationNode node : nodes) {
                    node.accept(mv.visitParameterAnnotation(parameter, node.desc, true));
                }
            }
            parameter++;
        }
    }

    if (methodNode.invisibleParameterAnnotations != null) {
        int parameter = 0;
        for (List<AnnotationNode> nodes : methodNode.invisibleParameterAnnotations) {
            if (nodes != null) {
                for (AnnotationNode node : nodes) {
                    node.accept(mv.visitParameterAnnotation(parameter, node.desc, false));
                }
            }
            parameter++;
        }
    }

    if (methodNode.attrs != null) {
        for (Attribute attribute : methodNode.attrs) {
            mv.visitAttribute(attribute);
        }
    }
}

From source file:org.springframework.migrationanalyzer.contributions.bytecode.DelegatingMethodVisitor.java

License:Apache License

@Override
public void visitAttribute(Attribute attr) {
    for (MethodVisitor delegate : this.delegates) {
        delegate.visitAttribute(attr);
    }/*  w  ww . j  av  a2s .com*/
}