aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core/src/org/jacoco/core/internal/analysis/MethodAnalyzer.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/internal/analysis/MethodAnalyzer.java')
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/analysis/MethodAnalyzer.java55
1 files changed, 53 insertions, 2 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 b27c54bc..6736acae 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
@@ -12,23 +12,36 @@
package org.jacoco.core.internal.analysis;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.jacoco.core.analysis.ICounter;
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.SynchronizedFilter;
import org.jacoco.core.internal.flow.IFrame;
import org.jacoco.core.internal.flow.Instruction;
import org.jacoco.core.internal.flow.LabelInfo;
import org.jacoco.core.internal.flow.MethodProbesVisitor;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.MethodNode;
+import org.objectweb.asm.tree.TryCatchBlockNode;
/**
* A {@link MethodProbesVisitor} that analyzes which statements and branches of
* a method have been executed based on given probe data.
*/
-public class MethodAnalyzer extends MethodProbesVisitor {
+public class MethodAnalyzer extends MethodProbesVisitor
+ implements IFilterOutput {
+
+ private static final IFilter[] FILTERS = new IFilter[] {
+ new SynchronizedFilter() };
private final boolean[] probes;
@@ -86,6 +99,40 @@ public class MethodAnalyzer extends MethodProbesVisitor {
return coverage;
}
+ /**
+ * {@link MethodNode#accept(MethodVisitor)}
+ */
+ @Override
+ public void accept(final MethodNode methodNode,
+ final MethodVisitor methodVisitor) {
+ this.ignored.clear();
+ for (final IFilter filter : FILTERS) {
+ filter.filter(methodNode, this);
+ }
+
+ for (final TryCatchBlockNode n : methodNode.tryCatchBlocks) {
+ n.accept(methodVisitor);
+ }
+ currentNode = methodNode.instructions.getFirst();
+ while (currentNode != null) {
+ currentNode.accept(methodVisitor);
+ currentNode = currentNode.getNext();
+ }
+ methodVisitor.visitEnd();
+ }
+
+ private final Set<AbstractInsnNode> ignored = new HashSet<AbstractInsnNode>();
+ private AbstractInsnNode currentNode;
+
+ public void ignore(final AbstractInsnNode fromInclusive,
+ final AbstractInsnNode toInclusive) {
+ for (AbstractInsnNode i = fromInclusive; i != toInclusive; i = i
+ .getNext()) {
+ ignored.add(i);
+ }
+ ignored.add(toInclusive);
+ }
+
@Override
public void visitLabel(final Label label) {
currentLabel.add(label);
@@ -106,7 +153,7 @@ public class MethodAnalyzer extends MethodProbesVisitor {
}
private void visitInsn() {
- final Instruction insn = new Instruction(currentLine);
+ final Instruction insn = new Instruction(currentNode, currentLine);
instructions.add(insn);
if (lastInsn != null) {
insn.setPredecessor(lastInsn);
@@ -272,6 +319,10 @@ public class MethodAnalyzer extends MethodProbesVisitor {
// Report result:
coverage.ensureCapacity(firstLine, lastLine);
for (final Instruction i : instructions) {
+ if (ignored.contains(i.getNode())) {
+ continue;
+ }
+
final int total = i.getBranches();
final int covered = i.getCoveredBranches();
final ICounter instrCounter = covered == 0 ? CounterImpl.COUNTER_1_0