randoop
Class ContractCheckingVisitor

Object
  extended by ContractCheckingVisitor
All Implemented Interfaces:
ExecutionVisitor

public final class ContractCheckingVisitor
extends Object
implements ExecutionVisitor

An execution visitor that checks unary and binary object contracts on the values created by the sequence. It does this only after the last statement has been executed. For each contract violation, the visitor adds an Check to the last index in the sequence. These checks can be added at any time; however, Randoop usually adds these checks (vian an ExecutionVisitor as the execution unfolds, based on observing the result of executing the statements in the sequence. For example, a RegressionCaptureVisitor creates NotNull checks as the sequence is executed, for those statments that return non-null values. If the sequence throws an exception, the visitor does not check any contracts [[ TODO update]]. If it does not throw an exception, it checks all contracts on each object returned by each statement, except objects that are boxed primitives or Strings.


Constructor Summary
Constructor and Description
ContractCheckingVisitor(List<ObjectContract> contracts, boolean checkAfterLast)
          Create a new visitor that checks the given contracts after the last statement in a sequence is executed.
 
Method Summary
Modifier and Type Method and Description
 void initialize(ExecutableSequence s)
          Called before execution of a sequence, to allow the visitor to perform any initialization steps required before execution.
 void visitAfter(ExecutableSequence s, int idx)
          If idx is the last index, checks contracts.
 void visitBefore(ExecutableSequence sequence, int i)
          Invoked by ExecutableSequence.execute before the i-th statement executes.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContractCheckingVisitor

public ContractCheckingVisitor(List<ObjectContract> contracts,
                               boolean checkAfterLast)
Create a new visitor that checks the given contracts after the last statement in a sequence is executed.

Parameters:
contracts - Expected to be unary contracts, i.e. for each contract c, c.getArity() == 1.
checkAfterLast - If true, checks contracts only when the last statement is visited. If false, checks contracts after each statement is visited.
Method Detail

initialize

public void initialize(ExecutableSequence s)
Description copied from interface: ExecutionVisitor
Called before execution of a sequence, to allow the visitor to perform any initialization steps required before execution.

Specified by:
initialize in interface ExecutionVisitor

visitBefore

public void visitBefore(ExecutableSequence sequence,
                        int i)
Description copied from interface: ExecutionVisitor
Invoked by ExecutableSequence.execute before the i-th statement executes. Precondition: statements 0..i-1 have been executed.

Specified by:
visitBefore in interface ExecutionVisitor

visitAfter

public void visitAfter(ExecutableSequence s,
                       int idx)
If idx is the last index, checks contracts.

Specified by:
visitAfter in interface ExecutionVisitor