Package randoop.condition
Class SpecificationCollection
- java.lang.Object
-
- randoop.condition.SpecificationCollection
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class SpecificationCollection extends Object implements Closeable
A collection ofOperationSpecification
objects, indexed byAccessibleObject
reflection objects. Only represents methods that have a specification.The
SpecificationCollection
should be constructed from the specification input before theOperationModel
is created.This class stores the
OperationSpecification
objects, and only constructs the correspondingExecutableSpecification
on demand. This lazy strategy avoids building condition methods for specifications that are not used.
-
-
Field Summary
Fields Modifier and Type Field Description private SequenceCompiler
compiler
Compiler for creating conditionMethods.private Map<AccessibleObject,ExecutableSpecification>
getExecutableSpecificationCache
private static com.google.gson.reflect.TypeToken<List<OperationSpecification>>
LIST_OF_OS_TYPE_TOKEN
The type ofList<OperationSpecification>>
.private Map<AccessibleObject,Set<Method>>
overridden
Map from reflection object to all the methods it overrides (that have a specification).private MultiMap<OperationSignature,Method>
signatureToMethods
Given a method signature, what methods (that have specifications) have that signature? Does not contain constructors.private Map<AccessibleObject,OperationSpecification>
specificationMap
Map from method or constructor to the correspondingOperationSpecification
.
-
Constructor Summary
Constructors Constructor Description SpecificationCollection(Map<AccessibleObject,OperationSpecification> specificationMap, MultiMap<OperationSignature,Method> signatureToMethods, Map<AccessibleObject,Set<Method>> overridden)
Creates aSpecificationCollection
for the given specification map.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static Map<AccessibleObject,Set<Method>>
buildOverridingMap(MultiMap<OperationSignature,Method> signatureToMethods)
Constructs a map between reflection objects representing override relationships among methods.void
close()
Releases any system resources used by this.static SpecificationCollection
create(List<Path> specificationFiles)
Creates aSpecificationCollection
from the list of JSON specification files.private static Set<Method>
findOverridden(Class<?> classType, Set<Method> methods)
Finds the methods inmethods
that are declared in a supertype ofclassType
.private static AccessibleObject
getAccessibleObject(OperationSignature operation)
Get thejava.lang.reflect.AccessibleObject
for theOperationSignature
.ExecutableSpecification
getExecutableSpecification(Executable executable)
Creates anExecutableSpecification
object for the given constructor or method, from its specifications in this object.private static void
readSpecificationFile(Path specificationFile, Map<AccessibleObject,OperationSpecification> specificationMap, MultiMap<OperationSignature,Method> signatureToMethods)
ReadsOperationSpecification
objects from the given file, and adds them to the other two arguments, which are modified by side effect.private static void
readSpecificationZipFile(Path specificationZipFile, Map<AccessibleObject,OperationSpecification> specificationMap, MultiMap<OperationSignature,Method> signatureToMethods)
ReadsOperationSpecification
objects from all the subfiles of the given zip file, and adds them to the other two arguments, which are modified by side effect.
-
-
-
Field Detail
-
specificationMap
private final Map<AccessibleObject,OperationSpecification> specificationMap
Map from method or constructor to the correspondingOperationSpecification
.
-
signatureToMethods
private final MultiMap<OperationSignature,Method> signatureToMethods
Given a method signature, what methods (that have specifications) have that signature? Does not contain constructors.
-
overridden
private final Map<AccessibleObject,Set<Method>> overridden
Map from reflection object to all the methods it overrides (that have a specification).
-
compiler
private final SequenceCompiler compiler
Compiler for creating conditionMethods.
-
LIST_OF_OS_TYPE_TOKEN
private static com.google.gson.reflect.TypeToken<List<OperationSpecification>> LIST_OF_OS_TYPE_TOKEN
The type ofList<OperationSpecification>>
.
-
getExecutableSpecificationCache
private Map<AccessibleObject,ExecutableSpecification> getExecutableSpecificationCache
-
-
Constructor Detail
-
SpecificationCollection
SpecificationCollection(Map<AccessibleObject,OperationSpecification> specificationMap, MultiMap<OperationSignature,Method> signatureToMethods, Map<AccessibleObject,Set<Method>> overridden)
Creates aSpecificationCollection
for the given specification map.This constructor is used internally. It is only accessible (package-protected) to allow testing. Clients should use
create(List)
instead.- Parameters:
specificationMap
- the map from method or constructor toOperationSpecification
signatureToMethods
- the multimap from a signature to methods with with the signatureoverridden
- the map from a method to methods that it overrides and that have a specification
-
-
Method Detail
-
create
public static SpecificationCollection create(List<Path> specificationFiles)
Creates aSpecificationCollection
from the list of JSON specification files.- Parameters:
specificationFiles
- files containing serialized specifications- Returns:
- the
SpecificationCollection
built from the serializedOperationSpecification
objects, or null if the argument is null
-
close
public void close()
Releases any system resources used by this.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
buildOverridingMap
private static Map<AccessibleObject,Set<Method>> buildOverridingMap(MultiMap<OperationSignature,Method> signatureToMethods)
Constructs a map between reflection objects representing override relationships among methods.- Parameters:
signatureToMethods
- the map from aOperationSignature
to methods with that signature- Returns:
- the map from an
AccessibleObject
to methods that it overrides
-
findOverridden
private static Set<Method> findOverridden(Class<?> classType, Set<Method> methods)
Finds the methods inmethods
that are declared in a supertype ofclassType
.This should be called only by
buildOverridingMap(randoop.util.MultiMap<randoop.condition.specification.OperationSignature, java.lang.reflect.Method>)
.- Parameters:
classType
- the class whose supertypes are searchedmethods
- the set of methods- Returns:
- the elements of
methods
that are declared in a strict supertype ofclassType
-
getAccessibleObject
private static AccessibleObject getAccessibleObject(OperationSignature operation)
Get thejava.lang.reflect.AccessibleObject
for theOperationSignature
.- Parameters:
operation
- theOperationSignature
- Returns:
- the
java.lang.reflect.AccessibleObject
foroperation
-
readSpecificationFile
private static void readSpecificationFile(Path specificationFile, Map<AccessibleObject,OperationSpecification> specificationMap, MultiMap<OperationSignature,Method> signatureToMethods)
ReadsOperationSpecification
objects from the given file, and adds them to the other two arguments, which are modified by side effect.- Parameters:
specificationFile
- the JSON file ofOperationSpecification
objectsspecificationMap
- side-effected by this methodsignatureToMethods
- side-effected by this method
-
readSpecificationZipFile
private static void readSpecificationZipFile(Path specificationZipFile, Map<AccessibleObject,OperationSpecification> specificationMap, MultiMap<OperationSignature,Method> signatureToMethods)
ReadsOperationSpecification
objects from all the subfiles of the given zip file, and adds them to the other two arguments, which are modified by side effect.- Parameters:
specificationZipFile
- a zip file containing files that containOperationSpecification
objectsspecificationMap
- side-effected by this methodsignatureToMethods
- side-effected by this method
-
getExecutableSpecification
public ExecutableSpecification getExecutableSpecification(Executable executable)
Creates anExecutableSpecification
object for the given constructor or method, from its specifications in this object.The translation makes the following conversions:
- Parameters:
executable
- the reflection object for a constructor or method- Returns:
- the
ExecutableSpecification
for the specifications of the given method or constructor
-
-