Skip to content

Commit 468fa99

Browse files
authored
Add filter for bridge methods (jacoco#1010)
1 parent d013ac8 commit 468fa99

File tree

6 files changed

+139
-1
lines changed

6 files changed

+139
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2009, 2020 Mountainminds GmbH & Co. KG and Contributors
3+
* This program and the accompanying materials are made available under
4+
* the terms of the Eclipse Public License 2.0 which is available at
5+
* http://www.eclipse.org/legal/epl-2.0
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Evgeny Mandrikov - initial API and implementation
11+
*
12+
*******************************************************************************/
13+
package org.jacoco.core.test.validation.kotlin;
14+
15+
import org.jacoco.core.test.validation.ValidationTestBase;
16+
import org.jacoco.core.test.validation.kotlin.targets.KotlinDelegatesTarget;
17+
18+
/**
19+
* Test of code coverage in {@link KotlinDelegatesTarget}.
20+
*/
21+
public class KotlinDelegatesTest extends ValidationTestBase {
22+
23+
public KotlinDelegatesTest() {
24+
super(KotlinDelegatesTarget.class);
25+
}
26+
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2009, 2020 Mountainminds GmbH & Co. KG and Contributors
3+
* This program and the accompanying materials are made available under
4+
* the terms of the Eclipse Public License 2.0 which is available at
5+
* http://www.eclipse.org/legal/epl-2.0
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Evgeny Mandrikov - initial API and implementation
11+
*
12+
*******************************************************************************/
13+
package org.jacoco.core.test.validation.kotlin.targets
14+
15+
/**
16+
* This test target contains different delegates.
17+
*/
18+
object KotlinDelegatesTarget {
19+
20+
class DelegatedList : List<Int> by ArrayList() // assertFullyCovered()
21+
22+
@JvmStatic
23+
fun main(args: Array<String>) {
24+
DelegatedList()
25+
}
26+
27+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2009, 2020 Mountainminds GmbH & Co. KG and Contributors
3+
* This program and the accompanying materials are made available under
4+
* the terms of the Eclipse Public License 2.0 which is available at
5+
* http://www.eclipse.org/legal/epl-2.0
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Evgeny Mandrikov - initial API and implementation
11+
*
12+
*******************************************************************************/
13+
package org.jacoco.core.internal.analysis.filter;
14+
15+
import org.jacoco.core.internal.instr.InstrSupport;
16+
import org.junit.Test;
17+
import org.objectweb.asm.Opcodes;
18+
import org.objectweb.asm.tree.MethodNode;
19+
20+
/**
21+
* Unit tests for {@link BridgeFilter}.
22+
*/
23+
public class BridgeFilterTest extends FilterTestBase {
24+
25+
private final BridgeFilter filter = new BridgeFilter();
26+
27+
@Test
28+
public void should_filter_bridge_methods() {
29+
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
30+
Opcodes.ACC_BRIDGE, "m", "()Ljava/lang/Object;", null, null);
31+
m.visitInsn(Opcodes.NOP);
32+
33+
filter.filter(m, context, output);
34+
35+
assertMethodIgnored(m);
36+
}
37+
38+
@Test
39+
public void should_not_filter_non_bridge_methods() {
40+
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0,
41+
"m", "()Ljava/lang/Object;", null, null);
42+
m.visitInsn(Opcodes.NOP);
43+
44+
filter.filter(m, context, output);
45+
46+
assertIgnored();
47+
}
48+
49+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2009, 2020 Mountainminds GmbH & Co. KG and Contributors
3+
* This program and the accompanying materials are made available under
4+
* the terms of the Eclipse Public License 2.0 which is available at
5+
* http://www.eclipse.org/legal/epl-2.0
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Evgeny Mandrikov - initial API and implementation
11+
*
12+
*******************************************************************************/
13+
package org.jacoco.core.internal.analysis.filter;
14+
15+
import org.objectweb.asm.Opcodes;
16+
import org.objectweb.asm.tree.MethodNode;
17+
18+
/**
19+
* Filters bridge methods.
20+
*/
21+
final class BridgeFilter implements IFilter {
22+
23+
public void filter(final MethodNode methodNode,
24+
final IFilterContext context, final IFilterOutput output) {
25+
if ((methodNode.access & Opcodes.ACC_BRIDGE) == 0) {
26+
return;
27+
}
28+
output.ignore(methodNode.instructions.getFirst(),
29+
methodNode.instructions.getLast());
30+
}
31+
32+
}

org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/Filters.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public final class Filters implements IFilter {
3333
*/
3434
public static IFilter all() {
3535
return new Filters(new EnumFilter(), new SyntheticFilter(),
36-
new SynchronizedFilter(), new TryWithResourcesJavac11Filter(),
36+
new BridgeFilter(), new SynchronizedFilter(),
37+
new TryWithResourcesJavac11Filter(),
3738
new TryWithResourcesJavacFilter(),
3839
new TryWithResourcesEcjFilter(), new FinallyFilter(),
3940
new PrivateEmptyNoArgConstructorFilter(),

org.jacoco.doc/docroot/doc/changes.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ <h3>New Features</h3>
2727
<li>Methods <code>toString</code>, <code>hashCode</code> and <code>equals</code>
2828
generated by compiler for records are filtered out during generation of report
2929
(GitHub <a href="https://github.com/jacoco/jacoco/issues/990">#990</a>).</li>
30+
<li>Bridge methods are filtered out during generation of report
31+
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1010">#1010</a>).</li>
3032
</ul>
3133

3234
<h3>Non-functional Changes</h3>

0 commit comments

Comments
 (0)