public abstract class AbstractCodeProvider extends java.lang.Object implements CodeProvider
AbstractCodeProvider
implementations.
The methods realized here are independent on counters storing structure.Modifier and Type | Class and Description |
---|---|
(package private) static class |
AbstractCodeProvider.Abcd |
Modifier and Type | Field and Description |
---|---|
(package private) java.lang.String |
CLASSMAP_LISTENER_INTERNALNAME |
static int |
FAKE_COUNTER_ID
CounterId used to store unnecessary events to avoid fake jump counting in
instrumented(generated) code
|
COBERTURA_CLASSMAP_METHOD_NAME, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_GET_AND_RESET_COUNTERS_METHOD_NAME, COBERTURA_INIT_METHOD_NAME
Constructor and Description |
---|
AbstractCodeProvider() |
Modifier and Type | Method and Description |
---|---|
private void |
classMapContent(org.objectweb.asm.ClassVisitor cv,
int nr,
java.util.List<TouchPointDescriptor> touchPointDescriptors) |
void |
generateCallCoberturaInitMethod(org.objectweb.asm.MethodVisitor mv,
java.lang.String className) |
protected abstract void |
generateCINITmethod(org.objectweb.asm.MethodVisitor mv,
java.lang.String className,
int counters_cnt)
Generates code that is injected into static constructor of an instrumented class.
|
void |
generateCoberturaClassMapMethod(org.objectweb.asm.ClassVisitor cv,
ClassMap classMap)
The version of cobertura prior to 1.10 used *.ser file to store information of lines, jumps, switches and other
constructions used in the class.
|
void |
generateCoberturaInitMethod(org.objectweb.asm.ClassVisitor cv,
java.lang.String className,
int countersCnt) |
void |
generateCodeThatIncrementsCoberturaCounterIfVariableEqualsAndCleanVariable(org.objectweb.asm.MethodVisitor nextMethodVisitor,
java.lang.Integer neededJumpCounterIdVariableValue,
java.lang.Integer counterIdToIncrement,
int lastJumpIdVariableIndex,
java.lang.String className)
Injects code that behaves the same as such a code snippet:
if (value('lastJumpIdVariableIndex')==neededJumpCounterIdVariableValue){
cobertura_counters.increment(counterIdToIncrement);
}
This snippet is used in switch case of switch statement.
|
void |
generateCodeThatSetsJumpCounterIdVariable(org.objectweb.asm.MethodVisitor nextMethodVisitor,
int new_value,
int lastJumpIdVariableIndex)
Injects code that sets internal variable (identified by lastJumpIdVariableIndex) to given value.
|
void |
generateCodeThatZeroJumpCounterIdVariable(org.objectweb.asm.MethodVisitor nextMethodVisitor,
int lastJumpIdVariableIndex)
Injects code that sets internal variable (identified by lastJumpIdVariableIndex) to zero.
|
protected void |
generateRegisterClass(org.objectweb.asm.MethodVisitor mv,
java.lang.String className)
The code injected by this implementation just registers the class using
TouchCollector.registerClass(Class) . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
generateCoberturaGetAndResetCountersMethod, generateCodeThatIncrementsCoberturaCounter, generateCodeThatIncrementsCoberturaCounterFromInternalVariable, generateCountersField
public static final int FAKE_COUNTER_ID
final java.lang.String CLASSMAP_LISTENER_INTERNALNAME
public AbstractCodeProvider()
public void generateCodeThatSetsJumpCounterIdVariable(org.objectweb.asm.MethodVisitor nextMethodVisitor, int new_value, int lastJumpIdVariableIndex)
CodeProvider
generateCodeThatSetsJumpCounterIdVariable
in interface CodeProvider
nextMethodVisitor
- - MethodVisitor
that is listener of code-generation eventsnew_value
- - value to set the variable tolastJumpIdVariableIndex
- - index of variable that have to be setpublic void generateCodeThatZeroJumpCounterIdVariable(org.objectweb.asm.MethodVisitor nextMethodVisitor, int lastJumpIdVariableIndex)
CodeProvider
generateCodeThatZeroJumpCounterIdVariable
in interface CodeProvider
nextMethodVisitor
- - MethodVisitor
that is listener of code-generation eventslastJumpIdVariableIndex
- - index of variable that have to be setpublic void generateCodeThatIncrementsCoberturaCounterIfVariableEqualsAndCleanVariable(org.objectweb.asm.MethodVisitor nextMethodVisitor, java.lang.Integer neededJumpCounterIdVariableValue, java.lang.Integer counterIdToIncrement, int lastJumpIdVariableIndex, java.lang.String className)
CodeProvider
if (value('lastJumpIdVariableIndex')==neededJumpCounterIdVariableValue){ cobertura_counters.increment(counterIdToIncrement); }This snippet is used in switch case of switch statement. We have a label and we want to ensure that we are executing the label in effect of switch statement-jump, and not other JUMP or fall-throught.
generateCodeThatIncrementsCoberturaCounterIfVariableEqualsAndCleanVariable
in interface CodeProvider
protected void generateRegisterClass(org.objectweb.asm.MethodVisitor mv, java.lang.String className)
TouchCollector.registerClass(Class)
. This way, during the
execution, touch collector knows that is responsible to ask the class after execution about a current status of the counters.public void generateCoberturaClassMapMethod(org.objectweb.asm.ClassVisitor cv, ClassMap classMap)
CodeProvider.COBERTURA_CLASSMAP_METHOD_NAME
) with such a signature:
__cobertura_classmap( LightClassmapListener
listener).
The method informs the listener about all lines, jumps and switches found, and about all counters tracking
the constructions.generateCoberturaClassMapMethod
in interface CodeProvider
cv
- - listener used to inject the codeclassMap
- - structure that is keeping all collected information about the class. The information from the structure will be stored as
method body.private void classMapContent(org.objectweb.asm.ClassVisitor cv, int nr, java.util.List<TouchPointDescriptor> touchPointDescriptors)
protected abstract void generateCINITmethod(org.objectweb.asm.MethodVisitor mv, java.lang.String className, int counters_cnt)
CodeProvider.generateCountersField(ClassVisitor)
),
or execute other code that should be executed when the class it used for the first time. Registering the class in
TouchCollector
would be a bright idea.
It is expected that all counter will be set to zero after that operation.mv
- - MethodVisitor
that is listener of code-generation eventsclassName
- - internal name (asm) of class being instrumentedcounters_cnt
- - information about how many counters are expected to be used by instrumentation code.
In most cases the method is responsible for allocating objects that will be used to store counters.public void generateCoberturaInitMethod(org.objectweb.asm.ClassVisitor cv, java.lang.String className, int countersCnt)
generateCoberturaInitMethod
in interface CodeProvider
public void generateCallCoberturaInitMethod(org.objectweb.asm.MethodVisitor mv, java.lang.String className)
generateCallCoberturaInitMethod
in interface CodeProvider