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

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

Introduction

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

Prototype

public ClassNode() 

Source Link

Document

Constructs a new ClassNode .

Usage

From source file:org.teavm.dependency.DependencyAnalyzer.java

License:Apache License

public String submitClassFile(byte[] data) {
    ClassNode node = new ClassNode();
    org.objectweb.asm.ClassReader reader = new org.objectweb.asm.ClassReader(data);
    reader.accept(node, 0);/*from w ww. j a  va2 s  .  co m*/
    submitClass(new Parser(new ReferenceCache()).parseClass(node));
    return node.name;
}

From source file:org.teavm.dependency.DependencyChecker.java

License:Apache License

public String submitClassFile(byte[] data) {
    ClassNode node = new ClassNode();
    org.objectweb.asm.ClassReader reader = new org.objectweb.asm.ClassReader(data);
    reader.accept(node, 0);/*from   w  w w . j  av  a 2 s .c o  m*/
    submitClass(Parser.parseClass(node));
    return node.name;
}

From source file:org.teavm.parsing.resource.ResourceClassHolderMapper.java

License:Apache License

@Override
public ClassHolder map(String name) {
    ClassNode clsNode = new ClassNode();
    String resourceName = name.replace('.', '/') + ".class";
    if (!resourceReader.hasResource(resourceName)) {
        return null;
    }/*from w ww  . ja v  a 2s  . com*/
    try (InputStream input = resourceReader.openResource(resourceName)) {
        ClassReader reader = new ClassReader(input);
        reader.accept(clsNode, 0);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return parser.parseClass(clsNode);
}

From source file:org.teavm.resource.ResourceClassHolderMapper.java

License:Apache License

@Override
public ClassHolder map(String name) {
    ClassNode clsNode = new ClassNode();
    String resourceName = name.replace('.', '/') + ".class";
    if (!resourceReader.hasResource(resourceName)) {
        return null;
    }/*  w w w  .  j a v  a  2  s  .c o  m*/
    try (InputStream input = resourceReader.openResource(resourceName)) {
        ClassReader reader = new ClassReader(input);
        reader.accept(clsNode, 0);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return Parser.parseClass(clsNode);
}

From source file:org.teavm.resource.ResourceParser.java

License:Apache License

@Override
public ClassHolder map(String name) {
    ClassNode clsNode = new ClassNode();
    try (InputStream input = resourceReader.openResource(name.replace('.', '/') + ".class")) {
        ClassReader reader = new ClassReader(input);
        reader.accept(clsNode, 0);// w  w w  . ja  v a 2  s. c  o  m
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return Parser.parseClass(clsNode);
}

From source file:org.testeoa.estatica.AnaliseEstatica.java

License:Open Source License

public static Classe lerClasse(String nome) throws ExAnaliseEstatica {
    try {//from ww w  . j  a  va  2 s  .c om
        ClassReader cr = new ClassReader(nome);
        ClassNode cn = new ClassNode();
        cr.accept(cn, ClassReader.SKIP_FRAMES);

        if (isAspecto(cn)) {
            throw new ExAnaliseEstatica("[" + nome + "] no  uma classe.", null);
        }

        Classe c = new Classe(nome);
        for (MethodNode mn : (List<MethodNode>) cn.methods) {
            if (isValido(mn)) {
                c.inserir(new Metodo(mn.name, mn.desc));
            }
        }

        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
        //         TraceClassVisitor tcv =
        //            new TraceClassVisitor(cw, new PrintWriter(System.out));
        ClassAdapter adapter = new AdapterClasse(c, cw);
        cn.accept(adapter);

        c.setBytecode(cw.toByteArray());

        return c;
    } catch (IOException e) {
        throw new ExAnaliseEstatica("Erro ao tentar abrir a classe [" + nome + "].", e);
    }
}

From source file:org.testeoa.estatica.AnaliseEstatica.java

License:Open Source License

public static Aspecto lerAspecto(String nome) throws ExAnaliseEstatica {
    try {/*w ww.  j  a va2s . c  o m*/
        ClassReader cr = new ClassReader(nome);
        ClassNode cn = new ClassNode();
        cr.accept(cn, ClassReader.SKIP_FRAMES);

        if (!isAspecto(cn)) {
            throw new ExAnaliseEstatica("[" + nome + "] no  um aspecto.", null);
        }

        Aspecto a = new Aspecto(nome);
        for (MethodNode mn : (List<MethodNode>) cn.methods) {
            if (isAdendo(mn.name)) {
                a.inserir(new Adendo(mn.name, mn.desc));
            } else {
                if (isValido(mn)) {
                    a.inserir(new Metodo(mn.name, mn.desc));
                }
            }
        }

        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
        //         TraceClassVisitor tcv =
        //            new TraceClassVisitor(cw, new PrintWriter(System.out));
        ClassAdapter adapter = new AdapterAspecto(a, cw);
        cn.accept(adapter);

        a.setBytecode(cw.toByteArray());

        return a;
    } catch (IOException e) {
        throw new ExAnaliseEstatica("Erro ao tentar abrir o aspecto [" + nome + "].", e);
    }
}

From source file:org.testeoa.estatica.AnaliseEstatica.java

License:Open Source License

public static CasoTeste lerCasoTeste(String nome) throws ExAnaliseEstatica {
    try {//from ww  w  .  j  a  v  a2s.  co  m
        ClassReader cr = new ClassReader(nome);
        ClassNode cn = new ClassNode();
        cr.accept(cn, ClassReader.SKIP_FRAMES);

        if (!isCasoTeste(cn)) {
            throw new ExAnaliseEstatica("[" + nome + "] no  um caso de " + "teste JUnit vlido.", null);
        }

        CasoTeste ct = new CasoTeste(nome);

        return ct;
    } catch (IOException e) {
        throw new ExAnaliseEstatica("Erro ao tentar abrir o caso de teste [" + nome + "].", e);
    }
}

From source file:org.unitils.mock.argumentmatcher.ArgumentMatcherPositionFinder.java

License:Apache License

/**
 * Uses ASM to read the byte code of the given class. This will access the class file and create some sort
 * of DOM tree for the structure of the bytecode.
 *
 * @param clazz The class to read, not null
 * @return The structure of the class, not null
 *///from   w  w w.  jav  a  2 s .c o  m
protected static ClassNode readClass(Class<?> clazz) {
    InputStream inputStream = null;
    try {
        inputStream = clazz.getClassLoader().getResourceAsStream(clazz.getName().replace('.', '/') + ".class");

        ClassReader classReader = new ClassReader(inputStream);
        ClassNode classNode = new ClassNode();
        classReader.accept(classNode, 0);
        return classNode;

    } catch (Exception e) {
        throw new UnitilsException("Unable to read class file for " + clazz, e);
    } finally {
        closeQuietly(inputStream);
    }
}

From source file:org.wildfly.swarm.jaxrs.runtime.DefaultApplicationDeploymentProcessorTest.java

License:Apache License

@Test
public void testApplicationPathAnnotation_None_And_ChangeThePath() throws Exception {
    String applicationPath = "/api";

    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
    DefaultApplicationDeploymentProcessor processor = new DefaultApplicationDeploymentProcessor(archive);
    processor.applicationPath.set(applicationPath);

    processor.process();//from  w w  w .j  a  v a 2 s.  co  m

    try (InputStream in = archive.get(PATH).getAsset().openStream()) {
        ClassReader reader = new ClassReader(in);
        ClassNode node = new ClassNode();

        reader.accept(node, 0);
        List<AnnotationNode> visibleAnnotations = node.visibleAnnotations;

        assertThat(visibleAnnotations.size()).isEqualTo(1);
        assertThat(visibleAnnotations.get(0).values).contains(applicationPath);
    } catch (IOException ignored) {
    }
}