aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core/src/org/jacoco/core/internal/flow
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2011-01-19 08:44:38 +0000
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2011-01-19 08:44:38 +0000
commit66aa380fc544f5646d507ad8cc8ce539866f005c (patch)
tree34f4c042b69a08e5304b2c344815d96dd12b356b /org.jacoco.core/src/org/jacoco/core/internal/flow
parent5c8983fa7d6995bd39a104981f0eb637c62b59f1 (diff)
downloadjacoco-66aa380fc544f5646d507ad8cc8ce539866f005c.tar.gz
SF #3161106: Allow any number of probes in static interface initializers
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/internal/flow')
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java29
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/flow/IClassProbesVisitor.java6
2 files changed, 32 insertions, 3 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java b/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java
index 60e4cb35..fe09dfbf 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java
@@ -15,6 +15,7 @@ import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.EmptyVisitor;
import org.objectweb.asm.commons.JSRInlinerAdapter;
@@ -50,10 +51,20 @@ public class ClassProbesAdapter extends ClassAdapter implements
EMPTY_BLOCK_METHOD_VISITOR = new Impl();
}
+ private static class ProbeCounter implements IProbeIdGenerator {
+ int count = 0;
+
+ public int nextId() {
+ return count++;
+ }
+ }
+
private final IClassProbesVisitor cv;
private int counter = 0;
+ private boolean interfaceType;
+
/**
* Creates a new adapter that delegates to the given visitor.
*
@@ -66,6 +77,14 @@ public class ClassProbesAdapter extends ClassAdapter implements
}
@Override
+ public void visit(final int version, final int access, final String name,
+ final String signature, final String superName,
+ final String[] interfaces) {
+ interfaceType = (access & Opcodes.ACC_INTERFACE) != 0;
+ super.visit(version, access, name, signature, superName, interfaces);
+ }
+
+ @Override
public final MethodVisitor visitMethod(final int access, final String name,
final String desc, final String signature, final String[] exceptions) {
final IMethodProbesVisitor methodProbes;
@@ -84,6 +103,12 @@ public class ClassProbesAdapter extends ClassAdapter implements
public void visitEnd() {
super.visitEnd();
this.accept(new LabelFlowAnalyzer());
+ if (interfaceType) {
+ final ProbeCounter counter = new ProbeCounter();
+ this.accept(new MethodProbesAdapter(
+ EMPTY_BLOCK_METHOD_VISITOR, counter));
+ cv.visitTotalProbeCount(counter.count);
+ }
this.accept(new MethodProbesAdapter(methodProbes,
ClassProbesAdapter.this));
}
@@ -92,7 +117,9 @@ public class ClassProbesAdapter extends ClassAdapter implements
@Override
public void visitEnd() {
- cv.visitTotalProbeCount(counter);
+ if (!interfaceType) {
+ cv.visitTotalProbeCount(counter);
+ }
super.visitEnd();
}
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/flow/IClassProbesVisitor.java b/org.jacoco.core/src/org/jacoco/core/internal/flow/IClassProbesVisitor.java
index 67fcb7c4..afb4a559 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/flow/IClassProbesVisitor.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/IClassProbesVisitor.java
@@ -23,8 +23,10 @@ public interface IClassProbesVisitor extends ClassVisitor {
String desc, String signature, String[] exceptions);
/**
- * Reports the total number of encountered probes. This method is called
- * just before {@link ClassVisitor#visitEnd()}.
+ * Reports the total number of encountered probes. For classes this method
+ * is called just before {@link ClassVisitor#visitEnd()}. For interfaces
+ * this method is called before the first method (the static initializer) is
+ * emitted.
*
* @param count
* total number of probes