aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core/src/org/jacoco/core/internal/flow
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2010-11-11 16:21:28 +0000
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2010-11-11 16:21:28 +0000
commit3872980c094a6ccdeee5db603512e76e90b65db7 (patch)
treec4acae17f176351ccf74ec3159c50bf6aa9798ec /org.jacoco.core/src/org/jacoco/core/internal/flow
parent44f9ba255c0e5da4580d66b8aa66ab299632f38a (diff)
downloadjacoco-3872980c094a6ccdeee5db603512e76e90b65db7.tar.gz
Track #66: probe position calculation
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/internal/flow')
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/flow/IProbeIdGenerator.java29
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/flow/LabelsInfo.java5
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java74
3 files changed, 108 insertions, 0 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/flow/IProbeIdGenerator.java b/org.jacoco.core/src/org/jacoco/core/internal/flow/IProbeIdGenerator.java
new file mode 100644
index 00000000..9cef1b8e
--- /dev/null
+++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/IProbeIdGenerator.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 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.flow;
+
+/**
+ * Internal interface to create probe ids unique within a class.
+ *
+ * @author Marc R. Hoffmann
+ * @version $qualified.bundle.version$
+ */
+public interface IProbeIdGenerator {
+
+ /**
+ * Returns the next unique probe id.
+ *
+ * @return unique probe id
+ */
+ int nextId();
+
+}
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/flow/LabelsInfo.java b/org.jacoco.core/src/org/jacoco/core/internal/flow/LabelsInfo.java
index 94bf6ecc..f96002eb 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/flow/LabelsInfo.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/LabelsInfo.java
@@ -198,6 +198,8 @@ final class LabelsInfo implements MethodVisitor {
public void visitInsn(final int opcode) {
switch (opcode) {
+ case Opcodes.RET:
+ throw new AssertionError("Subroutines not supported.");
case Opcodes.IRETURN:
case Opcodes.LRETURN:
case Opcodes.FRETURN:
@@ -236,6 +238,9 @@ final class LabelsInfo implements MethodVisitor {
}
public void visitJumpInsn(final int opcode, final Label label) {
+ if (opcode == Opcodes.JSR) {
+ throw new AssertionError("Subroutines not supported.");
+ }
target(label);
successor = opcode != Opcodes.GOTO;
}
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
new file mode 100644
index 00000000..2740937d
--- /dev/null
+++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 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.flow;
+
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodAdapter;
+import org.objectweb.asm.Opcodes;
+
+/**
+ * Adapter that creates additional visitor events for probes to be inserted into
+ * a method.
+ *
+ * @author Marc R. Hoffmann
+ * @version $qualified.bundle.version$
+ */
+final class MethodProbesAdapter extends MethodAdapter {
+
+ private final IMethodProbesVisitor probesVisitor;
+
+ private final IProbeIdGenerator idGenerator;
+
+ public MethodProbesAdapter(final IMethodProbesVisitor probesVisitor,
+ final IProbeIdGenerator idGenerator) {
+ super(probesVisitor);
+ this.probesVisitor = probesVisitor;
+ this.idGenerator = idGenerator;
+ }
+
+ @Override
+ public void visitLabel(final Label label) {
+ if (LabelsInfo.isMultiTarget(label) && LabelsInfo.isSuccessor(label)) {
+ probesVisitor.visitProbe(idGenerator.nextId());
+ }
+ probesVisitor.visitLabel(label);
+ }
+
+ @Override
+ public void visitInsn(final int opcode) {
+ switch (opcode) {
+ case Opcodes.IRETURN:
+ case Opcodes.LRETURN:
+ case Opcodes.FRETURN:
+ case Opcodes.DRETURN:
+ case Opcodes.ARETURN:
+ case Opcodes.RETURN:
+ case Opcodes.ATHROW:
+ probesVisitor.visitInsnWithProbe(opcode, idGenerator.nextId());
+ break;
+ default:
+ probesVisitor.visitInsn(opcode);
+ break;
+ }
+ }
+
+ @Override
+ public void visitJumpInsn(final int opcode, final Label label) {
+ if (LabelsInfo.isMultiTarget(label)) {
+ probesVisitor.visitJumpInsnWithProbe(opcode, label,
+ idGenerator.nextId());
+ } else {
+ probesVisitor.visitJumpInsn(opcode, label);
+ }
+ }
+
+}