Package org.codehaus.groovy.control.customizers.builder

# Class SourceAwareCustomizerFactory

java.lang.Object
groovy.util.AbstractFactory
org.codehaus.groovy.control.customizers.builder.SourceAwareCustomizerFactory

All Implemented Interfaces:
  `Factory`, `PostCompletionFactory`

public class SourceAwareCustomizerFactory extends AbstractFactory implements PostCompletionFactory
Factory for use with `CompilerCustomizationBuilder`. Allows the construction of `source aware customizers`. Syntax:

         // apply CompileStatic AST annotation on .sgroovy files
         builder.source(extension: 'sgroovy') {
             ast(CompileStatic)
         }

         // apply CompileStatic AST annotation on .sgroovy or .sg files
         builder.source(extensions: ['sgroovy','sg']) {
             ast(CompileStatic)
         }

         // apply CompileStatic AST annotation on .sgroovy or .sg files
         builder.source(extensionValidator: { it.name in ['sgroovy','sg']}) {
             ast(CompileStatic)
         }

         // apply CompileStatic AST annotation on files whose name is 'foo'
         builder.source(basename: 'foo') {
             ast(CompileStatic)
         }

         // apply CompileStatic AST annotation on files whose name is 'foo' or 'bar'
         builder.source(basenames: ['foo', 'bar']) {
             ast(CompileStatic)
         }

         // apply CompileStatic AST annotation on files whose name is 'foo' or 'bar'
         builder.source(basenameValidator: { it in ['foo', 'bar'] }) {
             ast(CompileStatic)
         }

         // apply CompileStatic AST annotation on files that do not contain a class named 'Baz'
         builder.source(unitValidator: { unit -> !unit.AST.classes.any { it.name == 'Baz' } }) {
             ast(CompileStatic)
         }

         // apply CompileStatic AST annotation on class nodes that end with 'CS'
         builder.source(classValidator: { cn -> cn.name.endsWith('CS') }) {
             ast(CompileStatic)
         }

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `SourceAwareCustomizerFactory.SourceOptions`
  Collected builder options used to create a `SourceAwareCustomizer`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SourceAwareCustomizerFactory()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `newInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes)`
  Creates the mutable source options collected from the builder node.
  `Object`
  `postCompleteNode(FactoryBuilderSupport factory, Object parent, Object node)`
  Converts the collected source options into a configured `SourceAwareCustomizer`.
  `void`
  `setChild(FactoryBuilderSupport builder, Object parent, Object child)`
  Captures the nested compilation customizer selected for the source-aware wrapper.

  ### Methods inherited from class groovy.util.AbstractFactory

  `isHandlesNodeChildren, isLeaf, onFactoryRegistration, onHandleNodeAttributes, onNodeChildren, onNodeCompleted, setParent`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### SourceAwareCustomizerFactory

    public SourceAwareCustomizerFactory()

- ## Method Details

  - ### newInstance

    public Object newInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes) throws InstantiationException, IllegalAccessException
    Creates the mutable source options collected from the builder node.
    Specified by:
      `newInstance` in interface `Factory`
    Parameters:
      `builder` - the active builder
      `name` - the node name
      `value` - the supplied node value
      `attributes` - the node attributes
    Returns:
      the collected source options
    Throws:
      `InstantiationException` - if instantiation fails
      `IllegalAccessException` - if access fails

  - ### setChild

    public void setChild(FactoryBuilderSupport builder, Object parent, Object child)
    Captures the nested compilation customizer selected for the source-aware wrapper.
    Specified by:
      `setChild` in interface `Factory`
    Overrides:
      `setChild` in class `AbstractFactory`
    Parameters:
      `builder` - the active builder
      `parent` - the parent node
      `child` - the child node

  - ### postCompleteNode

    public Object postCompleteNode(FactoryBuilderSupport factory, Object parent, Object node)
    Converts the collected source options into a configured `SourceAwareCustomizer`.
    Specified by:
      `postCompleteNode` in interface `PostCompletionFactory`
    Parameters:
      `factory` - the active builder
      `parent` - the parent node
      `node` - the completed node
    Returns:
      the configured source-aware customizer