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(final int api) 

Source Link

Document

Constructs a new ClassNode .

Usage

From source file:org.diorite.inject.controller.Transformer.java

License:Open Source License

Transformer(byte[] bytecode, ControllerClassData classData) {
    this.classData = classData;
    this.classNode = new ClassNode(Opcodes.ASM6);
    ClassReader cr = new ClassReader(bytecode);
    cr.accept(this.classNode, 0);
}

From source file:org.jacoco.core.analysis.DataflowAnalyzer.java

License:Open Source License

/**
 * Analyzes the class given as a ASM reader.
 * //from  w  w w  . j av a  2s  .c  o m
 * @param reader
 *            reader with class definitions
 */
@Override
public void analyzeClass(final ClassReader reader) {
    final ClassNode cn = new ClassNode(Opcodes.ASM5);
    reader.accept(cn, ClassReader.EXPAND_FRAMES);
    // do not analyze interfaces
    if ((cn.access & Opcodes.ACC_INTERFACE) != 0) {
        return;
    }

    final boolean[] probes = getProbes(CRC64.checksum(reader.b));

    if (probes == null) {
        return;
    }

    final ClassAnalyzer analyzer = new ClassAnalyzer(cn, probes, stringPool);

    analyzer.visit(cn);
    coverageVisitor.visitCoverage(analyzer.getCoverage());
}

From source file:org.sonar.java.bytecode.cfg.BytecodeCFGBuilderTest.java

License:Open Source License

@Test
public void test_all_instructions_are_part_of_CFG() throws Exception {
    SquidClassLoader squidClassLoader = new SquidClassLoader(
            Lists.newArrayList(new File("target/test-classes"), new File("target/classes")));
    File file = new File("src/test/java/org/sonar/java/bytecode/cfg/testdata/CFGTestData.java");
    CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse(file);
    SemanticModel.createFor(tree, squidClassLoader);
    Symbol.TypeSymbol testClazz = ((ClassTree) tree.types().get(0)).symbol();
    ClassReader cr = new ClassReader(squidClassLoader
            .getResourceAsStream(Convert.bytecodeName(CFGTestData.class.getCanonicalName()) + ".class"));
    ClassNode classNode = new ClassNode(BytecodeCompleter.ASM_API_VERSION);
    cr.accept(classNode, 0);//ww  w  .j  a  v a 2s .  c o m
    for (MethodNode method : classNode.methods) {
        Multiset<String> opcodes = Arrays.stream(method.instructions.toArray()).map(AbstractInsnNode::getOpcode)
                .filter(opcode -> opcode != -1).map(opcode -> Printer.OPCODES[opcode])
                .collect(Collectors.toCollection(HashMultiset::create));

        Symbol methodSymbol = Iterables.getOnlyElement(testClazz.lookupSymbols(method.name));
        BytecodeCFG bytecodeCFG = SETestUtils.bytecodeCFG(((Symbol.MethodSymbol) methodSymbol).signature(),
                squidClassLoader);
        Multiset<String> cfgOpcodes = cfgOpcodes(bytecodeCFG);
        assertThat(cfgOpcodes).isEqualTo(opcodes);
    }
}

From source file:org.tbot.core.bot.loader.asm.modifiers.adapters.tree.generic.AbstractClassTransform.java

License:Open Source License

@Override
public ClassNode queryProduct() {
    if (classBytes != null) {
        ClassReader cr = new ClassReader(classBytes);
        ClassNode cn = new ClassNode(ASM4);
        cr.accept(cn, 0);//from w w w  .  j  ava 2s  .  co m
        return cn;
    } else {
        throw new NullPointerException("ClassNode bytes is null!");
    }
}

From source file:org.wavescale.hotload.transformer.MethodTransformer.java

License:Open Source License

@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
        ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
    if (ClassUtil.inTabooListOfPackages(className)) {
        return classfileBuffer;
    }/*from  w ww  .j av a  2s. co  m*/

    ClassNode cn = new ClassNode(Opcodes.ASM5);
    ClassReader cr = new ClassReader(classfileBuffer);
    ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    // create adapter for method insertion.
    cr.accept(cn, 0);

    // add the public var arg helper methods
    for (int i = 0; i < configManager.getNumberOfMethodsToBeAdded(); i++) {
        String methodName = ClassUtil.getPublicMethodName(classBeingRedefined, "MethodCall", i);
        if (canAddMethodName(cn, methodName)) {
            cn.methods.add(new VarArgsHelperMethod(classBeingRedefined, methodName));
        }
    }

    // get the byte code
    cn.accept(cw);
    classfileBuffer = cw.toByteArray();
    return classfileBuffer;
}