korat.instrumentation
Class AbstractInstrumenter

java.lang.Object
  extended by korat.instrumentation.AbstractInstrumenter
All Implemented Interfaces:
IInstrumenter
Direct Known Subclasses:
CompoundInstrumenter, FieldInstrumenter, SpecialConstructorInstrumenter, TouchInstrumenter

abstract class AbstractInstrumenter
extends Object
implements IInstrumenter

Base instrumenter class.

Implements getByteCode(String) method (from IInstrumenter interface) using template method design pattern. Subclasses should only override instrument(CtClass) method which does the instrumentation in the terms of the javassist, i.e. instruments given javassist CtClass object.

Author:
Aleksandar Milicevic
See Also:
FieldInstrumenter, ArrayFieldInstrumenter, SpecialConstructorInstrumenter

Field Summary
protected  ClassPool cp
           
 
Constructor Summary
protected AbstractInstrumenter()
           
 
Method Summary
 byte[] getBytecode(String className)
          Gets instrumented bytecode (to be given to the class loader, for example).
protected abstract  void instrument(CtClass clz)
           
protected  boolean shouldProcessField(CtField f)
          Helper: returns if the given field should be processed i.e. instrumented.
protected  boolean shouldProcessMethod(CtMethod m)
          Helper: generally, abstract and native methods should not be processed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cp

protected ClassPool cp
Constructor Detail

AbstractInstrumenter

protected AbstractInstrumenter()
Method Detail

getBytecode

public byte[] getBytecode(String className)
                   throws ClassNotFoundException
Description copied from interface: IInstrumenter
Gets instrumented bytecode (to be given to the class loader, for example).

Specified by:
getBytecode in interface IInstrumenter
Parameters:
className - full class name
Returns:
instrumented bytecode
Throws:
ClassNotFoundException - if class with the className name is not found
See Also:
IInstrumenter.getBytecode(java.lang.String)

instrument

protected abstract void instrument(CtClass clz)
                            throws CannotCompileException,
                                   NotFoundException,
                                   IOException
Throws:
CannotCompileException
NotFoundException
IOException

shouldProcessField

protected boolean shouldProcessField(CtField f)
Helper: returns if the given field should be processed i.e. instrumented. For example, Korat should not instrument field accesses for static fields, nor it should add special getters and setters for them. Also, FilterManager instance should be consulted about user configured excluded-from-instrumentation packages. Subclasses may override this method if different policy is needed.

Parameters:
f - - field to instrument or not
Returns:
whether this field should be instrumented or not

shouldProcessMethod

protected boolean shouldProcessMethod(CtMethod m)
Helper: generally, abstract and native methods should not be processed.

Parameters:
m - - method to check
Returns:
if the method should be processes or not