Class ConstructorCall

java.lang.Object
randoop.operation.CallableOperation
randoop.operation.ConstructorCall
All Implemented Interfaces:
Operation

public final class ConstructorCall extends CallableOperation
ConstructorCall is an Operation that represents a call to a constructor, and holds a reference to a reflective Constructor object.

As an Operation, a call to constructor c with n arguments is represented as c : [t1,...,tn] → c, where the output type c is also the name of the class.

  • Field Details

    • constructor

      private final Constructor<?> constructor
    • hashCodeCached

      private int hashCodeCached
    • hashCodeComputed

      private boolean hashCodeComputed
  • Constructor Details

    • ConstructorCall

      public ConstructorCall(Constructor<?> constructor)
      Creates object corresponding to the given reflection constructor.
      Parameters:
      constructor - reflective object for a constructor
  • Method Details

    • getConstructor

      public Constructor<?> getConstructor()
      Return the reflective constructor corresponding to this ConstructorCall.
      Returns:
      Constructor object called by this constructor call
    • toString

      public String toString()
      Returns concise string representation of this ConstructorCall.
      Overrides:
      toString in class Object
    • getName

      public String getName()
      Description copied from interface: Operation
      Returns the name for the operation.
      Returns:
      the name for this operation
    • appendCode

      public void appendCode(Type declaringType, TypeTuple inputTypes, Type outputType, List<Variable> inputVars, StringBuilder b)
      Adds code for a constructor call to the given StringBuilder.
      Specified by:
      appendCode in class CallableOperation
      Parameters:
      inputVars - a list of variables representing the actual arguments for the constructor call
      b - the StringBuilder to which the output is appended
      declaringType - the declaring type for this operation
      inputTypes - the input types for this operation
      outputType - the output type for this operation
      See Also:
    • equals

      public boolean equals(Object o)
      Tests whether the parameter is a call to the same constructor.
      Overrides:
      equals in class Object
      Parameters:
      o - an object
      Returns:
      true if o is a ConstructorCall referring to same constructor object; false otherwise
    • hashCode

      public int hashCode()
      hashCode returns the hashCode for the constructor called by this object.
      Overrides:
      hashCode in class Object
    • execute

      public ExecutionOutcome execute(Object[] statementInput)
      Performs this operation using the array of input values. Returns the results of execution as an ResultOrException object and can output results to specified PrintStream.

      Performs call to the constructor given the objects as actual parameters, and the output stream for any output.

      Specified by:
      execute in class CallableOperation
      Parameters:
      statementInput - is an array of values corresponding to signature of the constructor
      Returns:
      results of executing this statement
      See Also:
    • toParsableString

      public String toParsableString(Type declaringType, TypeTuple inputTypes, Type outputType)
      Returns a string representation of this Operation, which can be read by static parse method for class. For a class C implementing the Operation interface, this method should return a String s such that parsing the string returns an object equivalent to this object, i.e. C.parse(this.s).equals(this).

      Generates a string representation of the constructor signature.

      Examples:

      
       java.util.ArrayList.<init>()
       java.util.ArrayList.<init>(java.util.Collection)
       
      Specified by:
      toParsableString in class CallableOperation
      Parameters:
      declaringType - the declaring type for this operation
      inputTypes - the input types for this operation
      outputType - the output type for this operation
      Returns:
      signature string for constructor
      See Also:
    • parse

      public static TypedClassOperation parse(String signature) throws OperationParseException
      Parse a constructor call in a string with the format generated by toParsableString(Type, TypeTuple, Type) and returns the corresponding ConstructorCall object.
      Parameters:
      signature - a string descriptor of a constructor call
      Returns:
      the constructor call for the given string descriptor
      Throws:
      OperationParseException - if no constructor found for signature
      See Also:
    • isConstructorCall

      public boolean isConstructorCall()
      Predicate to indicate whether object represents a call to a constructor.
      Specified by:
      isConstructorCall in interface Operation
      Overrides:
      isConstructorCall in class CallableOperation
      Returns:
      true, because this is a ConstructorCall
    • getReflectionObject

      public Constructor<?> getReflectionObject()
      Overrides:
      getReflectionObject in class CallableOperation
    • satisfies

      public boolean satisfies(ReflectionPredicate reflectionPredicate)
      Checks whether reflective object contained in an Operation satisfies the predicate. Since there is no reflective object in an CallableOperation, returns false.

      Determines whether enclosed Constructor satisfies the given predicate.

      Specified by:
      satisfies in interface Operation
      Overrides:
      satisfies in class CallableOperation
      Parameters:
      reflectionPredicate - ReflectionPredicate against which object to be checked
      Returns:
      true only if the constructor in this object satisfies the ReflectionPredicate.test(Constructor) implemented by predicate.