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
  • Field Details

    • factory

      protected final Factory factory
  • Constructor Details

  • Method Details

    • generateSingleTarget

      public <T> @Nullable T generateSingleTarget(RootNode node, ImmutableMap parameters, Class<T> expectedType)
      Generates one target depending on kind of this RootNode, expected `expectedType` and input `parameters`
      Parameters:
      node - to be generated node
      parameters - ImmutableMap
      expectedType - defines Class 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 this RootNode, expected `expectedType` and input `parameters`
      Parameters:
      node - to be generated node
      parameters - ImmutableMap
      expectedType - defines Class 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 this RootNode, expected `result` and input `parameters`
      Parameters:
      node - to be generated node
      result - the holder which receives the generated node
      parameters - 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 - the ParameterInfo, which describes exact parameter from `parameters`
      result - the holder which receives the generated node
      parameters - the input parameters
    • getFactory

      public Factory getFactory()
      Specified by:
      getFactory in interface Generator
      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 element
      genBy - the documentation to be added
    • getGeneratedByComment

      public String getGeneratedByComment(CtElement ele)
    • generate

      public <T extends CtElement> List<T> generate(ImmutableMap params)
      Description copied from interface: Generator
      Utility method that provides the same feature as Generator.generate(Map), but with a ImmutableMap as parameter (a Spoon elegant utility type)
      Specified by:
      generate in interface Generator
    • 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`
      Specified by:
      generate in interface Generator
      Parameters:
      params - - the substitution parameters, it can be CtElement, primitive literals like String, Integer, ... and or List or Set of them.
      Returns:
      List of generated elements
    • 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.
      Specified by:
      generate in interface Generator
      Parameters:
      typeQualifiedName - the qualified name of to be generated type
      params - the pattern parameters
      Returns:
      the generated type
    • isAddGeneratedBy

      public boolean isAddGeneratedBy()