public class OperationModel
extends java.lang.Object
OperationModel
represents the information context from which tests are generated. The
model includes:
This class manages all information about generic classes internally, and instantiates any type variables in operations before returning them.
Modifier and Type | Field and Description |
---|---|
private java.util.Set<Sequence> |
annotatedTestValues
Set of singleton sequences for values from TestValue annotated fields.
|
private MultiMap<ClassOrInterfaceType,Sequence> |
classLiteralMap
Map from a class to the literals that occur in it.
|
private java.util.Set<ClassOrInterfaceType> |
classTypes
The set of class declaration types for this model.
|
private ContractSet |
contracts
Set of object contracts used to generate tests.
|
private java.util.LinkedHashSet<java.lang.Class<?>> |
coveredClassesGoal
The set of classes used as goals in the covered-class test filter.
|
private java.util.Set<Type> |
inputTypes
The set of input types for this model.
|
private java.util.List<java.util.regex.Pattern> |
omitMethods
For debugging only.
|
private OmitMethodsPredicate |
omitMethodsPredicate
User-supplied predicate for methods that should not be used during test generation.
|
private java.util.Set<TypedOperation> |
operations
Set of concrete operations extracted from classes.
|
Modifier | Constructor and Description |
---|---|
private |
OperationModel()
Create an empty model of test context.
|
Modifier and Type | Method and Description |
---|---|
void |
addClassLiterals(ComponentManager compMgr,
java.util.List<java.lang.String> literalsFileList,
GenInputsAbstract.ClassLiteralsMode literalsLevel)
Adds literals to the component manager, by parsing any literals files specified by the user.
|
private void |
addClassTypes(AccessibilityPredicate accessibility,
ReflectionPredicate reflectionPredicate,
java.util.Set<java.lang.String> classnames,
java.util.Set<java.lang.String> coveredClassesGoalNames,
ClassNameErrorHandler errorHandler,
java.util.List<java.lang.String> literalsFileList)
Gathers class types to be used in a run of Randoop and adds them to this
OperationModel . |
private void |
addObjectConstructor()
Creates and adds the Object class default constructor call to the concrete operations.
|
private void |
addOperationsFromClasses(AccessibilityPredicate accessibility,
ReflectionPredicate reflectionPredicate,
SpecificationCollection operationSpecifications)
Adds operations to this
OperationModel from all of the classes of classTypes . |
static OperationModel |
createModel(AccessibilityPredicate accessibility,
ReflectionPredicate reflectionPredicate,
java.util.List<java.util.regex.Pattern> omitMethods,
java.util.Set<java.lang.String> classnames,
java.util.Set<java.lang.String> coveredClassnames,
ClassNameErrorHandler errorHandler,
java.util.List<java.lang.String> literalsFileList)
Factory method to construct an operation model for a particular set of classes without behavior
specifications.
|
static OperationModel |
createModel(AccessibilityPredicate accessibility,
ReflectionPredicate reflectionPredicate,
java.util.List<java.util.regex.Pattern> omitMethods,
java.util.Set<java.lang.String> classnames,
java.util.Set<java.lang.String> coveredClassesGoalNames,
ClassNameErrorHandler errorHandler,
java.util.List<java.lang.String> literalsFileList,
SpecificationCollection operationSpecifications)
Factory method to construct an operation model for a particular set of classes.
|
(package private) static OperationModel |
createModel(AccessibilityPredicate accessibility,
ReflectionPredicate reflectionPredicate,
java.util.Set<java.lang.String> classnames,
java.util.Set<java.lang.String> coveredClassnames,
ClassNameErrorHandler errorHandler,
java.util.List<java.lang.String> literalsFileList)
Factory method to construct an operation model for a particular set of classes without an
omit-methods list or behavior specifications.
|
void |
dumpModel()
Print a verbose representation of the model, if logging is enabled.
|
void |
dumpModel(java.io.PrintStream out)
Print a verbose representation of the model to
out . |
void |
dumpModel(java.io.Writer out)
Print a verbose representation of the model to
out . |
java.util.Set<Sequence> |
getAnnotatedTestValues()
Returns the set of singleton sequences for values from
@TestValue annotated fields. |
private static @Nullable java.lang.Class<?> |
getClass(@ClassGetName java.lang.String classname,
ClassNameErrorHandler errorHandler)
Returns the class whose name is
classname . |
java.util.Set<ClassOrInterfaceType> |
getClassTypes()
Returns the set of types for classes under test.
|
ContractSet |
getContracts()
Returns all
ObjectContract objects for this run of Randoop. |
java.util.Set<java.lang.Class<?>> |
getCoveredClassesGoal()
Returns the set of
Class<?> objects that are the goals for the covered class heuristic. |
java.util.Set<Type> |
getInputTypes()
Returns the set of input types that occur as parameters in classes under test.
|
OmitMethodsPredicate |
getOmitMethodsPredicate()
Returns the user-specified predicate for methods that should not be called.
|
java.util.List<TypedOperation> |
getOperations()
Return the operations of this model as a list.
|
private java.util.List<TypedClassOperation> |
getOperationsFromFile(java.nio.file.Path methodSignatures_file,
AccessibilityPredicate accessibility,
ReflectionPredicate reflectionPredicate)
Constructs an operation from every method signature in the given file.
|
void |
log() |
void |
logOperations(java.io.PrintStream out)
Output the operations of this model to
out , if logging is enabled. |
void |
logOperations(java.io.Writer out)
Output the operations of this model, if logging is enabled.
|
private static MultiMap<Type,TypedClassOperation> |
readOperations(org.plumelib.util.EntryReader er,
boolean ignoreParseError)
Returns operations read from the given EntryReader, which contains fully-qualified method
signatures.
|
static MultiMap<Type,TypedClassOperation> |
readOperations(java.io.InputStream is,
java.lang.String filename)
Returns operations read from the given stream, which contains fully-qualified method
signatures.
|
static MultiMap<Type,TypedClassOperation> |
readOperations(java.io.InputStream is,
java.lang.String filename,
boolean ignoreParseError)
Returns operations read from the given stream, which contains fully-qualified method
signatures.
|
static MultiMap<Type,TypedClassOperation> |
readOperations(@Nullable java.nio.file.Path file)
Given a file containing fully-qualified method signatures, returns the operations for them.
|
static MultiMap<Type,TypedClassOperation> |
readOperations(@Nullable java.nio.file.Path file,
boolean ignoreParseError)
Given a file containing fully-qualified method signatures, returns the operations for them.
|
static TypedClassOperation |
signatureToOperation(java.lang.String signature,
AccessibilityPredicate accessibility,
ReflectionPredicate reflectionPredicate)
Given a signature, returns the method or constructor it represents.
|
private java.util.Set<ClassOrInterfaceType> classTypes
private java.util.Set<Type> inputTypes
private final java.util.LinkedHashSet<java.lang.Class<?>> coveredClassesGoal
private MultiMap<ClassOrInterfaceType,Sequence> classLiteralMap
private java.util.Set<Sequence> annotatedTestValues
private ContractSet contracts
private final java.util.Set<TypedOperation> operations
private java.util.List<java.util.regex.Pattern> omitMethods
private OmitMethodsPredicate omitMethodsPredicate
public static OperationModel createModel(AccessibilityPredicate accessibility, ReflectionPredicate reflectionPredicate, java.util.List<java.util.regex.Pattern> omitMethods, java.util.Set<java.lang.String> classnames, java.util.Set<java.lang.String> coveredClassesGoalNames, ClassNameErrorHandler errorHandler, java.util.List<java.lang.String> literalsFileList, SpecificationCollection operationSpecifications) throws SignatureParseException, java.lang.NoSuchMethodException
accessibility
- the AccessibilityPredicate
to test accessibility of classes and
class membersreflectionPredicate
- the reflection predicate to determine which classes and class
members are usedomitMethods
- the patterns for operations that should be omittedclassnames
- the names of classes under testcoveredClassesGoalNames
- the coverage goal: the names of classes to be tested by the
covered class heuristicerrorHandler
- the handler for bad file name errorsliteralsFileList
- the list of literals file namesoperationSpecifications
- the collection of operation specificationsOperationModel
constructed with the given argumentsSignatureParseException
- if a method signature is ill-formedjava.lang.NoSuchMethodException
- if an attempt is made to load a non-existent methodstatic OperationModel createModel(AccessibilityPredicate accessibility, ReflectionPredicate reflectionPredicate, java.util.Set<java.lang.String> classnames, java.util.Set<java.lang.String> coveredClassnames, ClassNameErrorHandler errorHandler, java.util.List<java.lang.String> literalsFileList) throws java.lang.NoSuchMethodException, SignatureParseException
accessibility
- the AccessibilityPredicate
to test
accessibility of classes and class membersreflectionPredicate
- the reflection predicate to determine which classes and class
members are usedclassnames
- the names of classes under testcoveredClassnames
- the names of classes to be tested by exercised heuristicerrorHandler
- the handler for bad file name errorsliteralsFileList
- the list of literals file namesSignatureParseException
- if a method signature is ill-formedjava.lang.NoSuchMethodException
- if an attempt is made to load a non-existent methodpublic static OperationModel createModel(AccessibilityPredicate accessibility, ReflectionPredicate reflectionPredicate, java.util.List<java.util.regex.Pattern> omitMethods, java.util.Set<java.lang.String> classnames, java.util.Set<java.lang.String> coveredClassnames, ClassNameErrorHandler errorHandler, java.util.List<java.lang.String> literalsFileList) throws java.lang.NoSuchMethodException, SignatureParseException
accessibility
- the AccessibilityPredicate
to test accessibility of classes and
class membersreflectionPredicate
- the reflection predicate to determine which classes and class
members are usedomitMethods
- the patterns for operations that should be omittedclassnames
- the names of classes under testcoveredClassnames
- the names of classes to be tested by covered class heuristicerrorHandler
- the handler for bad file name errorsliteralsFileList
- the list of literals file namesOperationModel
constructed with the given argumentsSignatureParseException
- if a method signature is ill-formedjava.lang.NoSuchMethodException
- if an attempt is made to load a non-existent methodpublic void addClassLiterals(ComponentManager compMgr, java.util.List<java.lang.String> literalsFileList, GenInputsAbstract.ClassLiteralsMode literalsLevel)
GenInputsAbstract.ClassLiteralsMode
.compMgr
- the component managerliteralsFileList
- the list of literals file namesliteralsLevel
- the level of literals to addpublic static MultiMap<Type,TypedClassOperation> readOperations(@Nullable java.nio.file.Path file) throws OperationParseException
file
- a file that contains method or constructor signatures, one per line. If null, this
method returns an empty map.OperationParseException
- if a method signature cannot be parsedpublic static MultiMap<Type,TypedClassOperation> readOperations(@Nullable java.nio.file.Path file, boolean ignoreParseError) throws OperationParseException
file
- a file that contains method or constructor signatures, one per line. If null, this
method returns an empty map.ignoreParseError
- if true, ignore parse errors (skip malformed signatures)OperationParseException
- if a method signature cannot be parsedprivate static MultiMap<Type,TypedClassOperation> readOperations(org.plumelib.util.EntryReader er, boolean ignoreParseError)
er
- the EntryReader to read fromignoreParseError
- if true, ignore parse errors (skip malformed signatures)public static MultiMap<Type,TypedClassOperation> readOperations(java.io.InputStream is, java.lang.String filename)
is
- the stream from which to readfilename
- the file name to use in diagnostic messagespublic static MultiMap<Type,TypedClassOperation> readOperations(java.io.InputStream is, java.lang.String filename, boolean ignoreParseError)
is
- the stream from which to readfilename
- the file name to use in diagnostic messagesignoreParseError
- if true, ignore parse errors (skip malformed signatures)public java.util.Set<ClassOrInterfaceType> getClassTypes()
public java.util.Set<java.lang.Class<?>> getCoveredClassesGoal()
Class<?>
objects that are the goals for the covered class heuristic.public java.util.Set<Type> getInputTypes()
TypeExtractor
public java.util.List<TypedOperation> getOperations()
public ContractSet getContracts()
ObjectContract
objects for this run of Randoop. Includes Randoop defaults
and CheckRep
annotated methods.public OmitMethodsPredicate getOmitMethodsPredicate()
public java.util.Set<Sequence> getAnnotatedTestValues()
@TestValue
annotated fields.@TestValue
public void log()
public void logOperations(java.io.PrintStream out)
out
, if logging is enabled.out
- the PrintStream on which to produce outputpublic void logOperations(java.io.Writer out)
out
- the Writer on which to produce outputpublic void dumpModel()
public void dumpModel(java.io.PrintStream out)
out
.out
- the PrintStream on which to produce outputpublic void dumpModel(java.io.Writer out)
out
.out
- the Writer on which to produce outputprivate void addClassTypes(AccessibilityPredicate accessibility, ReflectionPredicate reflectionPredicate, java.util.Set<java.lang.String> classnames, java.util.Set<java.lang.String> coveredClassesGoalNames, ClassNameErrorHandler errorHandler, java.util.List<java.lang.String> literalsFileList)
OperationModel
. Specifically, collects types for classes-under-test, objects for covered-class
heuristic, concrete input types, annotated test values, and literal values. It operates by
converting from strings to Class
objects. Also collects annotated test values, and
class literal values used in test generation.accessibility
- the accessibility predicatereflectionPredicate
- the predicate to determine which reflection objects are usedclassnames
- the names of classes-under-testcoveredClassesGoalNames
- the names of classes used as goals in the covered-class
heuristicerrorHandler
- the handler for bad class namesliteralsFileList
- the list of literals file namesprivate static @Nullable java.lang.Class<?> getClass(@ClassGetName java.lang.String classname, ClassNameErrorHandler errorHandler)
classname
. A wrapper around Class.forName.classname
- the name of a class or primitive typeerrorHandler
- is called if no such class existsclassname
. May return null if errorHandler
just
warns on bad names.private void addOperationsFromClasses(AccessibilityPredicate accessibility, ReflectionPredicate reflectionPredicate, SpecificationCollection operationSpecifications)
OperationModel
from all of the classes of classTypes
.accessibility
- the accessibility predicatereflectionPredicate
- the reflection predicateoperationSpecifications
- the collection of OperationSpecification
private java.util.List<TypedClassOperation> getOperationsFromFile(java.nio.file.Path methodSignatures_file, AccessibilityPredicate accessibility, ReflectionPredicate reflectionPredicate) throws SignatureParseException
methodSignatures_file
- the file containing the signatures; if null, return the emply listaccessibility
- the accessibility predicatereflectionPredicate
- the reflection predicateSignatureParseException
- if any signature is syntactically invalidpublic static TypedClassOperation signatureToOperation(java.lang.String signature, AccessibilityPredicate accessibility, ReflectionPredicate reflectionPredicate) throws SignatureParseException, FailedPredicateException
signature
- the operation's signature, in Randoop's formataccessibility
- the accessibility predicatereflectionPredicate
- the reflection predicateFailedPredicateException
- if the accessibility or reflection predicate returns false on
the class or the method or constructorSignatureParseException
- if the signature cannot be parsedprivate void addObjectConstructor()