Example usage for org.objectweb.asm ConstantDynamic getName

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

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name 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);/*from   w ww  . j av  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());
}