Skip to content

Commit

Permalink
(WIP) add filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin committed Oct 26, 2018
1 parent 8ff17aa commit bdb5be3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package org.jacoco.core.test.validation.kotlin.targets
*/
object KotlinDefaultArgumentsTarget {

private fun f(a: String = "a", b: String = "b") { // assertFullyCovered(0, 2)
private fun f(a: String = "a", b: String = "b") { // assertFullyCovered(0, 0)
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

public class KotlinDefaultArgumentsFilterTest extends FilterTestBase {

private final IFilter filter = new KotlinDefaultArgumentsFilter();

private static MethodNode createMethod(final int access, final String name,
final String descriptor) {
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
Expand Down Expand Up @@ -48,6 +50,8 @@ public void should_filter() {
final MethodNode m = createMethod(Opcodes.ACC_SYNTHETIC,
"origin$default", "(LTarget;IILjava/lang/Object;)V");

filter.filter(m, context, output);

assertIgnored(new Range(m.instructions.get(3), m.instructions.get(3)));
}

Expand All @@ -56,6 +60,8 @@ public void should_not_filter_when_suffix_absent() {
final MethodNode m = createMethod(Opcodes.ACC_SYNTHETIC,
"synthetic_without_suffix", "(LTarget;IILjava/lang/Object;)V");

filter.filter(m, context, output);

assertIgnored();
}

Expand All @@ -64,6 +70,8 @@ public void should_not_filter_when_not_synthetic() {
final MethodNode m = createMethod(0, "not_synthetic$default",
"(LTarget;IILjava/lang/Object;)V");

filter.filter(m, context, output);

assertIgnored();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public final class Filters implements IFilter {
new EnumEmptyConstructorFilter(), new AnnotationGeneratedFilter(),
new KotlinGeneratedFilter(), new KotlinLateinitFilter(),
new KotlinWhenFilter(), new KotlinWhenStringFilter(),
new KotlinUnsafeCastOperatorFilter());
new KotlinUnsafeCastOperatorFilter(),
new KotlinDefaultArgumentsFilter());

private final IFilter[] filters;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Evgeny Mandrikov - initial API and implementation
*
*******************************************************************************/
package org.jacoco.core.internal.analysis.filter;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.VarInsnNode;

public final class KotlinDefaultArgumentsFilter implements IFilter {

private static final String SUFFIX = "$default";

public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
if ((methodNode.access & Opcodes.ACC_SYNTHETIC) == 0) {
return;
}
if (!methodNode.name.endsWith(SUFFIX)) {
return;
}

final int maskVar = Type.getMethodType(methodNode.desc)
.getArgumentTypes().length - 2;

for (AbstractInsnNode i = methodNode.instructions
.getFirst(); i != null; i = i.getNext()) {
if (AbstractInsnNode.VAR_INSN != i.getType()) {
continue;
}
if (maskVar != ((VarInsnNode) i).var) {
continue;
}

final AbstractInsnNode jump = i.getNext().getNext().getNext();
output.ignore(jump, jump);
}

}

}

0 comments on commit bdb5be3

Please sign in to comment.