Modifier | Constructor and Description |
---|---|
protected |
Generator(Class<T> type) |
protected |
Generator(List<Class<T>> types)
Used for generators of primitives and their wrappers.
|
Modifier and Type | Method and Description |
---|---|
void |
addComponentGenerators(List<Generator<?>> newComponents)
Adds component generators to this generator.
|
boolean |
canGenerateForParametersOfTypes(List<org.javaruntype.type.TypeParameter<?>> typeParameters) |
boolean |
canRegisterAsType(Class<?> type)
Tells whether this generator is allowed to be used for property
parameters of the given type.
|
boolean |
canShrink(Object larger)
Tells whether this generator is allowed to participate in the
Shrink process for the given "larger" value. |
static boolean |
compatibleWithTypeParameter(org.javaruntype.type.TypeParameter<?> parameter,
Class<?> clazz) |
protected static List<Annotation> |
configurationAnnotationsOn(AnnotatedElement element)
Gives a list of the
GeneratorConfiguration annotations present
on the given program element. |
void |
configure(AnnotatedElement element) |
void |
configure(AnnotatedType annotatedType)
Configures this generator using annotations from a given annotated
type.
|
List<T> |
doShrink(SourceOfRandomness random,
T larger)
Gives some objects that are "smaller" than a given "larger"
object.
|
protected Generators |
gen() |
boolean |
hasComponents() |
protected T |
narrow(Object wider)
Attempts to "narrow" the given object to the type this generator
produces.
|
int |
numberOfNeededComponents() |
void |
provide(Generators provided)
Used to supply the available generators to this one.
|
List<T> |
shrink(SourceOfRandomness random,
Object larger)
Gives some objects that are "smaller" than a given object.
|
List<Class<T>> |
types() |
protected Generator(Class<T> type)
type
- class token for type of property parameter this generator is
applicable topublic List<Class<T>> types()
public boolean canRegisterAsType(Class<?> type)
type
- type against which to test this generatortrue
if the generator is allowed to participate in
generating values for property parameters of type
public final List<T> shrink(SourceOfRandomness random, Object larger)
Generators first ensure that they can participate in shrinking the given value, and if so, they produce shrinks.
public boolean canShrink(Object larger)
Tells whether this generator is allowed to participate in the
Shrink
process for the given "larger" value.
Unless overridden, the only criterion for whether a generator is allowed to participate in shrinking a value is if the value can be safely cast to the type of values the generator produces.
larger
- the "larger" valuepublic List<T> doShrink(SourceOfRandomness random, T larger)
Gives some objects that are "smaller" than a given "larger" object.
Unless overridden, a generator will produce an empty list of "smaller" values.
random
- source of randomness to use in shrinking, if desiredlarger
- the larger objectprotected final T narrow(Object wider)
wider
- target of the narrowingClassCastException
- if the narrowing cannot be performedpublic boolean hasComponents()
addComponentGenerators(java.util.List)
public int numberOfNeededComponents()
addComponentGenerators(java.util.List)
public void addComponentGenerators(List<Generator<?>> newComponents)
Adds component generators to this generator.
Some generators need component generators to create proper values. For example, list generators require a single component generator in order to generate elements that have the type of the list parameter's type argument.
newComponents
- component generators to addpublic boolean canGenerateForParametersOfTypes(List<org.javaruntype.type.TypeParameter<?>> typeParameters)
typeParameters
- a list of generic type parameterspublic static boolean compatibleWithTypeParameter(org.javaruntype.type.TypeParameter<?> parameter, Class<?> clazz)
parameter
- a generic type parameterclazz
- a typecanGenerateForParametersOfTypes(List)
public void configure(AnnotatedType annotatedType)
Configures this generator using annotations from a given annotated type.
This method considers only annotations that are themselves marked
with GeneratorConfiguration
.
By default, the generator will configure itself using this procedure:
public
method on the generator named
configure
, that accepts a single parameter of the
annotation typeconfigure
method reflectively, passing the
annotation as the argumentannotatedType
- a type usageGeneratorConfigurationException
- if the generator does not
"understand" one of the generation configuration annotations on
the annotated typepublic void configure(AnnotatedElement element)
element
- an annotated program elementpublic void provide(Generators provided)
provided
- repository of available generatorsprotected Generators gen()
protected static List<Annotation> configurationAnnotationsOn(AnnotatedElement element)
GeneratorConfiguration
annotations present
on the given program element.element
- an annotated program element© Copyright 2010-2016 Paul R. Holser, Jr. All rights reserved. Licensed under The MIT License. pholser@alumni.rice.edu