Example usage for org.objectweb.asm ClassReader accept

List of usage examples for org.objectweb.asm ClassReader accept

Introduction

In this page you can find the example usage for org.objectweb.asm ClassReader accept.

Prototype

public void accept(final ClassVisitor classVisitor, final Attribute[] attributePrototypes,
        final int parsingOptions) 

Source Link

Document

Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this ClassReader .

Usage

From source file:com.geeksaga.light.profiler.util.ASMUtil.java

License:Apache License

public static ClassNodeWrapper parse(byte[] classfileBuffer, int flags) {
    ClassNodeWrapper classNodeWrapper = new ClassNodeWrapper();

    ClassReader reader = new ClassReaderWrapper(classfileBuffer);
    reader.accept(useJSRInlinerAdapter(classNodeWrapper), new Attribute[0], flags);

    return classNodeWrapper;
}

From source file:com.geeksaga.light.profiler.util.ASMUtil.java

License:Apache License

public static ClassNodeWrapper parse(Object obj) {
    ClassNodeWrapper classNodeWrapper = new ClassNodeWrapper();

    ClassReader reader = new ClassReaderWrapper(obj.getClass().getName());
    reader.accept(useJSRInlinerAdapter(classNodeWrapper), new Attribute[0], 0);

    return classNodeWrapper;
}

From source file:com.geeksaga.light.profiler.util.ASMUtil.java

License:Apache License

public static ClassNodeWrapper parse(Class clazz) {
    ClassNodeWrapper classNodeWrapper = new ClassNodeWrapper();

    ClassReader reader = new ClassReaderWrapper(clazz);
    reader.accept(useJSRInlinerAdapter(classNodeWrapper), new Attribute[0], 0);

    return classNodeWrapper;
}

From source file:com.geeksaga.light.profiler.util.ASMUtil.java

License:Apache License

private static ClassNodeWrapper getClassWrapperUsingClassName(String className) {
    if (ClassReaderWrapper.isValid(className)) {
        ClassNodeWrapper classNode = new ClassNodeWrapper();
        ClassReader cr = new ClassReaderWrapper(className);
        cr.accept(classNode, new Attribute[0], 0);

        return classNode;
    }/*  w  w  w. j a va2s.c  o  m*/

    return null;
}

From source file:com.google.devtools.cdbg.debuglets.java.SourceFileMapper.java

License:Open Source License

private void loadClass(InputStream resource) throws IOException {
    ClassReader classReader;
    classReader = new ClassReader(resource);

    // We don't need to parse any attributes while loading the class.
    Attribute[] attributes = new Attribute[0];

    classReader.accept(new MapperClassVisitor(), attributes, ClassReader.SKIP_FRAMES);
}

From source file:com.j2biz.pencil.ClassManager.java

License:Open Source License

private ASMClassInfoNode loadClassFromResource(final File fileSource) throws IOException {
    LOG.entry("loadClassFromResource(final File fileSource)");

    final FileInputStream in = new FileInputStream(fileSource);
    final ClassAnalyzerVisitor visitor = new ClassAnalyzerVisitor(this, fileSource);

    final ClassReader reader = new ClassReader(in);
    try {/*from  w ww .  jav a2 s. com*/
        reader.accept(visitor, Attributes.getDefaultAttributes(), false);
    } catch (Throwable x) {
        LOG.error("class is not parseable by ASM.");
        LOG.error("name of the class-file: " + fileSource);
        LOG.errorException(x);

        LOG.exit("loadClassFromResource(final File fileSource)");
        throw new ClassParseException("can't load class: " + fileSource, x);
    }

    LOG.exit("loadClassFromResource(final File fileSource)");
    return visitor.getClassInfo();
}

From source file:com.retroduction.carma.transformer.asm.AbstractASMTransition.java

License:Open Source License

public List<Mutant> applyTransitions(byte[] byteCode) {

    ClassNode classNode = new ClassNode();

    ClassReader reader = new ClassReader(byteCode);

    reader.accept(classNode, new Attribute[] { new CharacterRangeTable() }, 0);

    List<Mutant> result = new ArrayList<Mutant>();

    int methodIndex = 0;

    for (MethodNode methodNode : (List<MethodNode>) classNode.methods) {

        Iterator<AbstractInsnNode> instructionIterator = methodNode.instructions.iterator();

        CharacterRangeTable crt = null;/*w  ww  .j  a v a  2 s.  c  o  m*/

        if (methodNode.attrs != null) {
            for (Attribute attr : (List<Attribute>) methodNode.attrs) {
                if (attr instanceof CharacterRangeTable) {
                    crt = (CharacterRangeTable) attr;
                }
            }
        }

        CRTEntry crtEntry = new CRTEntry();

        while (instructionIterator.hasNext()) {

            AbstractInsnNode node = instructionIterator.next();

            if (node instanceof LineNumberNode) {
                if (crt == null) {
                    crtEntry.setStartPos(((LineNumberNode) node).line << 10);
                    crtEntry.setEndPos(((LineNumberNode) node).line << 10);
                }
                continue;
            }

            if ((node instanceof LabelNode)) {

                if (crt == null)
                    continue;

                if (crt.getLabelOffsets().containsKey(((LabelNode) node).getLabel())) {
                    crtEntry = crt.getLabelOffsets().get(((LabelNode) node).getLabel());
                }
                continue;
            }

            this.checkNode(classNode, methodNode, result, crtEntry, node);

        }
        methodIndex++;

    }

    return result;
}