public class SpecificationTranslator
extends java.lang.Object
createExecutableSpecification(java.lang.reflect.Executable, randoop.condition.specification.OperationSpecification, randoop.compile.SequenceCompiler)
translates an OperationSpecification
object
(which has preconditions, postconditions, and throws conditions) to its executable version,
ExecutableSpecification
.Modifier and Type | Field and Description |
---|---|
private SequenceCompiler |
compiler
The
SequenceCompiler for compiling expression methods. |
private static java.lang.String |
DUMMY_VARIABLE_BASE_NAME
The base name of dummy variables used by
ObjectContract . |
private java.lang.String |
poststateExpressionDeclarations
The parameter declaration string, with parentheses, for a poststate (property) expression
method.
|
private RawSignature |
poststateExpressionSignature
The
RawSignature for a poststate (property) expression method. |
private java.lang.String |
prestateExpressionDeclaration
The parameter part of a method declaration string, with parentheses, for a prestate (guard)
expression method.
|
private RawSignature |
prestateExpressionSignature
The
RawSignature for a prestate (guard) expression method. |
private java.util.Map<java.lang.String,java.lang.String> |
replacementMap
The map of expression identifiers to dummy variables.
|
Modifier | Constructor and Description |
---|---|
private |
SpecificationTranslator(RawSignature prestateExpressionSignature,
java.lang.String prestateExpressionDeclaration,
RawSignature poststateExpressionSignature,
java.lang.String poststateExpressionDeclaration,
java.util.Map<java.lang.String,java.lang.String> replacementMap,
SequenceCompiler compiler)
Creates a
SpecificationTranslator object in the given package with the signature
strings and variable replacementMap. |
Modifier and Type | Method and Description |
---|---|
private ExecutableBooleanExpression |
create(Guard expression)
Creates a
ExecutableBooleanExpression object for the given AbstractBooleanExpression using the prestate expression
signature of this SpecificationTranslator . |
ExecutableBooleanExpression |
create(Property expression)
Creates a
ExecutableBooleanExpression object for the given AbstractBooleanExpression using the poststate expression
signature of this SpecificationTranslator . |
static ExecutableSpecification |
createExecutableSpecification(java.lang.reflect.Executable executable,
OperationSpecification specification,
SequenceCompiler compiler)
Create the
ExecutableSpecification object for the given OperationSpecification
using this SpecificationTranslator . |
private static java.util.Map<java.lang.String,java.lang.String> |
createReplacementMap(java.util.List<java.lang.String> parameterNames)
Creates the replacement map from the given parameter names to numbered dummy variable names as
used in
ObjectContract . |
(package private) static SpecificationTranslator |
createTranslator(java.lang.reflect.Executable executable,
OperationSpecification specification,
SequenceCompiler compiler)
|
(package private) SequenceCompiler |
getCompiler()
Returns the compiler from this object.
|
private static RawSignature |
getExpressionSignature(java.lang.reflect.Executable executable,
boolean postState)
Create the
RawSignature for evaluating an expression about a method call to the given
method or constructor. |
private java.util.List<ExecutableBooleanExpression> |
getGuardExpressions(java.util.List<Precondition> preconditions)
Construct the list of
ExecutableBooleanExpression objects, one for each Precondition . |
(package private) java.lang.String |
getPoststateExpressionDeclarations()
Return the poststate expression method parameter declaration string.
|
(package private) RawSignature |
getPoststateExpressionSignature()
Returns the poststate expression method signature from this object.
|
(package private) java.lang.String |
getPrestateExpressionDeclaration()
Return the prestate expression method parameter declaration string.
|
private static RawSignature |
getRawSignature(@DotSeparatedIdentifiers java.lang.String packageName,
@Nullable java.lang.Class<?> receiverAType,
java.lang.Class<?>[] parameterTypes,
java.lang.Class<?> returnType)
Creates a
RawSignature for an expression method. |
(package private) java.util.Map<java.lang.String,java.lang.String> |
getReplacementMap()
Returns the replacement map for the identifiers in the expression to the dummy variables
expected in contract assertions.
|
private java.util.List<GuardPropertyPair> |
getReturnConditions(java.util.List<Postcondition> postconditions)
|
private java.util.List<GuardThrowsPair> |
getThrowsConditions(java.util.List<ThrowsCondition> throwsConditions)
|
private static @DotSeparatedIdentifiers java.lang.String |
renamedPackage(java.lang.Package aPackage)
Gets the name of the package.
|
private static final java.lang.String DUMMY_VARIABLE_BASE_NAME
ObjectContract
.private RawSignature prestateExpressionSignature
RawSignature
for a prestate (guard) expression method.private final java.lang.String prestateExpressionDeclaration
private RawSignature poststateExpressionSignature
RawSignature
for a poststate (property) expression method.private final java.lang.String poststateExpressionDeclarations
private final java.util.Map<java.lang.String,java.lang.String> replacementMap
private final SequenceCompiler compiler
SequenceCompiler
for compiling expression methods.private SpecificationTranslator(RawSignature prestateExpressionSignature, java.lang.String prestateExpressionDeclaration, RawSignature poststateExpressionSignature, java.lang.String poststateExpressionDeclaration, java.util.Map<java.lang.String,java.lang.String> replacementMap, SequenceCompiler compiler)
SpecificationTranslator
object in the given package with the signature
strings and variable replacementMap.prestateExpressionSignature
- the RawSignature
for a prestate expression methodprestateExpressionDeclaration
- the parameter declaration string, with parentheses, for a
prestate expression methodpoststateExpressionSignature
- the RawSignature
for a poststate expression methodpoststateExpressionDeclaration
- the parameter declaration string, with parentheses, for a
poststate expression methodreplacementMap
- the map of expression identifiers to dummy variablescompiler
- the SequenceCompiler
for creating expression methodsstatic SpecificationTranslator createTranslator(java.lang.reflect.Executable executable, OperationSpecification specification, SequenceCompiler compiler)
executable
- the java.lang.reflect.AccessibleObject
for the operation with OperationSpecification
to translatespecification
- the specification to be translatedcompiler
- the sequence compiler to use to create expression methodsexecutable
private static RawSignature getExpressionSignature(java.lang.reflect.Executable executable, boolean postState)
RawSignature
for evaluating an expression about a method call to the given
method or constructor.
The parameter types of the RawSignature are the declaring class as the receiver type,
followed by the parameter types of executable
, followed by the return type if postState
is true and executable
is not a void method. These are all needed, in case
the expression refers to them.
Note: The declaring class of the expression method is actually determined by ExecutableBooleanExpression.createMethod(RawSignature, String, String,
SequenceCompiler)
.
executable
- the method or constructor to which the expression belongspostState
- if true, include a variable for the return value in the signatureRawSignature
for a expression method of executable
private static RawSignature getRawSignature(@DotSeparatedIdentifiers java.lang.String packageName, @Nullable java.lang.Class<?> receiverAType, java.lang.Class<?>[] parameterTypes, java.lang.Class<?> returnType)
RawSignature
for an expression method.
Note that these signatures may be used more than once for different expression methods, and
so ExecutableBooleanExpression.createMethod(RawSignature, String,
String, SequenceCompiler)
replaces the classname to ensure a unique name.
packageName
- the package name for the expression class, or null for the default packagereceiverAType
- the declaring class of the method or constructor, included first in
parameter types if non-nullparameterTypes
- the parameter types for the original method or constructorreturnType
- the return type for the method, or the declaring class for a constructor,
included last in parameter types if non-nullprivate static @DotSeparatedIdentifiers java.lang.String renamedPackage(java.lang.Package aPackage)
"java."
, prefixes it by
"randoop."
, since user classes cannot be added to the java
package.aPackage
- the package to get the name of, may be nullaPackage
is nullprivate static java.util.Map<java.lang.String,java.lang.String> createReplacementMap(java.util.List<java.lang.String> parameterNames)
ObjectContract
.parameterNames
- the parameter names of the expression methodspublic static ExecutableSpecification createExecutableSpecification(java.lang.reflect.Executable executable, OperationSpecification specification, SequenceCompiler compiler)
ExecutableSpecification
object for the given OperationSpecification
using this SpecificationTranslator
.executable
- the java.lang.reflect.AccessibleObject
for the operation to translatespecification
- the specification to translatecompiler
- the sequence compiler to use to create expression methodsExecutableSpecification
for the given specificationprivate java.util.List<ExecutableBooleanExpression> getGuardExpressions(java.util.List<Precondition> preconditions)
ExecutableBooleanExpression
objects, one for each Precondition
.preconditions
- the list of Precondition
objects that will be converted to ExecutableBooleanExpression
ExecutableBooleanExpression
objects obtained by converting each
Precondition
private java.util.List<GuardPropertyPair> getReturnConditions(java.util.List<Postcondition> postconditions)
postconditions
- the list of Postcondition
that will be converted to GuardPropertyPair
objectsGuardPropertyPair
objects obtained by converting each Postcondition
private java.util.List<GuardThrowsPair> getThrowsConditions(java.util.List<ThrowsCondition> throwsConditions)
throwsConditions
- the list of ThrowsCondition
that will be converted to GuardPropertyPair
objectsGuardPropertyPair
objects obtained by converting each ThrowsCondition
private ExecutableBooleanExpression create(Guard expression)
ExecutableBooleanExpression
object for the given AbstractBooleanExpression
using the prestate expression
signature of this SpecificationTranslator
.expression
- the AbstractBooleanExpression
to be
convertedExecutableBooleanExpression
object for expression
public ExecutableBooleanExpression create(Property expression)
ExecutableBooleanExpression
object for the given AbstractBooleanExpression
using the poststate expression
signature of this SpecificationTranslator
.expression
- the AbstractBooleanExpression
to be
convertedExecutableBooleanExpression
object for expression
java.lang.String getPrestateExpressionDeclaration()
Only used for testing.
java.lang.String getPoststateExpressionDeclarations()
Only used for testing.
RawSignature getPoststateExpressionSignature()
Only used for testing.
SequenceCompiler getCompiler()
Only used for testing. ||||||| merged common ancestors
Only used for testing.
java.util.Map<java.lang.String,java.lang.String> getReplacementMap()