Example usage for org.objectweb.asm ConstantDynamic getBootstrapMethod

List of usage examples for org.objectweb.asm ConstantDynamic getBootstrapMethod

Introduction

In this page you can find the example usage for org.objectweb.asm ConstantDynamic getBootstrapMethod.

Prototype

public Handle getBootstrapMethod() 

Source Link

Document

Returns the bootstrap method used to compute the value of this constant.

Usage

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

License:Open Source License

@Test
public void should_store_instance_using_condy_and_checkcast() {
    final MethodNode m = new MethodNode();
    final int maxStack = strategy.storeInstance(m, false, 1);

    assertEquals(1, maxStack);/*  w  w  w  .j a  v  a2s .c  o m*/

    final ConstantDynamic constantDynamic = (ConstantDynamic) ((LdcInsnNode) m.instructions.get(0)).cst;
    assertEquals("$jacocoData", constantDynamic.getName());
    assertEquals("Ljava/lang/Object;", constantDynamic.getDescriptor());

    final Handle bootstrapMethod = constantDynamic.getBootstrapMethod();
    assertEquals(Opcodes.H_INVOKESTATIC, bootstrapMethod.getTag());
    assertEquals("ClassName", bootstrapMethod.getOwner());
    assertEquals("$jacocoInit", bootstrapMethod.getName());
    assertEquals("(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)[Z",
            bootstrapMethod.getDesc());
    assertTrue(bootstrapMethod.isInterface());

    final TypeInsnNode castInstruction = (TypeInsnNode) m.instructions.get(1);
    assertEquals(Opcodes.CHECKCAST, castInstruction.getOpcode());
    assertEquals("[Z", castInstruction.desc);

    final VarInsnNode storeInstruction = (VarInsnNode) m.instructions.get(2);
    assertEquals(Opcodes.ASTORE, storeInstruction.getOpcode());
    assertEquals(1, storeInstruction.var);

    assertEquals(3, m.instructions.size());
}