Package spoon.pattern

Class PatternBuilder

java.lang.Object
spoon.pattern.PatternBuilder

public class PatternBuilder extends Object
The master class to create a Pattern instance. Main documentation at http://spoon.gforge.inria.fr/pattern.html.
  • Field Details

  • Constructor Details

    • PatternBuilder

      protected PatternBuilder(List<? extends CtElement> template)
  • Method Details

    • create

      public static PatternBuilder create(List<? extends CtElement> patternModel)
      Creates a PatternBuilder from the List of template elements
      Parameters:
      patternModel - a List of Spoon AST nodes, which represents a template of to be generated or to be matched code
      Returns:
      new instance of PatternBuilder
    • create

      public static PatternBuilder create(CtElement... elems)
    • build

      public Pattern build()
      Builds a Pattern and returns it
      Returns:
      the built pattern
      Throws:
      SpoonException - if the pattern has been built already
    • configurePatternParameters

      public PatternBuilder configurePatternParameters()
      All the variable references, whose variables are out of the template model are automatically marked as pattern parameters
      Returns:
      this to support fluent API
    • configurePatternParameters

      public PatternBuilder configurePatternParameters(Consumer<PatternParameterConfigurator> parametersBuilder)
      Configure pattern parameters with a PatternParameterConfigurator
      Returns:
      this
    • configureInlineStatements

      public PatternBuilder configureInlineStatements(Consumer<InlinedStatementConfigurator> consumer)
      Configures inlined statements For example if the `for` statement in this pattern model
      
       for(Object x : $iterable$) {
              System.out.println(x);
       }
       
      is configured as inline statement and a Pattern is substituted using parameter $iterable$ = new String[]{"A", "B", "C"} then pattern generated this code
      
       System.out.println("A");
       System.out.println("B");
       System.out.println("C");
       
      because inline statements are executed during substitution process and are not included in generated result. The inline statements may be used in PatternMatching process (opposite to Pattern substitution) too.
      Parameters:
      consumer -
      Returns:
      this to support fluent API
    • getFactory

      protected Factory getFactory()
    • setAddGeneratedBy

      public PatternBuilder setAddGeneratedBy(boolean addGeneratedBy)
      Parameters:
      addGeneratedBy - true when generated by comments have to be appended to each generated type member
      Returns:
      this to support fluent API
    • isAutoSimplifySubstitutions

      public boolean isAutoSimplifySubstitutions()
      Returns:
      true if generated result has to be evaluated to apply simplifications.
    • setAutoSimplifySubstitutions

      public PatternBuilder setAutoSimplifySubstitutions(boolean autoSimplifySubstitutions)
      Parameters:
      autoSimplifySubstitutions - true if generated result of each substituted has to be evaluated to apply simplifications. The rule is applied only to substitutions defined after this call
      Returns:
      this to support fluent API