T
- the type of objects generatedpublic class Ctor<T> extends Generator<T>
Produces instances of a class by generating values for the parameters of one of the constructors on the class, and invoking the constructor.
If a constructor parameter is marked with an annotation that influences the generation of a given kind of value, that annotation will be applied to the generation of values for that parameter.
This generator is intended to be used with
From
, and not to be available via the
ServiceLoader
mechanism.
Constructor and Description |
---|
Ctor(Class<T> type)
Reflects the given type for a single accessible constructor to be used
to generate values of that type.
|
Ctor(Constructor<T> ctor)
Uses the given constructor to generate values of the declaring type.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canRegisterAsType(Class<?> type)
Tells whether this generator is allowed to be used for property
parameters of the given type.
|
void |
configure(AnnotatedType annotatedType)
Configures this generator using annotations from a given annotated
type.
|
T |
generate(SourceOfRandomness random,
GenerationStatus status)
Generates a value, possibly influenced by a source of randomness and
metadata about the generation.
|
void |
provide(Generators provided)
Used to supply the available generators to this one.
|
addComponentGenerators, canGenerateForParametersOfTypes, canShrink, compatibleWithTypeParameter, configurationAnnotationsOn, configure, doShrink, gen, hasComponents, narrow, numberOfNeededComponents, shrink, types
public Ctor(Class<T> type)
type
- the type of objects to be generatedpublic Ctor(Constructor<T> ctor)
ctor
- the constructor to reflect on to generate constructor
parameter valuespublic T generate(SourceOfRandomness random, GenerationStatus status)
Gen
random
- source of randomness to be used when generating the valuestatus
- an object that can be used to influence the generated
value. For example, generating lists can use the size
method to generate lists with a given
number of elements.public boolean canRegisterAsType(Class<?> type)
Generator
canRegisterAsType
in class Generator<T>
type
- type against which to test this generatortrue
if the generator is allowed to participate in
generating values for property parameters of type
public void provide(Generators provided)
Generator
public void configure(AnnotatedType annotatedType)
Generator
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 argument© Copyright 2010-2016 Paul R. Holser, Jr. All rights reserved. Licensed under The MIT License. pholser@alumni.rice.edu