@Test public void testVisitLdcInsn() { Textifier textifier = new Textifier(); InstructionAdapter instructionAdapter = new InstructionAdapter(new TraceMethodVisitor(textifier)); instructionAdapter.visitLdcInsn(Boolean.FALSE); instructionAdapter.visitLdcInsn(Boolean.TRUE); instructionAdapter.visitLdcInsn(Byte.valueOf((byte) 2)); instructionAdapter.visitLdcInsn(Character.valueOf('3')); instructionAdapter.visitLdcInsn(Short.valueOf((short) 4)); instructionAdapter.visitLdcInsn(Integer.valueOf(5)); instructionAdapter.visitLdcInsn(Long.valueOf(6)); instructionAdapter.visitLdcInsn(Float.valueOf(7.0f)); instructionAdapter.visitLdcInsn(Double.valueOf(8.0)); instructionAdapter.visitLdcInsn("9"); instructionAdapter.visitLdcInsn(Type.getObjectType("pkg/Class")); instructionAdapter.visitLdcInsn( new Handle(Opcodes.H_GETFIELD, "pkg/Class", "name", "I", false)); assertEquals( "ICONST_0 ICONST_1 ICONST_2 BIPUSH 51 ICONST_4 ICONST_5 LDC 6 LDC 7.0 LDC 8.0 LDC \"9\" " + "LDC Lpkg/Class;.class LDC pkg/Class.nameI (1)", textifier .text .stream() .map(text -> text.toString().trim()) .collect(Collectors.joining(" "))); }
@Override public void visitLdcInsn(final Object value) { if (api < Opcodes.ASM5 && (value instanceof Handle || (value instanceof Type && ((Type) value).getSort() == Type.METHOD))) { throw new UnsupportedOperationException("This feature requires ASM5"); } if (api != Opcodes.ASM7 && value instanceof ConstantDynamic) { throw new UnsupportedOperationException("This feature requires ASM7"); } if (value instanceof Integer) { iconst((Integer) value); } else if (value instanceof Byte) { iconst(((Byte) value).intValue()); } else if (value instanceof Character) { iconst(((Character) value).charValue()); } else if (value instanceof Short) { iconst(((Short) value).intValue()); } else if (value instanceof Boolean) { iconst(((Boolean) value).booleanValue() ? 1 : 0); } else if (value instanceof Float) { fconst((Float) value); } else if (value instanceof Long) { lconst((Long) value); } else if (value instanceof Double) { dconst((Double) value); } else if (value instanceof String) { aconst(value); } else if (value instanceof Type) { tconst((Type) value); } else if (value instanceof Handle) { hconst((Handle) value); } else if (value instanceof ConstantDynamic) { cconst((ConstantDynamic) value); } else { throw new IllegalArgumentException(); } }
InstructionAdapter extends MethodVisitor { @Override public void visitLdcInsn(final Object value) { if (api < Opcodes.ASM5 && (value instanceof Handle || (value instanceof Type && ((Type) value).getSort() == Type.METHOD))) { throw new UnsupportedOperationException("This feature requires ASM5"); } if (api != Opcodes.ASM7 && value instanceof ConstantDynamic) { throw new UnsupportedOperationException("This feature requires ASM7"); } if (value instanceof Integer) { iconst((Integer) value); } else if (value instanceof Byte) { iconst(((Byte) value).intValue()); } else if (value instanceof Character) { iconst(((Character) value).charValue()); } else if (value instanceof Short) { iconst(((Short) value).intValue()); } else if (value instanceof Boolean) { iconst(((Boolean) value).booleanValue() ? 1 : 0); } else if (value instanceof Float) { fconst((Float) value); } else if (value instanceof Long) { lconst((Long) value); } else if (value instanceof Double) { dconst((Double) value); } else if (value instanceof String) { aconst(value); } else if (value instanceof Type) { tconst((Type) value); } else if (value instanceof Handle) { hconst((Handle) value); } else if (value instanceof ConstantDynamic) { cconst((ConstantDynamic) value); } else { throw new IllegalArgumentException(); } } }
InstructionAdapter extends MethodVisitor { @Override public void visitLdcInsn(final Object value) { if (api < Opcodes.ASM5 && (value instanceof Handle || (value instanceof Type && ((Type) value).getSort() == Type.METHOD))) { throw new UnsupportedOperationException("This feature requires ASM5"); } if (api != Opcodes.ASM7 && value instanceof ConstantDynamic) { throw new UnsupportedOperationException("This feature requires ASM7"); } if (value instanceof Integer) { iconst((Integer) value); } else if (value instanceof Byte) { iconst(((Byte) value).intValue()); } else if (value instanceof Character) { iconst(((Character) value).charValue()); } else if (value instanceof Short) { iconst(((Short) value).intValue()); } else if (value instanceof Boolean) { iconst(((Boolean) value).booleanValue() ? 1 : 0); } else if (value instanceof Float) { fconst((Float) value); } else if (value instanceof Long) { lconst((Long) value); } else if (value instanceof Double) { dconst((Double) value); } else if (value instanceof String) { aconst(value); } else if (value instanceof Type) { tconst((Type) value); } else if (value instanceof Handle) { hconst((Handle) value); } else if (value instanceof ConstantDynamic) { cconst((ConstantDynamic) value); } else { throw new IllegalArgumentException(); } } InstructionAdapter(final MethodVisitor methodVisitor); protected  InstructionAdapter(final int api, final MethodVisitor methodVisitor); }
InstructionAdapter extends MethodVisitor { @Override public void visitLdcInsn(final Object value) { if (api < Opcodes.ASM5 && (value instanceof Handle || (value instanceof Type && ((Type) value).getSort() == Type.METHOD))) { throw new UnsupportedOperationException("This feature requires ASM5"); } if (api != Opcodes.ASM7 && value instanceof ConstantDynamic) { throw new UnsupportedOperationException("This feature requires ASM7"); } if (value instanceof Integer) { iconst((Integer) value); } else if (value instanceof Byte) { iconst(((Byte) value).intValue()); } else if (value instanceof Character) { iconst(((Character) value).charValue()); } else if (value instanceof Short) { iconst(((Short) value).intValue()); } else if (value instanceof Boolean) { iconst(((Boolean) value).booleanValue() ? 1 : 0); } else if (value instanceof Float) { fconst((Float) value); } else if (value instanceof Long) { lconst((Long) value); } else if (value instanceof Double) { dconst((Double) value); } else if (value instanceof String) { aconst(value); } else if (value instanceof Type) { tconst((Type) value); } else if (value instanceof Handle) { hconst((Handle) value); } else if (value instanceof ConstantDynamic) { cconst((ConstantDynamic) value); } else { throw new IllegalArgumentException(); } } InstructionAdapter(final MethodVisitor methodVisitor); protected  InstructionAdapter(final int api, final MethodVisitor methodVisitor); @Override void visitInsn(final int opcode); @Override void visitIntInsn(final int opcode, final int operand); @Override void visitVarInsn(final int opcode, final int var); @Override void visitTypeInsn(final int opcode, final String type); @Override void visitFieldInsn(
      final int opcode, final String owner, final String name, final String descriptor); @Override void visitMethodInsn(
      final int opcodeAndSource,
      final String owner,
      final String name,
      final String descriptor,
      final boolean isInterface); @Override void visitInvokeDynamicInsn(
      final String name,
      final String descriptor,
      final Handle bootstrapMethodHandle,
      final Object... bootstrapMethodArguments); @Override void visitJumpInsn(final int opcode, final Label label); @Override void visitLabel(final Label label); @Override void visitLdcInsn(final Object value); @Override void visitIincInsn(final int var, final int increment); @Override void visitTableSwitchInsn(
      final int min, final int max, final Label dflt, final Label... labels); @Override void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels); @Override void visitMultiANewArrayInsn(final String descriptor, final int numDimensions); void nop(); void aconst(final Object value); void iconst(final int intValue); void lconst(final long longValue); void fconst(final float floatValue); void dconst(final double doubleValue); void tconst(final Type type); void hconst(final Handle handle); void cconst(final ConstantDynamic constantDynamic); void load(final int var, final Type type); void aload(final Type type); void store(final int var, final Type type); void astore(final Type type); void pop(); void pop2(); void dup(); void dup2(); void dupX1(); void dupX2(); void dup2X1(); void dup2X2(); void swap(); void add(final Type type); void sub(final Type type); void mul(final Type type); void div(final Type type); void rem(final Type type); void neg(final Type type); void shl(final Type type); void shr(final Type type); void ushr(final Type type); void and(final Type type); void or(final Type type); void xor(final Type type); void iinc(final int var, final int increment); void cast(final Type from, final Type to); void lcmp(); void cmpl(final Type type); void cmpg(final Type type); void ifeq(final Label label); void ifne(final Label label); void iflt(final Label label); void ifge(final Label label); void ifgt(final Label label); void ifle(final Label label); void ificmpeq(final Label label); void ificmpne(final Label label); void ificmplt(final Label label); void ificmpge(final Label label); void ificmpgt(final Label label); void ificmple(final Label label); void ifacmpeq(final Label label); void ifacmpne(final Label label); void goTo(final Label label); void jsr(final Label label); void ret(final int var); void tableswitch(final int min, final int max, final Label dflt, final Label... labels); void lookupswitch(final Label dflt, final int[] keys, final Label[] labels); void areturn(final Type type); void getstatic(final String owner, final String name, final String descriptor); void putstatic(final String owner, final String name, final String descriptor); void getfield(final String owner, final String name, final String descriptor); void putfield(final String owner, final String name, final String descriptor); @Deprecated void invokevirtual(final String owner, final String name, final String descriptor); void invokevirtual(
      final String owner, final String name, final String descriptor, final boolean isInterface); @Deprecated void invokespecial(final String owner, final String name, final String descriptor); void invokespecial(
      final String owner, final String name, final String descriptor, final boolean isInterface); @Deprecated void invokestatic(final String owner, final String name, final String descriptor); void invokestatic(
      final String owner, final String name, final String descriptor, final boolean isInterface); void invokeinterface(final String owner, final String name, final String descriptor); void invokedynamic(
      final String name,
      final String descriptor,
      final Handle bootstrapMethodHandle,
      final Object[] bootstrapMethodArguments); void anew(final Type type); void newarray(final Type type); void arraylength(); void athrow(); void checkcast(final Type type); void instanceOf(final Type type); void monitorenter(); void monitorexit(); void multianewarray(final String descriptor, final int numDimensions); void ifnull(final Label label); void ifnonnull(final Label label); void mark(final Label label); }
