Package randoop.operation
Class EnumConstant
- java.lang.Object
-
- randoop.operation.CallableOperation
-
- randoop.operation.EnumConstant
-
- All Implemented Interfaces:
Operation
public class EnumConstant extends CallableOperation
-
-
Constructor Summary
Constructors Constructor Description EnumConstant(Enum<?> value)
-
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)
Produces a Java source code representation of this statement and appends it to the given StringBuilder.boolean
equals(Object obj)
boolean
equalsEnumConstant(EnumConstant e)
Returns true if this equals the given object.ExecutionOutcome
execute(Object[] statementInput)
Performs this operation using the array of input values.String
getName()
Returns the name for the operation.Object
getValue()
Returns the "value" of an operation that is actually a ground term, meaning a constant of some form.int
hashCode()
static TypedClassOperation
parse(String desc)
Parses the description of an enum constant value in a string as returned bytoParsableString(Type, TypeTuple, Type)
.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()
Enum<?>
value()
Returns the object for the value of this enum constant.private static Enum<?>
valueOf(Class<?> type, String valueName)
valueOf searches the enum constant list of a class for a constant with the given name.-
Methods inherited from class randoop.operation.CallableOperation
getArgumentString, getReflectionObject, isConstantField, isConstructorCall, isMessage, isMethodCall, isNonreceivingValue, isStatic, isUncheckedCast, satisfies
-
-
-
-
Field Detail
-
value
private Enum<?> value
-
-
Constructor Detail
-
EnumConstant
public EnumConstant(Enum<?> value)
-
-
Method Detail
-
equalsEnumConstant
public boolean equalsEnumConstant(EnumConstant e)
Returns true if this equals the given object.- Parameters:
e
- the value to compare against- Returns:
- true iff this equals the given value
-
getName
public String getName()
Description copied from interface:Operation
Returns the name for the operation.- Returns:
- the name for this operation
-
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.- Specified by:
execute
in classCallableOperation
- Parameters:
statementInput
- array containing appropriate inputs to operation- Returns:
- a
NormalExecution
object holding the value of the enum constant
-
appendCode
public void appendCode(Type declaringType, TypeTuple inputTypes, Type outputType, List<Variable> inputVars, StringBuilder b)
Produces a Java source code representation of this statement and appends it to the given StringBuilder.Adds qualified name of enum constant.
- Specified by:
appendCode
in classCallableOperation
- Parameters:
declaringType
- the declaring type for this operationinputTypes
- the input types for this operationoutputType
- the output type for this operationinputVars
- the list of variables that are inputs to operationb
- theStringBuilder
to which code is added
-
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).Issues a string representation of an enum constant as a type-value pair. The parse function should return an equivalent object.
- 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:
- a string representation of this operation
- See Also:
parse(String)
-
parse
public static TypedClassOperation parse(String desc) throws OperationParseException
Parses the description of an enum constant value in a string as returned bytoParsableString(Type, TypeTuple, Type)
.Valid strings may be of the form EnumType:EnumValue, or OuterClass$InnerEnum:EnumValue for an enum that is an inner type of a class.
- Parameters:
desc
- string representing type-value pair for an enum constant- Returns:
- the enum constant operation for the string descriptor
- Throws:
OperationParseException
- if desc does not match expected form
-
value
public Enum<?> value()
Returns the object for the value of this enum constant.- Returns:
- the object for value of this enum constant
-
getValue
public Object getValue()
Returns the "value" of an operation that is actually a ground term, meaning a constant of some form. Only null if value is null, otherwise throws an exception if there is not a reasonable meaning of value for type of operation.This is a hack to allow randoop.main.GenBranchDir to do mutation.
- Specified by:
getValue
in interfaceOperation
- Overrides:
getValue
in classCallableOperation
- Returns:
- value of enum constant
-
valueOf
private static Enum<?> valueOf(Class<?> type, String valueName)
valueOf searches the enum constant list of a class for a constant with the given name. Note: cannot make this work using valueOf method of Enum due to typing.- Parameters:
type
- class that is already known to be an enumvalueName
- name for value that may be a constant of the enum- Returns:
- reference to actual constant value, or null if none exists in type
-
-