Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter for bridge methods #1010

Merged
merged 5 commits into from Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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