com.jcoverage.coverage
Class InstrumentMethodGen

java.lang.Object
  extended bycom.jcoverage.coverage.InstrumentMethodGen

class InstrumentMethodGen
extends java.lang.Object

Add bytecode instrumentation to the method.


Field Summary
(package private)  ClassGenHelper classGenHelper
           
(package private)  java.util.Set conditionals
          The set of "conditionals" (@see Conditional).
(package private)  org.apache.oro.text.regex.Pattern ignoreRegex
           
(package private) static org.apache.log4j.Logger logger
           
(package private)  MethodGenHelper methodGenHelper
           
(package private)  org.apache.bcel.classfile.Method original
           
(package private)  org.apache.oro.text.regex.Perl5Matcher pm
           
(package private)  java.util.Set sourceLineNumbers
          The set of "valid" source lines.
 
Constructor Summary
(package private) InstrumentMethodGen(org.apache.bcel.classfile.Method original, org.apache.bcel.generic.ClassGen cg, java.lang.String ignoreRegex)
           
 
Method Summary
(package private)  void addIfInstruction(org.apache.bcel.generic.LineNumberGen lng, org.apache.bcel.generic.IfInstruction ifInstruction)
          We've found a conditional branch instruction.
 void addInstrumentation()
          The entry point for this class.
(package private)  void addInstrumentation(org.apache.bcel.generic.LineNumberGen lng)
          Add coverage instrumentation to the instructions representing a line of Java source code.
(package private)  void addInstrumentation(org.apache.bcel.generic.LineNumberGen[] lineNumberTable)
           
(package private)  void addSourceLine(org.apache.bcel.generic.LineNumberGen lng)
          We only record the set of "valid" source lines.
(package private)  org.apache.bcel.generic.InstructionList emitGetInstrumentationAndTouchLine(org.apache.bcel.generic.LineNumberGen lng)
          The core instrumentation.
(package private)  java.util.Set getConditionals()
          This method is used internally to calculate the branch coverage rate for this method.
(package private)  java.util.Set getSourceLineNumbers()
           
(package private)  void handleIfInstruction(org.apache.bcel.generic.LineNumberGen lng)
           
(package private)  boolean hasIgnoreRegex()
           
(package private)  boolean isIgnorable(ClassGenHelper helper, org.apache.bcel.generic.InstructionHandle handle)
          We currently only ignore those invoke instructions that are from a matching regular regular expression.
(package private)  boolean isIgnorable(ClassGenHelper helper, org.apache.bcel.generic.LineNumberGen lng)
          We can ignore (for the purposes of instrumentation) any set of instructions which are on our ignore list.
(package private)  void updateTargeters(org.apache.bcel.generic.InstructionHandle oldTarget, org.apache.bcel.generic.InstructionHandle newTarget)
          Inserting coverage instrumentation to a method, inserts additional code into the instrumented class.
(package private)  void updateTargeters(org.apache.bcel.generic.InstructionHandle oldTarget, org.apache.bcel.generic.InstructionHandle newTarget, org.apache.bcel.generic.InstructionTargeter targeter)
           
(package private)  void updateTargeters(org.apache.bcel.generic.InstructionHandle oldTarget, org.apache.bcel.generic.InstructionHandle newTarget, org.apache.bcel.generic.InstructionTargeter[] targeters)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static final org.apache.log4j.Logger logger

original

final org.apache.bcel.classfile.Method original

methodGenHelper

final MethodGenHelper methodGenHelper

classGenHelper

final ClassGenHelper classGenHelper

conditionals

final java.util.Set conditionals
The set of "conditionals" (@see Conditional). Whenever a conditional branch is encountered it is recorded here, including the next Java source line after the conditional branch, and the Java source line of the branch target. This information is later used to calculate the branch coverage rate for this method.


sourceLineNumbers

final java.util.Set sourceLineNumbers
The set of "valid" source lines. That is, those lines of Java source code that do not represent comments, or other syntax "fluff" (e.g., "} else {"), or those lines that have been ignored because they match the ignore regex.


pm

final org.apache.oro.text.regex.Perl5Matcher pm

ignoreRegex

org.apache.oro.text.regex.Pattern ignoreRegex
Constructor Detail

