List of usage examples for org.objectweb.asm.tree MethodNode visitLookupSwitchInsn
@Override public void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels)
From source file:org.jacoco.core.internal.analysis.filter.KotlinWhenStringFilterTest.java
License:Open Source License
@Test public void should_not_filter_empty_lookup_switch() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "name", "(Ljava/lang/String;)V", null, null);/*from ww w . ja v a2s. c o m*/ m.visitVarInsn(Opcodes.ALOAD, 1); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false); final Label defaultCase = new Label(); m.visitLookupSwitchInsn(defaultCase, null, new Label[] {}); m.visitLabel(defaultCase); m.visitInsn(Opcodes.RETURN); filter.filter(m, context, output); assertIgnored(); }
From source file:org.jacoco.core.internal.analysis.filter.StringSwitchEcjFilterTest.java
License:Open Source License
@Test public void should_filter_when_default_is_first() { final Set<AbstractInsnNode> expectedNewTargets = new HashSet<AbstractInsnNode>(); final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "name", "()V", null, null); final Label case1 = new Label(); final Label caseDefault = new Label(); final Label h1 = new Label(); // filter should not remember this unrelated slot m.visitLdcInsn(""); m.visitVarInsn(Opcodes.ASTORE, 1);//from w ww. j av a 2 s . c o m m.visitVarInsn(Opcodes.ALOAD, 1); // switch (...) m.visitInsn(Opcodes.DUP); m.visitVarInsn(Opcodes.ASTORE, 2); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false); m.visitLookupSwitchInsn(caseDefault, new int[] { 97 }, new Label[] { h1 }); final AbstractInsnNode switchNode = m.instructions.getLast(); m.visitLabel(h1); m.visitVarInsn(Opcodes.ALOAD, 2); m.visitLdcInsn("a"); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); // if equal "a", then goto its case m.visitJumpInsn(Opcodes.IFNE, case1); final AbstractInsnNode expectedToInclusive = m.instructions.getLast(); m.visitLabel(caseDefault); m.visitInsn(Opcodes.RETURN); expectedNewTargets.add(m.instructions.getLast()); m.visitLabel(case1); m.visitInsn(Opcodes.RETURN); expectedNewTargets.add(m.instructions.getLast()); filter.filter(m, context, output); assertReplacedBranches(switchNode, expectedNewTargets); assertIgnored(new Range(switchNode.getNext(), expectedToInclusive)); }
From source file:org.jacoco.core.internal.analysis.filter.StringSwitchEcjFilterTest.java
License:Open Source License
@Test public void should_not_filter_empty_lookup_switch() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "name", "(Ljava/lang/String;)V", null, null);/* w w w . j av a2 s .c o m*/ m.visitVarInsn(Opcodes.ALOAD, 1); m.visitVarInsn(Opcodes.ASTORE, 2); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false); final Label defaultCase = new Label(); m.visitLookupSwitchInsn(defaultCase, null, new Label[] {}); m.visitLabel(defaultCase); m.visitInsn(Opcodes.RETURN); filter.filter(m, context, output); assertIgnored(); }