korat.instrumentation
Class SpecialConstructorInstrumenter

java.lang.Object
  extended by korat.instrumentation.AbstractInstrumenter
      extended by korat.instrumentation.SpecialConstructorInstrumenter
All Implemented Interfaces:
IInstrumenter

 class SpecialConstructorInstrumenter
extends AbstractInstrumenter

This instrumenter equips the given class with a special field of ITester type and a special constructor that takes one parameter of type ITester to initialize that special field. Classes under test need this field since it holds an instance to be notified about field accesses.

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

Field Summary
 
Fields inherited from class korat.instrumentation.AbstractInstrumenter
cp
 
Constructor Summary
SpecialConstructorInstrumenter()
           
 
Method Summary
protected  void addConstructors(CtClass clz)
           Adds needed constructors to class under test First, if doesn't exist, no-arg constructor is added with empty body.
protected  void addITesterField(CtClass clz)
          Adds ITester field that holds an instance of the ITester class that should be notified about field accesses.
private  void addKoratConstructor(CtClass clz)
          Adds a special constructor that Korat will call to initialize object under test.
protected  void addNoArgConstr(CtClass clz)
          Adds no-arg constructor with empty body.
protected  void instrument(CtClass clz)
           
 
Methods inherited from class korat.instrumentation.AbstractInstrumenter
getBytecode, shouldProcessField, shouldProcessMethod
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpecialConstructorInstrumenter

SpecialConstructorInstrumenter()
Method Detail

instrument

protected void instrument(CtClass clz)
                   throws CannotCompileException,
                          NotFoundException,
                          IOException
Specified by:
instrument in class AbstractInstrumenter
Throws:
CannotCompileException
NotFoundException
IOException

addITesterField

protected void addITesterField(CtClass clz)
                        throws NotFoundException,
                               CannotCompileException
Adds ITester field that holds an instance of the ITester class that should be notified about field accesses. This field gets initialized in the korat-special constructor.

Parameters:
clz -
Throws:
NotFoundException
CannotCompileException

addConstructors

protected void addConstructors(CtClass clz)
                        throws NotFoundException,
                               CannotCompileException

Adds needed constructors to class under test

First, if doesn't exist, no-arg constructor is added with empty body. Then, special constructor with one parameter of ITester type is added. That constructor is used by Korat to initialize class under test passing it the instance of the ITester interface. Class under test will store that instance in its own field because that instance will be notified about every field access later on (calling the notifyFieldAccess method).

Parameters:
clz -
Throws:
NotFoundException
CannotCompileException

addNoArgConstr

protected void addNoArgConstr(CtClass clz)
                       throws CannotCompileException
Adds no-arg constructor with empty body.

Parameters:
clz -
Throws:
CannotCompileException

addKoratConstructor

private void addKoratConstructor(CtClass clz)
                          throws NotFoundException,
                                 CannotCompileException
Adds a special constructor that Korat will call to initialize object under test. This constructor only initializes ITester field.

Parameters:
clz -
Throws:
NotFoundException
CannotCompileException
See Also:
addITesterField(CtClass)