InstrumentMethodGen

InstrumentMethodGen(org.apache.bcel.classfile.Method original,
                    org.apache.bcel.generic.ClassGen cg,
                    java.lang.String ignoreRegex)
Method Detail

updateTargeters

void updateTargeters(org.apache.bcel.generic.InstructionHandle oldTarget,
                     org.apache.bcel.generic.InstructionHandle newTarget,
                     org.apache.bcel.generic.InstructionTargeter targeter)

updateTargeters

void updateTargeters(org.apache.bcel.generic.InstructionHandle oldTarget,
                     org.apache.bcel.generic.InstructionHandle newTarget,
                     org.apache.bcel.generic.InstructionTargeter[] targeters)

updateTargeters

void updateTargeters(org.apache.bcel.generic.InstructionHandle oldTarget,
                     org.apache.bcel.generic.InstructionHandle newTarget)
Inserting coverage instrumentation to a method, inserts additional code into the instrumented class. When this happens we need to adjust any targeters of the original instruction so that they instead target the inserted instrumentation. The instrumentation is inserted immediately prior to oldTarget. Adjusting the targeters to newTarget (the start of where the instrumentation has been added) ensures that the instrumentation is invoked as the original code would have been.


isIgnorable

boolean isIgnorable(ClassGenHelper helper,
                    org.apache.bcel.generic.InstructionHandle handle)
We currently only ignore those invoke instructions that are from a matching regular regular expression.


hasIgnoreRegex

boolean hasIgnoreRegex()

isIgnorable

boolean isIgnorable(ClassGenHelper helper,
                    org.apache.bcel.generic.LineNumberGen lng)
We can ignore (for the purposes of instrumentation) any set of instructions which are on our ignore list. Taking the instruction handle of the line number, we iterate over the instructions until we meet the next instruction that has a line number. If we encounter an instruction on our ignore list, then we can ignore (for the purposes of instrumentation) this group of instructions.


addIfInstruction

void addIfInstruction(org.apache.bcel.generic.LineNumberGen lng,
                      org.apache.bcel.generic.IfInstruction ifInstruction)
We've found a conditional branch instruction. We need to record the line number immediately after the branch, and the line number of the target of the branch. We can later determine branch coverage rates for this method.

Parameters:
lng - the line number that we found the branch instruction
ifInstruction - the actual if instruction

handleIfInstruction

void handleIfInstruction(org.apache.bcel.generic.LineNumberGen lng)

addInstrumentation

void addInstrumentation(org.apache.bcel.generic.LineNumberGen lng)
Add coverage instrumentation to the instructions representing a line of Java source code.


emitGetInstrumentationAndTouchLine

org.apache.bcel.generic.InstructionList emitGetInstrumentationAndTouchLine(org.apache.bcel.generic.LineNumberGen lng)
The core instrumentation. This sequence of instructions is emitted into the instrumented class on every line of original Java code. NOTE THAT THIS EMITTED CODE IS ALSO LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE. NON GPL INSTRUMENTED APPLICATIONS MUST BE LICENSED UNDER SEPARATE AGREEMENT. FOR FURTHER DETAILS, PLEASE VISIT http://jcoverage.com/license.html.


addSourceLine

void addSourceLine(org.apache.bcel.generic.LineNumberGen lng)
We only record the set of "valid" source lines. That is, source lines that are not comments, or contain other syntax "fluff" (e.g., "} else {"), or any line of code that is being ignored by instrumentation ignore regex. addSourceLine is only called if the source line represented by lng is a "real" line of code.


addInstrumentation

void addInstrumentation(org.apache.bcel.generic.LineNumberGen[] lineNumberTable)

addInstrumentation

public void addInstrumentation()
The entry point for this class. We add coverage instrumentation immediately prior to every instruction found in the line number table.


getSourceLineNumbers

java.util.Set getSourceLineNumbers()
Returns:
the set of valid source line numbers, that is those that are not comments, nor syntax "fluff" (e.g., "} else {"), nor lines that are being ignored by the instrumentation ignore regex.

getConditionals

java.util.Set getConditionals()
This method is used internally to calculate the branch coverage rate for this method.