Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filter for bridge methods (#1010)
- Loading branch information
Showing
6 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...est.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinDelegatesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...dation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDelegatesTarget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/BridgeFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters