Class SpecificationTranslator
- java.lang.Object
-
- randoop.condition.SpecificationTranslator
-
public class SpecificationTranslator extends Object
MethodcreateExecutableSpecification(java.lang.reflect.Executable, randoop.condition.specification.OperationSpecification, randoop.compile.SequenceCompiler)
translates anOperationSpecification
object (which has preconditions, postconditions, and throws conditions) to its executable version,ExecutableSpecification
.
-
-
Field Summary
Fields Modifier and Type Field Description private SequenceCompiler
compiler
TheSequenceCompiler
for compiling expression methods.private static String
DUMMY_VARIABLE_BASE_NAME
The base name of dummy variables used byObjectContract
.private String
poststateExpressionDeclarations
The parameter declaration string, with parentheses, for a poststate (property) expression method.private RawSignature
poststateExpressionSignature
TheRawSignature
for a poststate (property) expression method.private String
prestateExpressionDeclaration
The parameter part of a method declaration string, with parentheses, for a prestate (guard) expression method.private RawSignature
prestateExpressionSignature
TheRawSignature
for a prestate (guard) expression method.private Map<String,String>
replacementMap
The map of expression identifiers to dummy variables.
-
Constructor Summary
Constructors Modifier Constructor Description private
SpecificationTranslator(RawSignature prestateExpressionSignature, String prestateExpressionDeclaration, RawSignature poststateExpressionSignature, String poststateExpressionDeclaration, Map<String,String> replacementMap, SequenceCompiler compiler)
Creates aSpecificationTranslator
object in the given package with the signature strings and variable replacementMap.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private ExecutableBooleanExpression
create(Guard expression)
Creates aExecutableBooleanExpression
object for the givenAbstractBooleanExpression
using the prestate expression signature of thisSpecificationTranslator
.ExecutableBooleanExpression
create(Property expression)
Creates aExecutableBooleanExpression
object for the givenAbstractBooleanExpression
using the poststate expression signature of thisSpecificationTranslator
.static ExecutableSpecification
createExecutableSpecification(Executable executable, OperationSpecification specification, SequenceCompiler compiler)
Create theExecutableSpecification
object for the givenOperationSpecification
using thisSpecificationTranslator
.private static Map<String,String>
createReplacementMap(List<String> parameterNames)
Creates the replacement map from the given parameter names to numbered dummy variable names as used inObjectContract
.(package private) static SpecificationTranslator
createTranslator(Executable executable, OperationSpecification specification, SequenceCompiler compiler)
(package private) SequenceCompiler
getCompiler()
Returns the compiler from this object.private static RawSignature
getExpressionSignature(Executable executable, boolean postState)
Create theRawSignature
for evaluating an expression about a method call to the given method or constructor.private List<ExecutableBooleanExpression>
getGuardExpressions(List<Precondition> preconditions)
Construct the list ofExecutableBooleanExpression
objects, one for eachPrecondition
.(package private) 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) String
getPrestateExpressionDeclaration()
Return the prestate expression method parameter declaration string.private static RawSignature
getRawSignature(@DotSeparatedIdentifiers String packageName, @Nullable Class<?> receiverAType, Class<?>[] parameterTypes, Class<?> returnType)
Creates aRawSignature
for an expression method.(package private) Map<String,String>
getReplacementMap()
Returns the replacement map for the identifiers in the expression to the dummy variables expected in contract assertions.private List<GuardPropertyPair>
getReturnConditions(List<Postcondition> postconditions)
private List<GuardThrowsPair>
getThrowsConditions(List<ThrowsCondition> throwsConditions)
private static @DotSeparatedIdentifiers String
renamedPackage(Package aPackage)
Gets the name of the package.
-
-
-
Field Detail
-
DUMMY_VARIABLE_BASE_NAME
private static final String DUMMY_VARIABLE_BASE_NAME
The base name of dummy variables used byObjectContract
.- See Also:
- Constant Field Values
-
prestateExpressionSignature
private RawSignature prestateExpressionSignature
TheRawSignature
for a prestate (guard) expression method.
-
prestateExpressionDeclaration
private final String prestateExpressionDeclaration
The parameter part of a method declaration string, with parentheses, for a prestate (guard) expression method.
-
poststateExpressionSignature
private RawSignature poststateExpressionSignature
TheRawSignature
for a poststate (property) expression method.
-
poststateExpressionDeclarations
private final String poststateExpressionDeclarations
The parameter declaration string, with parentheses, for a poststate (property) expression method.
-
replacementMap
private final Map<String,String> replacementMap
The map of expression identifiers to dummy variables.
-
compiler
private final SequenceCompiler compiler
TheSequenceCompiler
for compiling expression methods.
-
-
Constructor Detail
-
SpecificationTranslator
private SpecificationTranslator(RawSignature prestateExpressionSignature, String prestateExpressionDeclaration, RawSignature poststateExpressionSignature, String poststateExpressionDeclaration, Map<String,String> replacementMap, SequenceCompiler compiler)
Creates aSpecificationTranslator
object in the given package with the signature strings and variable replacementMap.- Parameters:
prestateExpressionSignature
- theRawSignature
for a prestate expression methodprestateExpressionDeclaration
- the parameter declaration string, with parentheses, for a prestate expression methodpoststateExpressionSignature
- theRawSignature
for a poststate expression methodpoststateExpressionDeclaration
- the parameter declaration string, with parentheses, for a poststate expression methodreplacementMap
- the map of expression identifiers to dummy variablescompiler
- theSequenceCompiler
for creating expression methods
-
-
Method Detail
-
createTranslator
static SpecificationTranslator createTranslator(Executable executable, OperationSpecification specification, SequenceCompiler compiler)
- Parameters:
executable
- thejava.lang.reflect.AccessibleObject
for the operation withOperationSpecification
to translatespecification
- the specification to be translatedcompiler
- the sequence compiler to use to create expression methods- Returns:
- the translator object to convert the specifications for
executable
-
getExpressionSignature
private static RawSignature getExpressionSignature(Executable executable, boolean postState)
Create theRawSignature
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 ifpostState
is true andexecutable
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)
.- Parameters:
executable
- the method or constructor to which the expression belongspostState
- if true, include a variable for the return value in the signature- Returns:
- the
RawSignature
for a expression method ofexecutable
-
getRawSignature
private static RawSignature getRawSignature(@DotSeparatedIdentifiers String packageName, @Nullable Class<?> receiverAType, Class<?>[] parameterTypes, Class<?> returnType)
Creates aRawSignature
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.- Parameters:
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-null- Returns:
- the constructed post-expression method signature
-
renamedPackage
private static @DotSeparatedIdentifiers String renamedPackage(Package aPackage)
Gets the name of the package. If the package name begins with"java."
, prefixes it by"randoop."
, since user classes cannot be added to thejava
package.- Parameters:
aPackage
- the package to get the name of, may be null- Returns:
- the name of the package, updated to start with "randoop." if the original begins with
"java."; null if
aPackage
is null
-
createReplacementMap
private static Map<String,String> createReplacementMap(List<String> parameterNames)
Creates the replacement map from the given parameter names to numbered dummy variable names as used inObjectContract
.- Parameters:
parameterNames
- the parameter names of the expression methods- Returns:
- the map from the parameter names to dummy variables
-
createExecutableSpecification
public static ExecutableSpecification createExecutableSpecification(Executable executable, OperationSpecification specification, SequenceCompiler compiler)
Create theExecutableSpecification
object for the givenOperationSpecification
using thisSpecificationTranslator
.- Parameters:
executable
- thejava.lang.reflect.AccessibleObject
for the operation to translatespecification
- the specification to translatecompiler
- the sequence compiler to use to create expression methods- Returns:
- the
ExecutableSpecification
for the given specification
-
getGuardExpressions
private List<ExecutableBooleanExpression> getGuardExpressions(List<Precondition> preconditions)
Construct the list ofExecutableBooleanExpression
objects, one for eachPrecondition
.- Parameters:
preconditions
- the list ofPrecondition
objects that will be converted toExecutableBooleanExpression
- Returns:
- the list of
ExecutableBooleanExpression
objects obtained by converting eachPrecondition
-
getReturnConditions
private List<GuardPropertyPair> getReturnConditions(List<Postcondition> postconditions)
- Parameters:
postconditions
- the list ofPostcondition
that will be converted toGuardPropertyPair
objects- Returns:
- the list of
GuardPropertyPair
objects obtained by converting eachPostcondition
-
getThrowsConditions
private List<GuardThrowsPair> getThrowsConditions(List<ThrowsCondition> throwsConditions)
- Parameters:
throwsConditions
- the list ofThrowsCondition
that will be converted toGuardPropertyPair
objects- Returns:
- the list of
GuardPropertyPair
objects obtained by converting eachThrowsCondition
-
create
private ExecutableBooleanExpression create(Guard expression)
Creates aExecutableBooleanExpression
object for the givenAbstractBooleanExpression
using the prestate expression signature of thisSpecificationTranslator
.- Parameters:
expression
- theAbstractBooleanExpression
to be converted- Returns:
- the
ExecutableBooleanExpression
object forexpression
-
create
public ExecutableBooleanExpression create(Property expression)
Creates aExecutableBooleanExpression
object for the givenAbstractBooleanExpression
using the poststate expression signature of thisSpecificationTranslator
.- Parameters:
expression
- theAbstractBooleanExpression
to be converted- Returns:
- the
ExecutableBooleanExpression
object forexpression
-
getPrestateExpressionDeclaration
String getPrestateExpressionDeclaration()
Return the prestate expression method parameter declaration string. Includes parentheses.Only used for testing.
- Returns:
- the prestate expression method parameter declaration string
-
getPoststateExpressionDeclarations
String getPoststateExpressionDeclarations()
Return the poststate expression method parameter declaration string. Includes parentheses.Only used for testing.
- Returns:
- the poststate expression method parameter declaration string
-
getPoststateExpressionSignature
RawSignature getPoststateExpressionSignature()
Returns the poststate expression method signature from this object. This signature includes the parameters of the prestate expression signature, plus the return type.Only used for testing.
- Returns:
- the poststate expression method signature for this object
-
getCompiler
SequenceCompiler getCompiler()
Returns the compiler from this object.Only used for testing. ||||||| merged common ancestors
Only used for testing.
- Returns:
- the compiler for this object
-
-