diff options
author | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2017-04-03 17:04:22 +0200 |
---|---|---|
committer | Evgeny Mandrikov <Godin@users.noreply.github.com> | 2017-04-03 17:04:22 +0200 |
commit | 7f719c8365b3ac8853cfc8b62fd48d2eabddfc4c (patch) | |
tree | 0987bc32b552de06e3b4e76fb92c1668108bdcc3 /org.jacoco.core/src/org/jacoco/core/internal/analysis | |
parent | 40035a00a45f6e817d230334a065716827a69c15 (diff) | |
download | jacoco-7f719c8365b3ac8853cfc8b62fd48d2eabddfc4c.tar.gz |
Add filter for methods annotated with @lombok.Generated (#513)
Based on initial contribution by RĂ¼diger zu Dohna.
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/internal/analysis')
-rw-r--r-- | org.jacoco.core/src/org/jacoco/core/internal/analysis/MethodAnalyzer.java | 9 | ||||
-rw-r--r-- | org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/LombokGeneratedFilter.java | 44 |
2 files changed, 50 insertions, 3 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/MethodAnalyzer.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/MethodAnalyzer.java index a912e333..e5dde709 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/MethodAnalyzer.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/MethodAnalyzer.java @@ -21,6 +21,7 @@ import org.jacoco.core.analysis.IMethodCoverage; import org.jacoco.core.analysis.ISourceNode; import org.jacoco.core.internal.analysis.filter.IFilter; import org.jacoco.core.internal.analysis.filter.IFilterOutput; +import org.jacoco.core.internal.analysis.filter.LombokGeneratedFilter; import org.jacoco.core.internal.analysis.filter.SynchronizedFilter; import org.jacoco.core.internal.analysis.filter.SyntheticFilter; import org.jacoco.core.internal.flow.IFrame; @@ -42,7 +43,8 @@ public class MethodAnalyzer extends MethodProbesVisitor implements IFilterOutput { private static final IFilter[] FILTERS = new IFilter[] { - new SyntheticFilter(), new SynchronizedFilter() }; + new SyntheticFilter(), new SynchronizedFilter(), + new LombokGeneratedFilter() }; private final boolean[] probes; @@ -328,8 +330,9 @@ public class MethodAnalyzer extends MethodProbesVisitor final int covered = i.getCoveredBranches(); final ICounter instrCounter = covered == 0 ? CounterImpl.COUNTER_1_0 : CounterImpl.COUNTER_0_1; - final ICounter branchCounter = total > 1 ? CounterImpl.getInstance( - total - covered, covered) : CounterImpl.COUNTER_0_0; + final ICounter branchCounter = total > 1 + ? CounterImpl.getInstance(total - covered, covered) + : CounterImpl.COUNTER_0_0; coverage.increment(instrCounter, branchCounter, i.getLine()); } coverage.incrementMethodCounter(); diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/LombokGeneratedFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/LombokGeneratedFilter.java new file mode 100644 index 00000000..9f23ecd8 --- /dev/null +++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/LombokGeneratedFilter.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Marc R. Hoffmann - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.internal.analysis.filter; + +import java.util.List; + +import org.objectweb.asm.tree.AnnotationNode; +import org.objectweb.asm.tree.MethodNode; + +/** + * Filters methods annotated with <code>@lombok.Generated</code>. + */ +public class LombokGeneratedFilter implements IFilter { + + public void filter(final MethodNode methodNode, + final IFilterOutput output) { + if (hasLombokGeneratedAnnotation(methodNode)) { + output.ignore(methodNode.instructions.getFirst(), + methodNode.instructions.getLast()); + } + } + + private boolean hasLombokGeneratedAnnotation(final MethodNode methodNode) { + final List<AnnotationNode> runtimeInvisibleAnnotations = methodNode.invisibleAnnotations; + if (runtimeInvisibleAnnotations != null) { + for (final AnnotationNode annotation : runtimeInvisibleAnnotations) { + if ("Llombok/Generated;".equals(annotation.desc)) { + return true; + } + } + } + return false; + } + +} |