aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core/src/org/jacoco/core/internal/flow
diff options
context:
space:
mode:
authorAllen Hair <allenhair@google.com>2014-12-16 10:18:04 -0800
committerAllen Hair <allenhair@google.com>2014-12-16 10:18:04 -0800
commitfdd2f4841ba466e3fa7e5c3df285478d06af422c (patch)
tree4eb4610a5cc380048d46bd8baba14912d80cfe03 /org.jacoco.core/src/org/jacoco/core/internal/flow
parent0974a254332d669e6b90f05bc1d999079dca202d (diff)
downloadjacoco-fdd2f4841ba466e3fa7e5c3df285478d06af422c.tar.gz
Extend try-catch blocks to cover inserted probes.
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/internal/flow')
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java b/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java
index 6d44bc5a..2fe7e315 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java
@@ -17,6 +17,9 @@ import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.AnalyzerAdapter;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Adapter that creates additional visitor events for probes to be inserted into
* a method.
@@ -29,6 +32,8 @@ public final class MethodProbesAdapter extends MethodVisitor {
private AnalyzerAdapter analyzer;
+ private Map<Label, Label> tryCatchProbeLabels = new HashMap<Label, Label>();
+
/**
* Create a new adapter instance.
*
@@ -56,8 +61,27 @@ public final class MethodProbesAdapter extends MethodVisitor {
}
@Override
+ public void visitTryCatchBlock(Label start, final Label end,
+ final Label handler, final String type) {
+ // If a probe will be inserted before the start label, we'll need to use a
+ // different label for the try-catch block.
+ if (tryCatchProbeLabels.containsKey(start)) {
+ start = tryCatchProbeLabels.get(start);
+ } else if (LabelInfo.isMultiTarget(start) && LabelInfo.isSuccessor(start)) {
+ Label probeLabel = new Label();
+ LabelInfo.setSuccessor(probeLabel);
+ tryCatchProbeLabels.put(start, probeLabel);
+ start = probeLabel;
+ }
+ probesVisitor.visitTryCatchBlock(start, end, handler, type);
+ }
+
+ @Override
public void visitLabel(final Label label) {
if (LabelInfo.isMultiTarget(label) && LabelInfo.isSuccessor(label)) {
+ if (tryCatchProbeLabels.containsKey(label)) {
+ probesVisitor.visitLabel(tryCatchProbeLabels.get(label));
+ }
probesVisitor.visitProbe(idGenerator.nextId());
}
probesVisitor.visitLabel(label);