aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core/src/org
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2013-06-01 12:19:09 +0200
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2013-06-01 12:19:09 +0200
commite048201f115d862e1b99e78249ef9e720212c201 (patch)
treee127902553a8c7b40e8c1a847b619ffcfba1482b /org.jacoco.core/src/org
parent73a2235e02b93b114b2dee69b05ab07ae5a0693a (diff)
downloadjacoco-e048201f115d862e1b99e78249ef9e720212c201.tar.gz
Issue error when analyzing instrumented classes (GitHub #108)
Diffstat (limited to 'org.jacoco.core/src/org')
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/analysis/ClassAnalyzer.java11
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/instr/ClassInstrumenter.java27
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java23
3 files changed, 36 insertions, 25 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/ClassAnalyzer.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/ClassAnalyzer.java
index ee8f05a2..9fa52889 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/ClassAnalyzer.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/ClassAnalyzer.java
@@ -14,6 +14,8 @@ package org.jacoco.core.internal.analysis;
import org.jacoco.core.analysis.IMethodCoverage;
import org.jacoco.core.internal.flow.ClassProbesVisitor;
import org.jacoco.core.internal.flow.MethodProbesVisitor;
+import org.jacoco.core.internal.instr.InstrSupport;
+import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Opcodes;
/**
@@ -72,6 +74,8 @@ public class ClassAnalyzer extends ClassProbesVisitor {
public MethodProbesVisitor visitMethod(final int access, final String name,
final String desc, final String signature, final String[] exceptions) {
+ InstrSupport.assertNotInstrumented(name, coverage.getName());
+
// TODO: Use filter hook
if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
return null;
@@ -92,6 +96,13 @@ public class ClassAnalyzer extends ClassProbesVisitor {
}
@Override
+ public FieldVisitor visitField(final int access, final String name,
+ final String desc, final String signature, final Object value) {
+ InstrSupport.assertNotInstrumented(name, coverage.getName());
+ return super.visitField(access, name, desc, signature, value);
+ }
+
+ @Override
public void visitTotalProbeCount(final int count) {
// nothing to do
}
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/instr/ClassInstrumenter.java b/org.jacoco.core/src/org/jacoco/core/internal/instr/ClassInstrumenter.java
index 796a004a..d9fb76ea 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/instr/ClassInstrumenter.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/instr/ClassInstrumenter.java
@@ -11,8 +11,6 @@
*******************************************************************************/
package org.jacoco.core.internal.instr;
-import static java.lang.String.format;
-
import org.jacoco.core.internal.flow.ClassProbesVisitor;
import org.jacoco.core.internal.flow.MethodProbesVisitor;
import org.jacoco.core.runtime.IExecutionDataAccessorGenerator;
@@ -78,7 +76,7 @@ public class ClassInstrumenter extends ClassProbesVisitor {
@Override
public FieldVisitor visitField(final int access, final String name,
final String desc, final String signature, final Object value) {
- assertNotInstrumented(name, InstrSupport.DATAFIELD_NAME);
+ InstrSupport.assertNotInstrumented(name, className);
return super.visitField(access, name, desc, signature, value);
}
@@ -86,7 +84,7 @@ public class ClassInstrumenter extends ClassProbesVisitor {
public MethodProbesVisitor visitMethod(final int access, final String name,
final String desc, final String signature, final String[] exceptions) {
- assertNotInstrumented(name, InstrSupport.INITMETHOD_NAME);
+ InstrSupport.assertNotInstrumented(name, className);
final MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
exceptions);
@@ -119,27 +117,6 @@ public class ClassInstrumenter extends ClassProbesVisitor {
super.visitEnd();
}
- /**
- * Ensures that the given member does not correspond to a internal member
- * created by the instrumentation process. This would mean that the class
- * has been instrumented twice.
- *
- * @param member
- * name of the member to check
- * @param instrMember
- * name of a instrumentation member
- * @throws IllegalStateException
- * thrown if the member has the same name than the
- * instrumentation member
- */
- private void assertNotInstrumented(final String member,
- final String instrMember) throws IllegalStateException {
- if (member.equals(instrMember)) {
- throw new IllegalStateException(format(
- "Class %s is already instrumented.", className));
- }
- }
-
// === probe array strategies ===
private class ClassTypeStrategy implements IProbeArrayStrategy {
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java b/org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java
index 8bb46026..8c74a4b8 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java
@@ -11,6 +11,8 @@
*******************************************************************************/
package org.jacoco.core.internal.instr;
+import static java.lang.String.format;
+
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
@@ -61,6 +63,27 @@ public final class InstrSupport {
| Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL;
/**
+ * Ensures that the given member does not correspond to a internal member
+ * created by the instrumentation process. This would mean that the class is
+ * already instrumented.
+ *
+ * @param member
+ * name of the member to check
+ * @param owner
+ * name of the class owning the member
+ * @throws IllegalStateException
+ * thrown if the member has the same name than the
+ * instrumentation member
+ */
+ public static void assertNotInstrumented(final String member,
+ final String owner) throws IllegalStateException {
+ if (member.equals(DATAFIELD_NAME) || member.equals(INITMETHOD_NAME)) {
+ throw new IllegalStateException(format(
+ "Class %s is already instrumented.", owner));
+ }
+ }
+
+ /**
* Generates the instruction to push the given int value on the stack.
* Implementation taken from
* {@link org.objectweb.asm.commons.GeneratorAdapter#push(int)}.