diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinDelegatesTest.java b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinDelegatesTest.java new file mode 100644 index 0000000000..895bf89b50 --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinDelegatesTest.java @@ -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); + } + +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDelegatesTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDelegatesTarget.kt new file mode 100644 index 0000000000..f61a808e1d --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDelegatesTarget.kt @@ -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 by ArrayList() // assertFullyCovered() + + @JvmStatic + fun main(args: Array) { + DelegatedList() + } + +} diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/BridgeFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/BridgeFilterTest.java new file mode 100644 index 0000000000..b0dd1adc9a --- /dev/null +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/BridgeFilterTest.java @@ -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(); + } + +} diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java new file mode 100644 index 0000000000..78fe5ad66f --- /dev/null +++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java @@ -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()); + } + +} diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/Filters.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/Filters.java index 3ceff7bfa0..bbe041f6f8 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/Filters.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/Filters.java @@ -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(), diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html index 8049067ac3..da3817fc35 100644 --- a/org.jacoco.doc/docroot/doc/changes.html +++ b/org.jacoco.doc/docroot/doc/changes.html @@ -27,6 +27,8 @@

New Features

  • Methods toString, hashCode and equals generated by compiler for records are filtered out during generation of report (GitHub #990).
  • +
  • Bridge methods are filtered out during generation of report + (GitHub #1010).
  • Non-functional Changes