Skip to content

Commit

Permalink
Add filter for bridge methods (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin committed Feb 1, 2020
1 parent d013ac8 commit 468fa99
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 1 deletion.
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 Mountainminds GmbH & Co. KG and Contributors
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Evgeny Mandrikov - initial API and implementation
*
*******************************************************************************/
package org.jacoco.core.test.validation.kotlin;

import org.jacoco.core.test.validation.ValidationTestBase;
import org.jacoco.core.test.validation.kotlin.targets.KotlinDelegatesTarget;

/**
* Test of code coverage in {@link KotlinDelegatesTarget}.
*/
public class KotlinDelegatesTest extends ValidationTestBase {

public KotlinDelegatesTest() {
super(KotlinDelegatesTarget.class);
}

}
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 Mountainminds GmbH & Co. KG and Contributors
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Evgeny Mandrikov - initial API and implementation
*
*******************************************************************************/
package org.jacoco.core.test.validation.kotlin.targets

/**
* This test target contains different delegates.
*/
object KotlinDelegatesTarget {

class DelegatedList : List<Int> by ArrayList() // assertFullyCovered()

@JvmStatic
fun main(args: Array<String>) {
DelegatedList()
}

}
@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 Mountainminds GmbH & Co. KG and Contributors
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Evgeny Mandrikov - initial API and implementation
*
*******************************************************************************/
package org.jacoco.core.internal.analysis.filter;

import org.jacoco.core.internal.instr.InstrSupport;
import org.junit.Test;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.MethodNode;

/**
* Unit tests for {@link BridgeFilter}.
*/
public class BridgeFilterTest extends FilterTestBase {

private final BridgeFilter filter = new BridgeFilter();

@Test
public void should_filter_bridge_methods() {
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
Opcodes.ACC_BRIDGE, "m", "()Ljava/lang/Object;", null, null);
m.visitInsn(Opcodes.NOP);

filter.filter(m, context, output);

assertMethodIgnored(m);
}

@Test
public void should_not_filter_non_bridge_methods() {
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0,
"m", "()Ljava/lang/Object;", null, null);
m.visitInsn(Opcodes.NOP);

filter.filter(m, context, output);

assertIgnored();
}

}
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 Mountainminds GmbH & Co. KG and Contributors
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Evgeny Mandrikov - initial API and implementation
*
*******************************************************************************/
package org.jacoco.core.internal.analysis.filter;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.MethodNode;

/**
* Filters bridge methods.
*/
final class BridgeFilter implements IFilter {

public void filter(final MethodNode methodNode,
final IFilterContext context, final IFilterOutput output) {
if ((methodNode.access & Opcodes.ACC_BRIDGE) == 0) {
return;
}
output.ignore(methodNode.instructions.getFirst(),
methodNode.instructions.getLast());
}

}
Expand Up @@ -33,7 +33,8 @@ public final class Filters implements IFilter {
*/
public static IFilter all() {
return new Filters(new EnumFilter(), new SyntheticFilter(),
new SynchronizedFilter(), new TryWithResourcesJavac11Filter(),
new BridgeFilter(), new SynchronizedFilter(),
new TryWithResourcesJavac11Filter(),
new TryWithResourcesJavacFilter(),
new TryWithResourcesEcjFilter(), new FinallyFilter(),
new PrivateEmptyNoArgConstructorFilter(),
Expand Down
2 changes: 2 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -27,6 +27,8 @@ <h3>New Features</h3>
<li>Methods <code>toString</code>, <code>hashCode</code> and <code>equals</code>
generated by compiler for records are filtered out during generation of report
(GitHub <a href="https://github.com/jacoco/jacoco/issues/990">#990</a>).</li>
<li>Bridge methods are filtered out during generation of report
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1010">#1010</a>).</li>
</ul>

<h3>Non-functional Changes</h3>
Expand Down

0 comments on commit 468fa99

Please sign in to comment.