List of usage examples for org.objectweb.asm Opcodes RETURN
int RETURN
To view the source code for org.objectweb.asm Opcodes RETURN.
Click Source Link
From source file:org.jacoco.core.internal.analysis.filter.FinallyFilterTest.java
License:Open Source License
@Test public void ecj_always_completes_abruptly() { final Label tryStart = new Label(); final Label tryEnd = new Label(); final Label finallyStart = new Label(); m.visitTryCatchBlock(tryStart, tryEnd, tryEnd, null); m.visitLabel(tryStart);/*ww w . j av a 2s . c o m*/ m.visitInsn(Opcodes.NOP); // try body m.visitJumpInsn(Opcodes.GOTO, finallyStart); m.visitLabel(tryEnd); m.visitInsn(Opcodes.POP); m.visitLabel(finallyStart); m.visitInsn(Opcodes.RETURN); // finally body execute(); }
From source file:org.jacoco.core.internal.analysis.filter.KotlinDefaultArgumentsFilterTest.java
License:Open Source License
private static MethodNode createMethod(final int access, final String name, final String descriptor) { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, access, name, descriptor, null, null); m.visitVarInsn(Opcodes.ILOAD, 2);// w ww . j a v a 2 s .com m.visitInsn(Opcodes.ICONST_1); m.visitInsn(Opcodes.IAND); final Label label = new Label(); m.visitJumpInsn(Opcodes.IFEQ, label); // default argument m.visitLdcInsn(Integer.valueOf(42)); m.visitVarInsn(Opcodes.ISTORE, 1); m.visitLabel(label); m.visitVarInsn(Opcodes.ALOAD, 0); m.visitVarInsn(Opcodes.ILOAD, 1); m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Target", "origin", "(I)V", false); m.visitInsn(Opcodes.RETURN); return m; }
From source file:org.jacoco.core.internal.analysis.filter.KotlinDefaultArgumentsFilterTest.java
License:Open Source License
/** * <pre>// ww w. j a v a2s .c o m * open class Open { * open fun foo(a: Int = 42) { * } * } * </pre> */ @Test public void should_filter_open_functions() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "foo$default", "(LOpen;IILjava/lang/Object;)V", null, null); context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); { m.visitVarInsn(Opcodes.ALOAD, 3); final Label label = new Label(); m.visitJumpInsn(Opcodes.IFNULL, label); m.visitTypeInsn(Opcodes.NEW, "java/lang/UnsupportedOperationException"); m.visitInsn(Opcodes.DUP); m.visitLdcInsn("Super calls with default arguments not supported in this target, function: foo"); m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>", "(Ljava/lang/String;)V", false); m.visitInsn(Opcodes.ATHROW); m.visitLabel(label); } { m.visitVarInsn(Opcodes.ILOAD, 2); m.visitInsn(Opcodes.ICONST_1); m.visitInsn(Opcodes.IAND); final Label label = new Label(); m.visitJumpInsn(Opcodes.IFEQ, label); // default argument m.visitLdcInsn(Integer.valueOf(42)); m.visitVarInsn(Opcodes.ISTORE, 1); m.visitLabel(label); m.visitVarInsn(Opcodes.ALOAD, 0); m.visitVarInsn(Opcodes.ILOAD, 1); m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Open", "foo", "(I)V", false); m.visitInsn(Opcodes.RETURN); } filter.filter(m, context, output); assertIgnored(new Range(m.instructions.getFirst(), m.instructions.get(6)), new Range(m.instructions.get(11), m.instructions.get(11))); }
From source file:org.jacoco.core.internal.analysis.filter.KotlinDefaultArgumentsFilterTest.java
License:Open Source License
/** * <pre>/*from w w w. ja v a2 s. c o m*/ * class C(a: Int = 42) * </pre> */ @Test public void should_filter_constructors() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "<init>", "(IILkotlin/jvm/internal/DefaultConstructorMarker;)V", null, null); context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); m.visitVarInsn(Opcodes.ILOAD, 2); m.visitInsn(Opcodes.ICONST_1); m.visitInsn(Opcodes.IAND); Label label = new Label(); m.visitJumpInsn(Opcodes.IFEQ, label); // default argument m.visitLdcInsn(Integer.valueOf(42)); m.visitVarInsn(Opcodes.ISTORE, 1); m.visitLabel(label); m.visitVarInsn(Opcodes.ALOAD, 0); m.visitVarInsn(Opcodes.ILOAD, 1); m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Owner", "<init>", "(I)V", false); m.visitInsn(Opcodes.RETURN); filter.filter(m, context, output); assertIgnored(new Range(m.instructions.get(3), m.instructions.get(3))); }
From source file:org.jacoco.core.internal.analysis.filter.KotlinDefaultArgumentsFilterTest.java
License:Open Source License
/** * <pre>/*from ww w. j a va 2s .c om*/ * data class C(val x: Long = 42) * </pre> */ @Test public void should_filter_methods_with_parameters_that_consume_two_slots() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "<init>", "(JILkotlin/jvm/internal/DefaultConstructorMarker;)V", null, null); context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); m.visitVarInsn(Opcodes.ILOAD, 3); m.visitInsn(Opcodes.ICONST_1); m.visitInsn(Opcodes.IAND); final Label label = new Label(); m.visitJumpInsn(Opcodes.IFEQ, label); // default argument m.visitLdcInsn(Integer.valueOf(42)); m.visitVarInsn(Opcodes.ISTORE, 1); m.visitLabel(label); m.visitVarInsn(Opcodes.ALOAD, 0); m.visitVarInsn(Opcodes.ILOAD, 1); m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Owner", "<init>", "(J)V", false); m.visitInsn(Opcodes.RETURN); filter.filter(m, context, output); assertIgnored(new Range(m.instructions.get(3), m.instructions.get(3))); }
From source file:org.jacoco.core.internal.analysis.filter.KotlinInlineFilterTest.java
License:Open Source License
@Test public void should_filter() { context.sourceFileName = "callsite.kt"; context.sourceDebugExtension = "" // + "SMAP\n" // + "callsite.kt\n" // OutputFileName=callsite.kt + "Kotlin\n" // DefaultStratumId=Kotlin + "*S Kotlin\n" // StratumID=Kotlin + "*F\n" // FileSection + "+ 1 callsite.kt\n" // FileID=1,FileName=callsite.kt + "CallsiteKt\n" // + "+ 2 a.kt\n" // FileID=2,FileName=a.kt + "AKt\n" // + "+ 3 b.kt\n" // FileID=3,FileName=b.kt + "BKt\n" // + "*L\n" // LineSection + "1#1,8:1\n" // InputStartLine=1,LineFileID=1,RepeatCount=8,OutputStartLine=1 + "2#2,2:9\n" // InputStartLine=2,LineFileID=2,RepeatCount=2,OutputStartLine=9 + "2#3,2:11\n" // InputStartLine=2,LineFileID=3,RepeatCount=2,OutputStartLine=11 + "*E\n"; // EndSection context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); m.visitLineNumber(2, new Label()); m.visitInsn(Opcodes.NOP);//ww w. jav a 2s . c om m.visitLineNumber(9, new Label()); shouldIgnorePrevious(m); m.visitMethodInsn(Opcodes.INVOKESTATIC, "Stubs", "nop", "()V", false); shouldIgnorePrevious(m); m.visitLineNumber(10, new Label()); shouldIgnorePrevious(m); m.visitInsn(Opcodes.NOP); shouldIgnorePrevious(m); m.visitLineNumber(3, new Label()); m.visitInsn(Opcodes.NOP); m.visitLineNumber(11, new Label()); shouldIgnorePrevious(m); m.visitMethodInsn(Opcodes.INVOKESTATIC, "Stubs", "nop", "()V", false); shouldIgnorePrevious(m); m.visitLineNumber(12, new Label()); shouldIgnorePrevious(m); m.visitInsn(Opcodes.NOP); shouldIgnorePrevious(m); m.visitLineNumber(4, new Label()); m.visitInsn(Opcodes.RETURN); filter.filter(m, context, output); assertIgnored(expectedRanges.toArray(new Range[0])); // should not reparse: context.sourceDebugExtension = ""; filter.filter(m, context, output); }
From source file:org.jacoco.core.internal.analysis.filter.KotlinInlineFilterTest.java
License:Open Source License
/** * <pre>//from w w w. j a v a2 s. co m * inline fun inlined_top_level() { * Stubs.nop() * } * * class Callsite { * fun inlined() { * Stubs.nop() * } * * fun callsite { * inlined_top_level() * inlined() * } * } * </pre> */ @Test public void should_filter_when_in_same_file() { context.sourceFileName = "example.kt"; context.sourceDebugExtension = "" // + "SMAP\n" // + "example.kt\n" // OutputFileName=example.kt + "Kotlin\n" // DefaultStratumId=Kotlin + "*S Kotlin\n" // StratumID=Kotlin + "*F\n" // FileSection + "+ 1 example.kt\n" // FileID=1,FileName=example.kt + "Callsite\n" // + "+ 2 example.kt\n" // FileID=2,FileName=example.kt + "ExampleKt\n" // + "*L\n" // LineSection + "1#1,15:1\n" // InputStartLine=1,LineFileID=1,RepeatCount=10,OutputStartLine=1 + "7#1,2:18\n" // InputStartLine=7,LineFileID=1,RepeatCount=2,OutputStartLine=18 + "2#2,2:16\n" // InputStartLine=2,LineFileID=2,RepeatCount=2,OutputStartLine=16 + "*E\n"; // EndSection context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); m.visitLineNumber(11, new Label()); m.visitInsn(Opcodes.NOP); m.visitLineNumber(16, new Label()); shouldIgnorePrevious(m); m.visitMethodInsn(Opcodes.INVOKESTATIC, "Stubs", "nop", "()V", false); shouldIgnorePrevious(m); m.visitLineNumber(17, new Label()); shouldIgnorePrevious(m); m.visitInsn(Opcodes.NOP); shouldIgnorePrevious(m); m.visitLineNumber(12, new Label()); m.visitVarInsn(Opcodes.ALOAD, 0); m.visitVarInsn(Opcodes.ASTORE, 1); m.visitLineNumber(18, new Label()); shouldIgnorePrevious(m); m.visitMethodInsn(Opcodes.INVOKESTATIC, "Stubs", "nop", "()V", false); shouldIgnorePrevious(m); m.visitLineNumber(19, new Label()); shouldIgnorePrevious(m); m.visitInsn(Opcodes.NOP); shouldIgnorePrevious(m); m.visitLineNumber(13, new Label()); m.visitInsn(Opcodes.RETURN); filter.filter(m, context, output); assertIgnored(expectedRanges.toArray(new Range[0])); }
From source file:org.jacoco.core.internal.analysis.filter.KotlinInlineFilterTest.java
License:Open Source License
@Test public void should_not_parse_SourceDebugExtension_attribute_when_no_kotlin_metadata_annotation() { context.sourceDebugExtension = "SMAP"; m.visitLineNumber(1, new Label()); m.visitInsn(Opcodes.RETURN); filter.filter(m, context, output);/*w w w .j av a 2 s. com*/ assertIgnored(); }
From source file:org.jacoco.core.internal.analysis.filter.KotlinInlineFilterTest.java
License:Open Source License
@Test public void should_not_filter_when_no_SourceDebugExtension_attribute() { context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); m.visitLineNumber(1, new Label()); m.visitInsn(Opcodes.RETURN); filter.filter(m, context, output);/*from ww w . jav a 2 s. c o m*/ assertIgnored(); }
From source file:org.jacoco.core.internal.analysis.filter.KotlinWhenStringFilterTest.java
License:Open Source License
@Test public void should_filter() { final Set<AbstractInsnNode> expectedNewTargets = new HashSet<AbstractInsnNode>(); final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "name", "()V", null, null); final Label h1 = new Label(); final Label sameHash = new Label(); final Label h2 = new Label(); final Label case1 = new Label(); final Label case2 = new Label(); final Label case3 = new Label(); final Label defaultCase = new Label(); // filter should not remember this unrelated slot m.visitLdcInsn(""); m.visitVarInsn(Opcodes.ASTORE, 1);/*w ww . j a v a2s . com*/ m.visitVarInsn(Opcodes.ALOAD, 1); // switch (...) m.visitVarInsn(Opcodes.ASTORE, 2); m.visitVarInsn(Opcodes.ALOAD, 2); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false); m.visitTableSwitchInsn(97, 98, defaultCase, h1, h2); // case "a" m.visitLabel(h1); final AbstractInsnNode expectedFromInclusive = m.instructions.getLast(); m.visitVarInsn(Opcodes.ALOAD, 2); m.visitLdcInsn("a"); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); m.visitJumpInsn(Opcodes.IFEQ, sameHash); m.visitJumpInsn(Opcodes.GOTO, case1); // case "\u0000a" m.visitLabel(sameHash); m.visitVarInsn(Opcodes.ALOAD, 2); m.visitLdcInsn("\u0000a"); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); m.visitJumpInsn(Opcodes.IFEQ, defaultCase); m.visitJumpInsn(Opcodes.GOTO, case2); // case "b" m.visitLabel(h2); m.visitVarInsn(Opcodes.ALOAD, 2); m.visitLdcInsn("\u0000a"); m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); m.visitJumpInsn(Opcodes.IFEQ, defaultCase); m.visitJumpInsn(Opcodes.GOTO, case3); final AbstractInsnNode expectedToInclusive = m.instructions.getLast(); m.visitLabel(case1); m.visitInsn(Opcodes.RETURN); expectedNewTargets.add(m.instructions.getLast()); m.visitLabel(case2); m.visitInsn(Opcodes.RETURN); expectedNewTargets.add(m.instructions.getLast()); m.visitLabel(case3); m.visitInsn(Opcodes.RETURN); expectedNewTargets.add(m.instructions.getLast()); m.visitLabel(defaultCase); m.visitInsn(Opcodes.RETURN); expectedNewTargets.add(m.instructions.getLast()); filter.filter(m, context, output); assertReplacedBranches(expectedFromInclusive.getPrevious(), expectedNewTargets); assertIgnored(new Range(expectedFromInclusive, expectedToInclusive)); }