Package randoop.operation
Class ConstructorCall
- java.lang.Object
-
- randoop.operation.CallableOperation
-
- randoop.operation.ConstructorCall
-
- All Implemented Interfaces:
Operation
public final class ConstructorCall extends CallableOperation
ConstructorCall is anOperation
that represents a call to a constructor, and holds a reference to a reflectiveConstructor
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 Summary
Fields Modifier and Type Field Description private Constructor<?>
constructor
private int
hashCodeCached
private boolean
hashCodeComputed
-
Constructor Summary
Constructors Constructor Description ConstructorCall(Constructor<?> constructor)
Creates object corresponding to the given reflection constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendCode(Type declaringType, TypeTuple inputTypes, Type outputType, List<Variable> inputVars, StringBuilder b)
Adds code for a constructor call to the givenStringBuilder
.boolean
equals(Object o)
Tests whether the parameter is a call to the same constructor.ExecutionOutcome
execute(Object[] statementInput)
Performs this operation using the array of input values.Constructor<?>
getConstructor()
Return the reflective constructor corresponding to this ConstructorCall.String
getName()
Returns the name for the operation.Constructor<?>
getReflectionObject()
int
hashCode()
Returns the hashCode for the constructor called by this object.boolean
isConstructorCall()
Predicate to indicate whether object represents a call to a constructor.static TypedClassOperation
parse(String signature)
Parse a constructor call in a string with the format generated bytoParsableString(Type, TypeTuple, Type)
and returns the correspondingConstructorCall
object.boolean
satisfies(ReflectionPredicate reflectionPredicate)
Checks whether reflective object contained in anOperation
satisfies the predicate.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.String
toString()
Returns concise string representation of this ConstructorCall.-
Methods inherited from class randoop.operation.CallableOperation
getArgumentString, getValue, isConstantField, isMessage, isMethodCall, isNonreceivingValue, isStatic, isUncheckedCast
-
-
-
-
Field Detail
-
constructor
private final Constructor<?> constructor
-
hashCodeCached
private int hashCodeCached
-
hashCodeComputed
private boolean hashCodeComputed
-
-
Constructor Detail
-
ConstructorCall
public ConstructorCall(Constructor<?> constructor)
Creates object corresponding to the given reflection constructor.- Parameters:
constructor
- reflective object for a constructor
-
-
Method Detail
-
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.
-
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 givenStringBuilder
.- Specified by:
appendCode
in classCallableOperation
- Parameters:
inputVars
- a list of variables representing the actual arguments for the constructor callb
- the StringBuilder to which the output is appendeddeclaringType
- the declaring type for this operationinputTypes
- the input types for this operationoutputType
- the output type for this operation- See Also:
TypedClassOperation.appendCode(List, StringBuilder)
-
equals
public boolean equals(Object o)
Tests whether the parameter is a call to the same constructor.
-
hashCode
public int hashCode()
Returns the hashCode for the constructor called by this 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 classCallableOperation
- Parameters:
statementInput
- is an array of values corresponding to signature of the constructor- Returns:
- results of executing this statement
- See Also:
TypedOperation.execute(Object[])
-
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 classCallableOperation
- Parameters:
declaringType
- the declaring type for this operationinputTypes
- the input types for this operationoutputType
- the output type for this operation- Returns:
- signature string for constructor
- See Also:
parse(String)
-
parse
public static TypedClassOperation parse(String signature) throws OperationParseException
Parse a constructor call in a string with the format generated bytoParsableString(Type, TypeTuple, Type)
and returns the correspondingConstructorCall
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:
OperationParser.parse(String)
-
isConstructorCall
public boolean isConstructorCall()
Predicate to indicate whether object represents a call to a constructor.- Specified by:
isConstructorCall
in interfaceOperation
- Overrides:
isConstructorCall
in classCallableOperation
- Returns:
- true, because this is a
ConstructorCall
-
getReflectionObject
public Constructor<?> getReflectionObject()
- Overrides:
getReflectionObject
in classCallableOperation
-
satisfies
public boolean satisfies(ReflectionPredicate reflectionPredicate)
Checks whether reflective object contained in anOperation
satisfies the predicate. Since there is no reflective object in anCallableOperation
, returns false.Determines whether enclosed
Constructor
satisfies the given predicate.- Specified by:
satisfies
in interfaceOperation
- Overrides:
satisfies
in classCallableOperation
- 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.
-
-