Search in sources :

Example 6 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project bytecode-viewer by Konloch.

the class NumberNode method setNumber.

public void setNumber(int number) {
    AbstractInsnNode ain = insn();
    if (ain instanceof IntInsnNode) {
        ((IntInsnNode) insn()).operand = number;
        ((IntInsnNode) ain).operand = number;
    } else if (ain instanceof LdcInsnNode) {
        ((LdcInsnNode) insn()).cst = number;
        ((LdcInsnNode) ain).cst = number;
    }
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 7 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project bytecode-viewer by Konloch.

the class Assembly method rename.

public static void rename(Collection<ClassNode> classes, ClassNode cn, String newName) {
    for (ClassNode node : classes) {
        if (node.superName.equals(cn.name))
            node.superName = newName;
        if (node.interfaces.contains(cn.name)) {
            node.interfaces.remove(cn.name);
            node.interfaces.add(newName);
        }
        for (FieldNode fn : node.fields) {
            if (fn.desc.endsWith("L" + cn.name + ";"))
                fn.desc = fn.desc.replace("L" + cn.name + ";", "L" + newName + ";");
        }
        for (MethodNode mn : node.methods) {
            if (mn.desc.contains("L" + cn.name + ";"))
                mn.desc = mn.desc.replaceAll("L" + cn.name + ";", "L" + newName + ";");
            for (AbstractInsnNode ain : mn.instructions.toArray()) {
                if (ain instanceof FieldInsnNode) {
                    FieldInsnNode fin = (FieldInsnNode) ain;
                    if (fin.owner.equals(cn.name))
                        fin.owner = newName;
                } else if (ain instanceof MethodInsnNode) {
                    MethodInsnNode min = (MethodInsnNode) ain;
                    if (min.owner.equals(cn.name))
                        min.owner = newName;
                }
            }
        }
    }
    cn.name = newName;
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 8 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project jacoco by jacoco.

the class MethodAnalyzer method visitEnd.

@Override
public void visitEnd() {
    // Wire jumps:
    for (final Jump j : jumps) {
        LabelInfo.getInstruction(j.target).setPredecessor(j.source, j.branch);
    }
    // Propagate probe values:
    for (final CoveredProbe p : coveredProbes) {
        p.instruction.setCovered(p.branch);
    }
    // Merge:
    for (final Instruction i : instructions) {
        final AbstractInsnNode m = i.getNode();
        final AbstractInsnNode r = findRepresentative(m);
        if (r != m) {
            ignored.add(m);
            nodeToInstruction.get(r).merge(i);
        }
    }
    // Report result:
    coverage.ensureCapacity(firstLine, lastLine);
    for (final Instruction i : instructions) {
        if (ignored.contains(i.getNode())) {
            continue;
        }
        final int total = i.getBranches();
        final int covered = i.getCoveredBranches();
        final ICounter instrCounter = covered == 0 ? CounterImpl.COUNTER_1_0 : CounterImpl.COUNTER_0_1;
        final ICounter branchCounter = total > 1 ? CounterImpl.getInstance(total - covered, covered) : CounterImpl.COUNTER_0_0;
        coverage.increment(instrCounter, branchCounter, i.getLine());
    }
    coverage.incrementMethodCounter();
}
Also used : ICounter(org.jacoco.core.analysis.ICounter) Instruction(org.jacoco.core.internal.flow.Instruction) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 9 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project jacoco by jacoco.

the class StringSwitchJavacFilter method filter.

public void filter(final String className, final String superClassName, final MethodNode methodNode, final IFilterOutput output) {
    AbstractInsnNode i = methodNode.instructions.getFirst();
    while (i != null) {
        filter(i, output);
        i = i.getNext();
    }
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 10 with AbstractInsnNode

use of org.objectweb.asm.tree.AbstractInsnNode in project jacoco by jacoco.

the class SynchronizedFilter method filter.

public void filter(final String className, final String superClassName, final MethodNode methodNode, final IFilterOutput output) {
    for (TryCatchBlockNode tryCatch : methodNode.tryCatchBlocks) {
        if (tryCatch.type != null) {
            continue;
        }
        if (tryCatch.start == tryCatch.handler) {
            continue;
        }
        final AbstractInsnNode to = new Matcher(tryCatch.handler).match();
        if (to == null) {
            continue;
        }
        output.ignore(tryCatch.handler, to);
    }
}
Also used : TryCatchBlockNode(org.objectweb.asm.tree.TryCatchBlockNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Aggregations

AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)185 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)68 MethodNode (org.objectweb.asm.tree.MethodNode)54 InsnList (org.objectweb.asm.tree.InsnList)53 InsnNode (org.objectweb.asm.tree.InsnNode)41 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)38 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)37 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)35 ClassNode (org.objectweb.asm.tree.ClassNode)33 LabelNode (org.objectweb.asm.tree.LabelNode)27 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)26 Test (org.junit.Test)25 Label (org.objectweb.asm.Label)25 ClassReader (org.objectweb.asm.ClassReader)23 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)23 HashSet (java.util.HashSet)16 Type (org.objectweb.asm.Type)15 Frame (org.objectweb.asm.tree.analysis.Frame)13 ArrayList (java.util.ArrayList)12 TryCatchBlockNode (org.objectweb.asm.tree.TryCatchBlockNode)11