Example usage for org.objectweb.asm Opcodes ASM4

List of usage examples for org.objectweb.asm Opcodes ASM4

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ASM4.

Prototype

int ASM4

To view the source code for org.objectweb.asm Opcodes ASM4.

Click Source Link

Usage

From source file:org.jacoco.core.internal.instr.ClassInstrumenterTest.java

License:Open Source License

@Before
public void setup() {
    runtime = new LoggerRuntime();
    instrumenter = new ClassInstrumenter(123, runtime, new ClassVisitor(Opcodes.ASM4) {
    });/*from   w w  w  .j  a  va  2 s .co m*/
}

From source file:org.jacoco.core.internal.instr.ClassInstrumenterTest.java

License:Open Source License

@Test
public void testNoMethodVisitor() {
    instrumenter = new ClassInstrumenter(123, runtime, new ClassVisitor(Opcodes.ASM4) {
        @Override/*w  ww  .  j a v  a  2s  .c  o  m*/
        public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                String[] exceptions) {
            return null;
        }
    });
    assertNull(instrumenter.visitMethod(0, "foo", "()V", null, null));
}

From source file:org.jacoco.core.internal.instr.DuplicateFrameEliminator.java

License:Open Source License

public DuplicateFrameEliminator(final MethodVisitor mv) {
    super(Opcodes.ASM4, mv);
    instruction = true;
}

From source file:org.jacoco.core.internal.instr.FrameTracker.java

License:Open Source License

public FrameTracker(final String owner, final int access, final String name, final String desc,
        final MethodVisitor mv) {
    super(Opcodes.ASM4, mv);
    this.owner = owner;
    local = new Object[8];
    localSize = 0;/*from  www  .  ja v  a2  s  . c  o m*/
    stack = new Object[8];
    stackSize = 0;

    if ((access & Opcodes.ACC_STATIC) == 0) {
        if ("<init>".equals(name)) {
            set(localSize, Opcodes.UNINITIALIZED_THIS);
        } else {
            set(localSize, owner);
        }
    }
    for (final Type t : Type.getArgumentTypes(desc)) {
        set(localSize, t);
    }

}

From source file:org.jacoco.core.internal.instr.FrameTrackerTest.java

License:Open Source License

@After
public void verify() {
    MethodRecorder actual = new MethodRecorder();
    MethodVisitor noLabels = new MethodVisitor(Opcodes.ASM4, actual.getVisitor()) {
        @Override/*from w  w  w. j  a v  a 2  s . c o  m*/
        public void visitLabel(Label label) {
            // Ignore labels inserted by the tracker
        }
    };
    FrameTracker tracker = new FrameTracker("Test", ACC_STATIC, "test", "()V", noLabels);
    before.accept(tracker);
    mv.instructions.accept(tracker);
    tracker.insertFrame();

    MethodRecorder expected = new MethodRecorder();
    before.accept(expected.getVisitor());
    mv.instructions.accept(expected.getVisitor());
    after.accept(expected.getVisitor());

    assertEquals(expected, actual);
}

From source file:org.jacoco.core.internal.instr.LazyFrameTracker.java

License:Open Source License

public LazyFrameTracker(final MethodVisitor mv, final String owner) {
    super(Opcodes.ASM4, mv);
    this.owner = owner;
    this.tracker = null;
}

From source file:org.jacoco.core.internal.instr.ProbeInserter.java

License:Open Source License

/**
 * Creates a new {@link ProbeInserter}./*from w w w  .j a va2 s . com*/
 * 
 * @param access
 *            access flags of the adapted method.
 * @param desc
 *            the method's descriptor
 * @param mv
 *            the method visitor to which this adapter delegates calls
 * @param arrayStrategy
 *            callback to create the code that retrieves the reference to
 *            the probe array
 */
ProbeInserter(final int access, final String desc, final MethodVisitor mv,
        final IProbeArrayStrategy arrayStrategy) {
    super(Opcodes.ASM4, mv);
    this.arrayStrategy = arrayStrategy;
    int pos = (Opcodes.ACC_STATIC & access) == 0 ? 1 : 0;
    for (final Type t : Type.getArgumentTypes(desc)) {
        pos += t.getSize();
    }
    variable = pos;
}

From source file:org.jacoco.core.runtime.ModifiedSystemClassRuntime.java

License:Open Source License

/**
 * Adds the static access method and data field to the given class
 * definition./* www .j  a va2 s.  com*/
 * 
 * @param source
 *            class definition source
 * @param accessFieldName
 *            name of the runtime access field
 * @return instrumented version with added members
 */
public static byte[] instrument(final byte[] source, final String accessFieldName) {
    final ClassReader reader = new ClassReader(source);
    final ClassWriter writer = new ClassWriter(reader, 0);
    reader.accept(new ClassVisitor(Opcodes.ASM4, writer) {

        @Override
        public void visitEnd() {
            createDataField(cv, accessFieldName);
            super.visitEnd();
        }

    }, ClassReader.EXPAND_FRAMES);
    return writer.toByteArray();
}

From source file:org.jacoco.core.runtime.RuntimeTestBase.java

License:Open Source License

@Test
public void testNoLocalVariablesInDataAccessor() throws InstantiationException, IllegalAccessException {
    runtime.generateDataAccessor(1001, "Target", 5, new MethodVisitor(Opcodes.ASM4) {
        @Override/*from   w  ww  .j av  a  2 s  . com*/
        public void visitVarInsn(int opcode, int var) {
            fail("No usage of local variables allowed.");
        }
    });
}

From source file:org.jacoco.core.test.validation.ClassFileVersionsTest.java

License:Open Source License

private void assertFrames(byte[] source, boolean expected) {
    final boolean[] hasFrames = new boolean[] { false };
    new ClassReader(source).accept(new ClassVisitor(Opcodes.ASM4) {

        @Override/*from   w  w  w  . j  ava  2 s.  co  m*/
        public MethodVisitor visitMethod(int access, String name, String desc, String signature,
                String[] exceptions) {
            return new MethodVisitor(Opcodes.ASM4) {

                @Override
                public void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack) {
                    hasFrames[0] = true;
                }

            };
        }

    }, 0);
    assertEquals(Boolean.valueOf(expected), Boolean.valueOf(hasFrames[0]));
}