public class InjectCodeTouchPointListener extends java.lang.Object implements TouchPointListener
codeProvider
into the instrumented method's body. Injects code that
is responsible for incrementing counters. Mapping of places into counters is provided by classMap
.Modifier and Type | Field and Description |
---|---|
private ClassMap |
classMap
Source of mapping from place (eventId) into counterId that is incremented if the place is touched
|
private CodeProvider |
codeProvider
Component that is resposible for generation of the snipets
|
private int |
lastJumpIdVariableIndex |
private static org.apache.log4j.Logger |
logger |
Constructor and Description |
---|
InjectCodeTouchPointListener(ClassMap classMap,
CodeProvider codeProvider) |
Modifier and Type | Method and Description |
---|---|
void |
afterJump(int eventId,
org.objectweb.asm.Label label,
int currentLine,
org.objectweb.asm.MethodVisitor nextMethodVisitor)
After jump we will increment counterId for the 'false' branch of the JUMP.
|
void |
afterLabel(int eventId,
org.objectweb.asm.Label label,
int currentLine,
org.objectweb.asm.MethodVisitor mv)
If the label is JUMP destination, we will increment the counter stored inside the 'internal variable'.
|
void |
afterLineNumber(int eventId,
org.objectweb.asm.Label label,
int currentLine,
org.objectweb.asm.MethodVisitor nextMethodVisitor,
java.lang.String methodName,
java.lang.String methodSignature)
After every 'linenumber' instruction we increments counter connected with the line number.
|
void |
afterMethodStart(org.objectweb.asm.MethodVisitor nextMethodVisitor)
At the start of every method we initiates the 'internal variable' with zero.
|
void |
beforeJump(int eventId,
org.objectweb.asm.Label label,
int currentLine,
org.objectweb.asm.MethodVisitor nextMethodVisitor)
Before jump we will store into 'internal variable' the counterId of a 'true' branch of the JUMP
|
void |
beforeLabel(int eventId,
org.objectweb.asm.Label label,
int currentLine,
org.objectweb.asm.MethodVisitor mv)
Called before processing 'label' directive
|
void |
beforeSwitch(int eventId,
org.objectweb.asm.Label def,
org.objectweb.asm.Label[] labels,
int currentLine,
org.objectweb.asm.MethodVisitor mv,
java.lang.String conditionType)
Before switch we set the internal variable to a special counterId connected with the switch.
|
void |
ignoreLine(int eventId,
int currentLine)
If we determined that some line should be not 'counted' by cobertura (for example the line might be specified in
AbstractFindTouchPointsClassInstrumenter.ignoreRegexp )
we call this method. |
void |
setLastJumpIdVariableIndex(int lastJumpIdVariableIndex)
Index of 'internal variable'.
|
private static final org.apache.log4j.Logger logger
private final CodeProvider codeProvider
private final ClassMap classMap
private int lastJumpIdVariableIndex
public InjectCodeTouchPointListener(ClassMap classMap, CodeProvider codeProvider)
public void beforeJump(int eventId, org.objectweb.asm.Label label, int currentLine, org.objectweb.asm.MethodVisitor nextMethodVisitor)
beforeJump
in interface TouchPointListener
eventId
- - id of the detected event.label
- - destination label of the jumpcurrentLine
- - number of currently visited linenextMethodVisitor
- - sink for instrumented codepublic void afterJump(int eventId, org.objectweb.asm.Label label, int currentLine, org.objectweb.asm.MethodVisitor nextMethodVisitor)
afterJump
in interface TouchPointListener
eventId
- - id of the detected event.label
- - destination label of the jumpcurrentLine
- - number of currently visited linenextMethodVisitor
- - sink for instrumented codepublic void beforeSwitch(int eventId, org.objectweb.asm.Label def, org.objectweb.asm.Label[] labels, int currentLine, org.objectweb.asm.MethodVisitor mv, java.lang.String conditionType)
beforeSwitch
in interface TouchPointListener
eventId
- - id of the detected event.def
- - label of 'default' target label that will be used when none of given values match the switchlabels
- - table of labels connected to switch 'values' (different switch branches). There might be duplicates in the table (fall-through in switch statement)currentLine
- - number of line in which the 'switch' keyword has been found (number of line currently being processed)mv
- - sink for instrumented (injected) codeconditionType
- - NULL (if undetected) or signature of variable used as a switch condition. *public void afterLabel(int eventId, org.objectweb.asm.Label label, int currentLine, org.objectweb.asm.MethodVisitor mv)
If the label is JUMP destination, we will increment the counter stored inside the 'internal variable'. This way we are incrementing the 'true' branch of the condition.
If the label is SWITCH destination, we check all switch instructions that have targets in the label we generate code that checks if the 'internal variable' is equal to id of considered switch and if so increments counterId connected to the switch.
afterLabel
in interface TouchPointListener
eventId
- - id of the detected event.label
- - internal identifier of label being found (single pass of instrumentation valid only)currentLine
- - number of line in which the 'switch' keyword has been found (number of line currently being processed)mv
- - sink for instrumented (injected) codepublic void afterLineNumber(int eventId, org.objectweb.asm.Label label, int currentLine, org.objectweb.asm.MethodVisitor nextMethodVisitor, java.lang.String methodName, java.lang.String methodSignature)
afterLineNumber
in interface TouchPointListener
eventId
- - id of the detected event.label
- - label connected to the linecurrentLine
- - number of currently visited linenextMethodVisitor
- - sink for instrumented codemethodName
- - name of currently being instrumented methodmethodSignature
- - signature (params and returned value type) of currently being instrumented methodpublic void afterMethodStart(org.objectweb.asm.MethodVisitor nextMethodVisitor)
afterMethodStart
in interface TouchPointListener
nextMethodVisitor
- - sink for instrumented codepublic void beforeLabel(int eventId, org.objectweb.asm.Label label, int currentLine, org.objectweb.asm.MethodVisitor mv)
TouchPointListener
beforeLabel
in interface TouchPointListener
eventId
- - id of the detected event.label
- - internal identifier of label being found (single pass of instrumentation valid only)currentLine
- - number of line in which the 'switch' keyword has been found (number of line currently being processed)mv
- - sink for instrumented (injected) codepublic void ignoreLine(int eventId, int currentLine)
TouchPointListener
If we determined that some line should be not 'counted' by cobertura (for example the line might be specified in AbstractFindTouchPointsClassInstrumenter.ignoreRegexp
)
we call this method.
TouchPointListener.afterLineNumber(int, Label, int, MethodVisitor, String, String)
event will be (or has been already) fired.ignoreLine
in interface TouchPointListener
eventId
- - id of the event connected to the line (the same eventId that might be used for the line in TouchPointListener.afterLineNumber(int, Label, int, MethodVisitor, String, String)
)currentLine
- - number of line that should be ignored.public void setLastJumpIdVariableIndex(int lastJumpIdVariableIndex)
ShiftVariableMethodAdapter#calculateFirstStackVariable(int, String)
.