Package randoop.condition
Class ExecutableBooleanExpression
java.lang.Object
randoop.condition.ExecutableBooleanExpression
A
ExecutableBooleanExpression
represents a boolean Java expression, and allows evaluation
on argument values.
This is the executable form of AbstractBooleanExpression
.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final NameGenerator
The name generator to use to generate class names.private final String
The comment describing this expression.private final String
The Java source code inObjectContract
format.private final Method
Thejava.lang.reflect.Method
to test this expression. -
Constructor Summary
ConstructorDescriptionExecutableBooleanExpression
(Method expressionMethod, String comment, String contractSource) Creates aExecutableBooleanExpression
that calls the method to evaluate the expression.ExecutableBooleanExpression
(RawSignature signature, String declarations, String expressionSource, String contractSource, String comment, SequenceCompiler compiler) Creates aExecutableBooleanExpression
for evaluating an expression (seeGuard
) of a specification. -
Method Summary
Modifier and TypeMethodDescription(package private) ExecutableBooleanExpression
addPrestate
(Object[] args) Returns theExecutableBooleanExpression
that checks the expression with the given argument values as the pre-state.boolean
Indicate whether this expression is satisfied by the given values.private static String
createConditionClassSource
(String methodName, String expressionText, String parameterDeclarations, String packageName, String expressionClassName) Create the source code for the expression class.(package private) static Method
createMethod
(RawSignature signature, String parameterDeclaration, String expressionSource, SequenceCompiler compiler) Creates ajava.lang.reflect.Method
to test the expression given bycontractSource
.boolean
Return the code comment for this expression.private static String
getCompilerErrorMessage
(List<Diagnostic<? extends JavaFileObject>> diagnostics, String classText) Gets the compilation error message for the expression class from the compiler diagnostics object.Return the Java source code for this expression.int
hashCode()
toString()
-
Field Details
-
classNameGenerator
The name generator to use to generate class names. -
expressionMethod
Thejava.lang.reflect.Method
to test this expression. The method is static (it does not take a receiver argument). -
comment
The comment describing this expression. -
contractSource
The Java source code inObjectContract
format. SeegetContractSource()
for format details.
-
-
Constructor Details
-
ExecutableBooleanExpression
Creates aExecutableBooleanExpression
that calls the method to evaluate the expression.- Parameters:
expressionMethod
- the reflectionMethod
for the expressioncomment
- a comment describing this expressioncontractSource
- the source code for this expression (seegetContractSource()
for format details)
-
ExecutableBooleanExpression
ExecutableBooleanExpression(RawSignature signature, String declarations, String expressionSource, String contractSource, String comment, SequenceCompiler compiler) Creates aExecutableBooleanExpression
for evaluating an expression (seeGuard
) of a specification.- Parameters:
signature
- the signature for the expression method to be created. The class name of the expression method signature is ignored and a new name is generated usingclassNameGenerator
.declarations
- the parameter declaration string for the expression method to be created, including parameter names and wrapped in parenthesesexpressionSource
- the source code for a Java expression to be used as the body of the expression methodcontractSource
- a Java expression that is the source code for the expression, in the format ofgetContractSource()
. The same asexpressionSource
, except that it uses dummy variable names x0, x1, instead of formal parameter names.comment
- the comment describing the expressioncompiler
- the compiler to used to compile the expression method
-
-
Method Details
-
addPrestate
Returns theExecutableBooleanExpression
that checks the expression with the given argument values as the pre-state.Since pre-state is not yet implemented, this method just returns this object.
- Parameters:
args
- the pre-state values to the arguments- Returns:
- the
ExecutableBooleanExpression
with the pre-state set
-
equals
-
hashCode
public int hashCode() -
toString
-
check
Indicate whether this expression is satisfied by the given values.- Parameters:
values
- the values to check the expression against- Returns:
- true if this expression is satisfied by the values, false otherwise
-
getComment
Return the code comment for this expression.- Returns:
- the code comment for this expression
-
getContractSource
Return the Java source code for this expression. Arguments to the expression follow theObjectContract
convention where parameters (including the receiver, if any) are represented byx0
, ...,xn
for some numbern
. If the operation has a return value it will bexn
(the last, extra variable).- Returns:
- the Java representation of the expression as a
String
-
createMethod
static Method createMethod(RawSignature signature, String parameterDeclaration, String expressionSource, SequenceCompiler compiler) Creates ajava.lang.reflect.Method
to test the expression given bycontractSource
.Generates the Java source for a class with the method, compiles the class, and returns the expression method.
- Parameters:
signature
- the signature for the expression method. The class name of the expression method signature is ignored and a new name is generated usingclassNameGenerator
.parameterDeclaration
- the parameter declaration string, including parameter names and wrapped in parenthesesexpressionSource
- a Java expression that is the source code for the expression, in the format ofgetContractSource()
compiler
- the compiler to use to compile the expression class- Returns:
- the
Method
object forcontractSource
-
createConditionClassSource
private static String createConditionClassSource(String methodName, String expressionText, String parameterDeclarations, String packageName, String expressionClassName) Create the source code for the expression class.- Parameters:
methodName
- the name of the expression methodexpressionText
- the expression source code -- a boolean Java expressionparameterDeclarations
- the signature string for the expression methodpackageName
- the package of the expression class, or null for the default packageexpressionClassName
- the name of the expression class- Returns:
- the Java source code for the expression class
-
getCompilerErrorMessage
private static String getCompilerErrorMessage(List<Diagnostic<? extends JavaFileObject>> diagnostics, String classText) Gets the compilation error message for the expression class from the compiler diagnostics object.- Parameters:
diagnostics
- the compiler diagnostics objectclassText
- the source code of the expression class- Returns:
- the compiler error message string
-