Package spoon.pattern.internal
Class DefaultGenerator
- java.lang.Object
-
- spoon.pattern.internal.DefaultGenerator
-
- All Implemented Interfaces:
Generator
- Direct Known Subclasses:
PatternPrinter
public class DefaultGenerator extends Object implements Generator
Drives generation process
-
-
Constructor Summary
Constructors Constructor Description DefaultGenerator(Factory factory, ListOfNodes nodes)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyGeneratedBy(CtElement generatedElement, String genBy)
Adds a Generated by comment to the javadoc of generatedElement<T extends CtType<?>>
Tgenerate(String typeQualifiedName, Map<String,Object> params)
Generates a type with qualified name `typeQualifiedName` by replacing the generator parameters with the arguments given in `params`.<T extends CtElement>
List<T>generate(Map<String,Object> params)
Main method to generate a new AST made from substituting of parameters by the values in `params`<T extends CtElement>
List<T>generate(ImmutableMap params)
Utility method that provides the same feature asGenerator.generate(Map)
, but with aImmutableMap
as parameter (a Spoon elegant utility type)<T> T
generateSingleTarget(RootNode node, ImmutableMap parameters, Class<T> expectedType)
Generates one target depending on kind of thisRootNode
, expected `expectedType` and input `parameters`<T> void
generateTargets(RootNode node, ResultHolder<T> result, ImmutableMap parameters)
Generates zero, one or more target depending on kind of thisRootNode
, expected `result` and input `parameters`<T> List<T>
generateTargets(RootNode node, ImmutableMap parameters, Class<T> expectedType)
Generates zero, one or more targets depending on kind of thisRootNode
, expected `expectedType` and input `parameters`Factory
getFactory()
String
getGeneratedByComment(CtElement ele)
<T> void
getValueAs(ParameterInfo parameterInfo, ResultHolder<T> result, ImmutableMap parameters)
Returns zero, one or more values into `result`.boolean
isAddGeneratedBy()
DefaultGenerator
setAddGeneratedBy(boolean addGeneratedBy)
-
-
-
Field Detail
-
factory
protected final Factory factory
-
-
Constructor Detail
-
DefaultGenerator
public DefaultGenerator(Factory factory, ListOfNodes nodes)
-
-
Method Detail
-
generateSingleTarget
public <T> T generateSingleTarget(RootNode node, ImmutableMap parameters, Class<T> expectedType)
Generates one target depending on kind of thisRootNode
, expected `expectedType` and input `parameters`- Parameters:
node
- to be generated nodeparameters
-ImmutableMap
expectedType
- definesClass
of returned value- Returns:
- a generate value or null
-
generateTargets
public <T> List<T> generateTargets(RootNode node, ImmutableMap parameters, Class<T> expectedType)
Generates zero, one or more targets depending on kind of thisRootNode
, expected `expectedType` and input `parameters`- Parameters:
node
- to be generated nodeparameters
-ImmutableMap
expectedType
- definesClass
of returned value- Returns:
- a
List
of generated targets
-
generateTargets
public <T> void generateTargets(RootNode node, ResultHolder<T> result, ImmutableMap parameters)
Generates zero, one or more target depending on kind of thisRootNode
, expected `result` and input `parameters`- Parameters:
node
- to be generated noderesult
- the holder which receives the generated nodeparameters
- the input parameters
-
getValueAs
public <T> void getValueAs(ParameterInfo parameterInfo, ResultHolder<T> result, ImmutableMap parameters)
Returns zero, one or more values into `result`. The value comes from `parameters` from the location defined by `parameterInfo`- Parameters:
parameterInfo
- theParameterInfo
, which describes exact parameter from `parameters`result
- the holder which receives the generated nodeparameters
- the input parameters
-
getFactory
public Factory getFactory()
- Specified by:
getFactory
in interfaceGenerator
- Returns:
- a
Factory
, which has to be used to generate instances
-
setAddGeneratedBy
public DefaultGenerator setAddGeneratedBy(boolean addGeneratedBy)
-
applyGeneratedBy
public void applyGeneratedBy(CtElement generatedElement, String genBy)
Adds a Generated by comment to the javadoc of generatedElement- Parameters:
generatedElement
- a newly generated elementgenBy
- the documentation to be added
-
generate
public <T extends CtElement> List<T> generate(ImmutableMap params)
Description copied from interface:Generator
Utility method that provides the same feature asGenerator.generate(Map)
, but with aImmutableMap
as parameter (a Spoon elegant utility type)
-
generate
public <T extends CtElement> List<T> generate(Map<String,Object> params)
Description copied from interface:Generator
Main method to generate a new AST made from substituting of parameters by the values in `params`
-
generate
public <T extends CtType<?>> T generate(String typeQualifiedName, Map<String,Object> params)
Description copied from interface:Generator
Generates a type with qualified name `typeQualifiedName` by replacing the generator parameters with the arguments given in `params`. Note: the root element of pattern must be a CtType.
-
isAddGeneratedBy
public boolean isAddGeneratedBy()
-
-