public class ExecutableSequence
extends java.lang.Object
Sequence
with functionality for executing the sequence, via
methods execute(ExecutionVisitor, TestCheckGenerator)
and execute(ExecutionVisitor, TestCheckGenerator, boolean)
. It also lets the client add Check
s that check expected behaviors of the execution.
An ExecutableSequence augments a sequence with three additional pieces of data:
NotNull
check to the ith index of a sequence to signify that the value
returned by the statement at index i should not be null.
An ExecutableSequence only directly manages the execution results. Other data, including
checks and check evaluation results, are added or removed by the client of the
ExecutableSequence. One way of doing this is by implementing an ExecutionVisitor
and
passing it as an argument to the execute
method.
Modifier and Type | Field and Description |
---|---|
private @MonotonicNonNull TestChecks<?> |
checks
The checks for the last statement in this sequence.
|
java.util.List<Sequence> |
componentSequences
The subsequences that were concatenated to create this sequence.
|
long |
exectime
How long it took to execute this sequence in nanoseconds.
|
private Execution |
executionResults
Contains the runtime objects created and exceptions thrown (if any) during execution of this
sequence.
|
long |
gentimeNanos
How long it took to generate this sequence in nanoseconds, excluding execution time.
|
private boolean |
hasNullInput
Flag to record whether execution of sequence has a null input.
|
private static java.io.ByteArrayOutputStream |
output_buffer
Captures output from the executed sequence.
|
private static java.io.PrintStream |
output_buffer_stream
Used to populate
output_buffer . |
Sequence |
sequence
The underlying sequence.
|
private IdentityMultiMap<java.lang.Object,Variable> |
variableMap
Maps a value to the set of variables that hold it.
|
Constructor and Description |
---|
ExecutableSequence(Sequence sequence)
Create an executable sequence that executes the given sequence.
|
Modifier and Type | Method and Description |
---|---|
void |
addCoveredClass(java.lang.Class<?> c)
Adds a covered class to the most recent execution results of this sequence.
|
private void |
addReferenceValue(Variable variable,
java.lang.Object value,
java.util.Set<ReferenceValue> refValues)
If the variable has a non-String reference type, add its value to the set and also add a
mapping to
variableMap . |
boolean |
coversClass(java.lang.Class<?> c)
Indicates whether the given class is covered by the most recent execution of this sequence.
|
boolean |
equals(@Nullable java.lang.Object obj) |
void |
execute(ExecutionVisitor visitor,
TestCheckGenerator gen)
Executes sequence, stopping on exceptions.
|
private void |
execute(ExecutionVisitor visitor,
TestCheckGenerator gen,
boolean ignoreException)
Execute this sequence, invoking the given visitor as the execution unfolds.
|
private static void |
executeStatement(Sequence s,
java.util.List<ExecutionOutcome> outcome,
int index,
java.lang.Object[] inputVariables) |
java.util.List<ReferenceValue> |
getAllValues()
Returns all values computed in the sequence.
|
TestChecks<?> |
getChecks()
Return the set of test checks for the most recent execution.
|
private int |
getExceptionIndex(java.lang.Class<?> exceptionClass)
Returns the index in the sequence at which an exception of the given class (or a class
compatible with it) was thrown.
|
java.util.List<ReferenceValue> |
getLastStatementValues()
Returns the list of (reference type) values created and used by the last statement of this
sequence.
|
int |
getNonExecutedIndex()
Returns the index i for a non-executed statement, or -1 if there is no such index.
|
int |
getNonNormalExecutionIndex() |
TypedOperation |
getOperation()
Return the operation from which this sequence was generated -- the operation of the last
statement of this sequence.
|
ExecutionOutcome |
getResult(int index)
This method is typically used by ExecutionVisitors.
|
private java.lang.Object[] |
getRuntimeInputs(java.util.List<ExecutionOutcome> outcome,
java.util.List<Variable> inputs) |
java.lang.Object[] |
getRuntimeInputs(java.util.List<Variable> inputs) |
static java.lang.Object[] |
getRuntimeValuesForVars(java.util.List<Variable> vars,
Execution execution)
Returns the values for the given variables in the
Execution object. |
private static java.lang.Object[] |
getRuntimeValuesForVars(java.util.List<Variable> vars,
java.util.List<ExecutionOutcome> execution) |
private java.lang.Object |
getValue(int index)
The result of executing the index-th element of the sequence.
|
Variable |
getVariable(java.lang.Object value)
Returns some variable that has the given value in the outcome of executing this sequence.
|
@Nullable java.util.List<Variable> |
getVariables(java.lang.Object value)
Returns the set of variables that have the given value in the outcome of executing this
sequence.
|
boolean |
hasFailure()
Indicate whether checks are failing or passing.
|
int |
hashCode() |
boolean |
hasInvalidBehavior()
Indicate whether there are any invalid checks.
|
boolean |
hasNonExecutedStatements()
Returns whether the sequence contains a non-executed statement.
|
boolean |
hasNullInput()
Indicates whether the executed sequence has any null input values.
|
boolean |
isNormalExecution() |
private boolean |
isNormalExecution(int i)
This method is typically used by ExecutionVisitors.
|
private void |
reset()
Reset this object to its initial state.
|
int |
size()
Return the number of statements in this sequence.
|
java.lang.String |
statementToCodeString(int i)
Return the code representation of the i'th statement.
|
boolean |
throwsException(java.lang.Class<?> exceptionClass)
Return true if an exception of the given class (or a class compatible with it) was thrown
during this sequence's execution.
|
private java.util.List<java.lang.String> |
toCodeLines()
Return this sequence as code.
|
java.lang.String |
toCodeString()
Return this sequence as code.
|
java.lang.String |
toString() |
public Sequence sequence
private @MonotonicNonNull TestChecks<?> checks
private transient Execution executionResults
public long gentimeNanos
public long exectime
private boolean hasNullInput
TODO: This is wonky, it really belongs to execution.
private static java.io.ByteArrayOutputStream output_buffer
private static java.io.PrintStream output_buffer_stream
output_buffer
.private IdentityMultiMap<java.lang.Object,Variable> variableMap
public java.util.List<Sequence> componentSequences
public ExecutableSequence(Sequence sequence)
sequence
- the underlying sequence for this executable sequenceprivate void reset()
public java.lang.String toString()
toString
in class java.lang.Object
private java.util.List<java.lang.String> toCodeLines()
Sequence.toCodeString()
except includes the
checks.
If for a given statement there is a check of type ExceptionCheck
, that
check's pre-statement code is printed immediately before the statement, and its post-statement
code is printed immediately after the statement.
public java.lang.String toCodeString()
Sequence.toCodeString()
except includes the
checks.
If for a given statement there is a check of type ExceptionCheck
, that
check's pre-statement code is printed immediately before the statement, and its post-statement
code is printed immediately after the statement.
public java.lang.String statementToCodeString(int i)
i
- the statement indexpublic void execute(ExecutionVisitor visitor, TestCheckGenerator gen)
visitor
- the ExecutionVisitor
that collects checks from resultsgen
- the check generator for testsexecute(ExecutionVisitor, TestCheckGenerator, boolean)
private void execute(ExecutionVisitor visitor, TestCheckGenerator gen, boolean ignoreException)
Check
s about the execution.
This method operates as follows:
visitor.initialize(this)
.
visitor.visitBefore(this, i)
visitor.visitAfter(this, i)
ignoreException==false
.
null
input value is implicitly passed to the statement (i.e., not via explicit
declaration like x = null)
visitAfter
method, a
ContractViolation
check is present at index i.
After invoking this method, the client can query the outcome of executing each statement via
the method getResult(int)
.
visitor
- the ExecutionVisitor
gen
- the initial check generator, which this augments then usesignoreException
- if true, ignore exceptions thrown before the last statementjava.lang.Error
- if execution of the sequence throws an exception and ignoreException==false
public java.lang.Object[] getRuntimeInputs(java.util.List<Variable> inputs)
private java.lang.Object[] getRuntimeInputs(java.util.List<ExecutionOutcome> outcome, java.util.List<Variable> inputs)
public static java.lang.Object[] getRuntimeValuesForVars(java.util.List<Variable> vars, Execution execution)
Execution
object. The variables are
Variable
objects in the Sequence
of this ExecutableSequence
object.vars
- a list of Variable
objectsexecution
- the object representing outcome of executing this sequenceprivate static java.lang.Object[] getRuntimeValuesForVars(java.util.List<Variable> vars, java.util.List<ExecutionOutcome> execution)
private static void executeStatement(Sequence s, java.util.List<ExecutionOutcome> outcome, int index, java.lang.Object[] inputVariables)
public ExecutionOutcome getResult(int index)
The result of executing the index-th element of the sequence.
index
- the statement indexpublic TestChecks<?> getChecks()
TestChecks
generated from the most recent executionprivate java.lang.Object getValue(int index)
index
- which element to obtainpublic java.util.List<ReferenceValue> getLastStatementValues()
private void addReferenceValue(Variable variable, java.lang.Object value, java.util.Set<ReferenceValue> refValues)
variableMap
.variable
- the variable to use as a value in variableMapvalue
- the Java value to use as a key in variableMaprefValues
- the set of all reference values; is side-effected by this methodpublic java.util.List<ReferenceValue> getAllValues()
public @Nullable java.util.List<Variable> getVariables(java.lang.Object value)
value
- the valuepublic Variable getVariable(java.lang.Object value)
value
- the valueprivate boolean isNormalExecution(int i)
i
- the statement index to test for normal executionpublic int getNonNormalExecutionIndex()
public boolean isNormalExecution()
private int getExceptionIndex(java.lang.Class<?> exceptionClass)
exceptionClass
- the exception thrownpublic boolean throwsException(java.lang.Class<?> exceptionClass)
exceptionClass
- the exception classpublic boolean hasNonExecutedStatements()
public int getNonExecutedIndex()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(@Nullable java.lang.Object obj)
equals
in class java.lang.Object
public boolean hasNullInput()
public boolean hasFailure()
public boolean hasInvalidBehavior()
public void addCoveredClass(java.lang.Class<?> c)
c
- the class covered by the execution of this sequencepublic boolean coversClass(java.lang.Class<?> c)
c
- the class to be coveredpublic TypedOperation getOperation()
public int size()