Package randoop.sequence
Class Statement
- java.lang.Object
-
- randoop.sequence.Statement
-
public final class Statement extends Object
Statement represents a Java statement, such as a method callFoo f = m(i1...iN)
or a declarationint x = 0
. The statement's data includes an operation and the list of inputs for the operation. The inputs to the operation are variables, but are represented by indexing into the enclosing sequence.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) List<Sequence.RelativeNegativeIndex>
inputs
private TypedOperation
operation
The operation (method call, constructor call, primitive values declaration, etc.).
-
Constructor Summary
Constructors Constructor Description Statement(TypedOperation operation)
Creates a statement based on the given operation.Statement(TypedOperation operation, List<Sequence.RelativeNegativeIndex> inputVariables)
Create a new statement of type statement that takes as input the given values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendCode(Variable variable, List<Variable> inputs, StringBuilder b)
Adds code for the statement to the givenStringBuilder
.boolean
equals(Object obj)
equals tests whether two Statement objects are equal:ExecutionOutcome
execute(Object[] inputs)
execute performs the operation of the statement for the input variables and returns outcome.Type
getDeclaringClass()
getDeclaringClass returns the declaring class as defined by theOperation
of the statement.String
getInlinedForm()
Returns a printed representation of the value as a literal, rather than as a variable reference.TypeTuple
getInputTypes()
TypedOperation
getOperation()
getTypedOperation is meant to be a temporary solution to type confusion in generators.Type
getOutputType()
Object
getValue()
getValue returns the "value" for a statement.int
hashCode()
boolean
isConstructorCall()
isConstructorCall determines if operation for statement is a call to a constructor.boolean
isMethodCall()
isMethodCall indicates whether a statement corresponds to a method-call-like operation.boolean
isNonreceivingInitialization()
isNonreceivingInitialization determines if operation is a nonreceiver term.boolean
isNullInitialization()
isNullInitialization determines if statement represents an initialization by null value.boolean
isStatic()
isStatic indicates whether the corresponding operation is declared as static.String
toParsableString(String variableName, List<Variable> inputs)
String
toString()
-
-
-
Field Detail
-
operation
private final TypedOperation operation
The operation (method call, constructor call, primitive values declaration, etc.).
-
inputs
final List<Sequence.RelativeNegativeIndex> inputs
-
-
Constructor Detail
-
Statement
public Statement(TypedOperation operation, List<Sequence.RelativeNegativeIndex> inputVariables)
Create a new statement of type statement that takes as input the given values.- Parameters:
operation
- the operation of this statementinputVariables
- the variable that are used in this statement
-
Statement
public Statement(TypedOperation operation)
Creates a statement based on the given operation.- Parameters:
operation
- the operation for action of this statement
-
-
Method Detail
-
equals
public boolean equals(Object obj)
equals tests whether two Statement objects are equal:
-
getOutputType
public Type getOutputType()
-
getInputTypes
public TypeTuple getInputTypes()
-
appendCode
public void appendCode(Variable variable, List<Variable> inputs, StringBuilder b)
Adds code for the statement to the givenStringBuilder
.- Parameters:
variable
- theVariable
to be used if an initializationinputs
- the input list for the operation of the statementb
- theStringBuilder
to which code text is appended- See Also:
Sequence.appendCode(StringBuilder, int)
-
isStatic
public boolean isStatic()
isStatic indicates whether the corresponding operation is declared as static.- Returns:
- result of isStatic on operation corresponding to statement
-
isMethodCall
public boolean isMethodCall()
isMethodCall indicates whether a statement corresponds to a method-call-like operation. This could be either a method call, an assignment/initialization involving a method call, or the use of a public field in an assignment on either lhs (as "setter") or rhs (as "getter").- Returns:
- true if operation is method-call-like, and false otherwise
-
execute
public ExecutionOutcome execute(Object[] inputs)
execute performs the operation of the statement for the input variables and returns outcome.- Parameters:
inputs
- list of objects to use as inputs to execution- Returns:
- object representing outcome of computation
-
getDeclaringClass
public Type getDeclaringClass()
getDeclaringClass returns the declaring class as defined by theOperation
of the statement.- Returns:
- result of getDeclaringClass for corresponding statement
-
isConstructorCall
public boolean isConstructorCall()
isConstructorCall determines if operation for statement is a call to a constructor.- Returns:
- true if operation is a constructor call, and false otherwise
-
isNonreceivingInitialization
public boolean isNonreceivingInitialization()
isNonreceivingInitialization determines if operation is a nonreceiver term.- Returns:
- true if operation is a nonreceiver, and false otherwise
-
isNullInitialization
public boolean isNullInitialization()
isNullInitialization determines if statement represents an initialization by null value.- Returns:
- true if statement represents null initialization, and false otherwise
-
getInlinedForm
public String getInlinedForm()
Returns a printed representation of the value as a literal, rather than as a variable reference.- Returns:
- string containing code for a literal value
-
getValue
public Object getValue()
getValue returns the "value" for a statement. Is only meaningful if statement is an assignment of a constant value. Appeals toCallableOperation
to throw appropriate exception when unable to provide a value.This is a hack to allow randoop.main.GenBranchDir to do mutation.
- Returns:
- value of term in statement (rhs of assignment/initialization) if any
-
getOperation
public final TypedOperation getOperation()
getTypedOperation is meant to be a temporary solution to type confusion in generators. This should go away. Only intended to be called bySequence.extend(TypedOperation, List)
.- Returns:
- operation object in the statement
-
-