Class ExecutableBooleanExpression

java.lang.Object
randoop.condition.ExecutableBooleanExpression

public class ExecutableBooleanExpression extends Object
A ExecutableBooleanExpression represents a boolean Java expression, and allows evaluation on argument values.

This is the executable form of AbstractBooleanExpression.

See Also:
  • Field Details

    • classNameGenerator

      private static final NameGenerator classNameGenerator
      The name generator to use to generate class names.
    • expressionMethod

      private final Method expressionMethod
      The java.lang.reflect.Method to test this expression. The method is static (it does not take a receiver argument).
    • comment

      private final String comment
      The comment describing this expression.
    • contractSource

      private final String contractSource
      The Java source code in ObjectContract format. See getContractSource() for format details.
  • Constructor Details

    • ExecutableBooleanExpression

      ExecutableBooleanExpression(Method expressionMethod, String comment, String contractSource)
      Creates a ExecutableBooleanExpression that calls the method to evaluate the expression.
      Parameters:
      expressionMethod - the reflection Method for the expression
      comment - a comment describing this expression
      contractSource - the source code for this expression (see getContractSource() for format details)
    • ExecutableBooleanExpression

      ExecutableBooleanExpression(RawSignature signature, String declarations, String expressionSource, String contractSource, String comment, SequenceCompiler compiler)
      Creates a ExecutableBooleanExpression for evaluating an expression (see Guard) 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 using classNameGenerator.
      declarations - the parameter declaration string for the expression method to be created, including parameter names and wrapped in parentheses
      expressionSource - the source code for a Java expression to be used as the body of the expression method
      contractSource - a Java expression that is the source code for the expression, in the format of getContractSource(). The same as expressionSource, except that it uses dummy variable names x0, x1, instead of formal parameter names.
      comment - the comment describing the expression
      compiler - the compiler to used to compile the expression method
  • Method Details

    • addPrestate

      ExecutableBooleanExpression addPrestate(Object[] args)
      Returns the ExecutableBooleanExpression 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

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • check

      public boolean check(Object[] values)
      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

      public String getComment()
      Return the code comment for this expression.
      Returns:
      the code comment for this expression
    • getContractSource

      public String getContractSource()
      Return the Java source code for this expression. Arguments to the expression follow the ObjectContract convention where parameters (including the receiver, if any) are represented by x0, ..., xn for some number n. If the operation has a return value it will be xn (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 a java.lang.reflect.Method to test the expression given by contractSource.

      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 using classNameGenerator.
      parameterDeclaration - the parameter declaration string, including parameter names and wrapped in parentheses
      expressionSource - a Java expression that is the source code for the expression, in the format of getContractSource()
      compiler - the compiler to use to compile the expression class
      Returns:
      the Method object for contractSource
    • 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 method
      expressionText - the expression source code -- a boolean Java expression
      parameterDeclarations - the signature string for the expression method
      packageName - the package of the expression class, or null for the default package
      expressionClassName - 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 object
      classText - the source code of the expression class
      Returns:
      the compiler error message string