InstructionAdapter extends MethodVisitor { @Override public void visitLdcInsn(final Object value) { if (api < Opcodes.ASM5 && (value instanceof Handle || (value instanceof Type && ((Type) value).getSort() == Type.METHOD))) { throw new UnsupportedOperationException("This feature requires ASM5"); } if (api != Opcodes.ASM7 && value instanceof ConstantDynamic) { throw new UnsupportedOperationException("This feature requires ASM7"); } if (value instanceof Integer) { iconst((Integer) value); } else if (value instanceof Byte) { iconst(((Byte) value).intValue()); } else if (value instanceof Character) { iconst(((Character) value).charValue()); } else if (value instanceof Short) { iconst(((Short) value).intValue()); } else if (value instanceof Boolean) { iconst(((Boolean) value).booleanValue() ? 1 : 0); } else if (value instanceof Float) { fconst((Float) value); } else if (value instanceof Long) { lconst((Long) value); } else if (value instanceof Double) { dconst((Double) value); } else if (value instanceof String) { aconst(value); } else if (value instanceof Type) { tconst((Type) value); } else if (value instanceof Handle) { hconst((Handle) value); } else if (value instanceof ConstantDynamic) { cconst((ConstantDynamic) value); } else { throw new IllegalArgumentException(); } } InstructionAdapter(final MethodVisitor methodVisitor); protected  InstructionAdapter(final int api, final MethodVisitor methodVisitor); @Override void visitInsn(final int opcode); @Override void visitIntInsn(final int opcode, final int operand); @Override void visitVarInsn(final int opcode, final int var); @Override void visitTypeInsn(final int opcode, final String type); @Override void visitFieldInsn(
      final int opcode, final String owner, final String name, final String descriptor); @Override void visitMethodInsn(
      final int opcodeAndSource,
      final String owner,
      final String name,
      final String descriptor,
      final boolean isInterface); @Override void visitInvokeDynamicInsn(
      final String name,
      final String descriptor,
      final Handle bootstrapMethodHandle,
      final Object... bootstrapMethodArguments); @Override void visitJumpInsn(final int opcode, final Label label); @Override void visitLabel(final Label label); @Override void visitLdcInsn(final Object value); @Override void visitIincInsn(final int var, final int increment); @Override void visitTableSwitchInsn(
      final int min, final int max, final Label dflt, final Label... labels); @Override void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels); @Override void visitMultiANewArrayInsn(final String descriptor, final int numDimensions); void nop(); void aconst(final Object value); void iconst(final int intValue); void lconst(final long longValue); void fconst(final float floatValue); void dconst(final double doubleValue); void tconst(final Type type); void hconst(final Handle handle); void cconst(final ConstantDynamic constantDynamic); void load(final int var, final Type type); void aload(final Type type); void store(final int var, final Type type); void astore(final Type type); void pop(); void pop2(); void dup(); void dup2(); void dupX1(); void dupX2(); void dup2X1(); void dup2X2(); void swap(); void add(final Type type); void sub(final Type type); void mul(final Type type); void div(final Type type); void rem(final Type type); void neg(final Type type); void shl(final Type type); void shr(final Type type); void ushr(final Type type); void and(final Type type); void or(final Type type); void xor(final Type type); void iinc(final int var, final int increment); void cast(final Type from, final Type to); void lcmp(); void cmpl(final Type type); void cmpg(final Type type); void ifeq(final Label label); void ifne(final Label label); void iflt(final Label label); void ifge(final Label label); void ifgt(final Label label); void ifle(final Label label); void ificmpeq(final Label label); void ificmpne(final Label label); void ificmplt(final Label label); void ificmpge(final Label label); void ificmpgt(final Label label); void ificmple(final Label label); void ifacmpeq(final Label label); void ifacmpne(final Label label); void goTo(final Label label); void jsr(final Label label); void ret(final int var); void tableswitch(final int min, final int max, final Label dflt, final Label... labels); void lookupswitch(final Label dflt, final int[] keys, final Label[] labels); void areturn(final Type type); void getstatic(final String owner, final String name, final String descriptor); void putstatic(final String owner, final String name, final String descriptor); void getfield(final String owner, final String name, final String descriptor); void putfield(final String owner, final String name, final String descriptor); @Deprecated void invokevirtual(final String owner, final String name, final String descriptor); void invokevirtual(
      final String owner, final String name, final String descriptor, final boolean isInterface); @Deprecated void invokespecial(final String owner, final String name, final String descriptor); void invokespecial(
      final String owner, final String name, final String descriptor, final boolean isInterface); @Deprecated void invokestatic(final String owner, final String name, final String descriptor); void invokestatic(
      final String owner, final String name, final String descriptor, final boolean isInterface); void invokeinterface(final String owner, final String name, final String descriptor); void invokedynamic(
      final String name,
      final String descriptor,
      final Handle bootstrapMethodHandle,
      final Object[] bootstrapMethodArguments); void anew(final Type type); void newarray(final Type type); void arraylength(); void athrow(); void checkcast(final Type type); void instanceOf(final Type type); void monitorenter(); void monitorexit(); void multianewarray(final String descriptor, final int numDimensions); void ifnull(final Label label); void ifnonnull(final Label label); void mark(final Label label); static final Type OBJECT_TYPE; }