Package: org.codehaus.groovy.control.customizers

## [Java] Class SourceAwareCustomizer

- org.codehaus.groovy.control.customizers.SourceAwareCustomizer

-     public class SourceAwareCustomizer
      extends DelegatingCustomizer

  A base class for customizers which only have to be applied on specific source units. This is for example useful if you want a customizer to be applied only for files matching some extensions.

  For convenience, this class implements several methods that you may extend to customize the behaviour of this utility. For example, if you want to apply a customizer only for classes matching the '.foo' file extension, then you only have to override the acceptExtension(String) method:

      return "foo".equals(extension)

  Since:
    2.1.0

- - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class DelegatingCustomizer` | `delegate`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `SourceAwareCustomizer(CompilationCustomizer delegate)` Creates a source-aware wrapper around another compilation customizer.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public boolean` | `accept(String fileName)` Checks whether a source file name is accepted by the base-name and extension validators.
    `` | `public boolean` | `acceptBaseName(String baseName)` Checks whether a base file name is accepted.
    `` | `public boolean` | `acceptClass(ClassNode cnode)` Checks whether a class node is accepted.
    `` | `public boolean` | `acceptExtension(String extension)` Checks whether a file extension is accepted.
    `` | `public boolean` | `acceptSource(SourceUnit unit)` Checks whether a source unit is accepted.
    `` | `public void` | `call(SourceUnit source, GeneratorContext context, ClassNode classNode)` Invokes the delegate only when the source and class validators accept the current input.
    `` | `public void` | `setBaseNameValidator(Closure<Boolean> baseNameValidator)` Sets the predicate used to validate source base names.
    `` | `public void` | `setClassValidator(Closure<Boolean> classValidator)` Sets the predicate used to validate class nodes.
    `` | `public void` | `setExtensionValidator(Closure<Boolean> extensionValidator)` Sets the predicate used to validate source file extensions.
    `` | `public void` | `setSourceUnitValidator(Closure<Boolean> sourceUnitValidator)` Sets the predicate used to validate whole source units.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class DelegatingCustomizer` | `call, setCompilationUnit`
    `class CompilationCustomizer` | `getPhase`

- - ### Constructor Detail

    - #### public SourceAwareCustomizer(CompilationCustomizer delegate)

      Creates a source-aware wrapper around another compilation customizer.

      Parameters:
        `delegate` - the customizer to invoke when the source matches

  - ### Method Detail

    - #### public boolean accept(String fileName)

      Checks whether a source file name is accepted by the base-name and extension validators.

      Parameters:
        `fileName` - the file name to inspect
      Returns:
        `true` if the file name is accepted

    - #### public boolean acceptBaseName(String baseName)

      Checks whether a base file name is accepted.

      Parameters:
        `baseName` - the base file name to inspect
      Returns:
        `true` if the base name is accepted

    - #### public boolean acceptClass(ClassNode cnode)

      Checks whether a class node is accepted.

      Parameters:
        `cnode` - the class node to inspect
      Returns:
        `true` if the class is accepted

    - #### public boolean acceptExtension(String extension)

      Checks whether a file extension is accepted.

      Parameters:
        `extension` - the extension to inspect
      Returns:
        `true` if the extension is accepted

    - #### public boolean acceptSource(SourceUnit unit)

      Checks whether a source unit is accepted.

      Parameters:
        `unit` - the source unit to inspect
      Returns:
        `true` if the source is accepted

    - #### public void call(SourceUnit source, GeneratorContext context, ClassNode classNode)

      Invokes the delegate only when the source and class validators accept the current input.

      A `null` source unit selects nothing: this customizer exists to match against source units, so a class node which has none (see org.codehaus.groovy.control.CompilationUnit.IPrimaryClassNodeOperation#call) cannot satisfy any source-based criterion, and the delegate is not invoked.

      throws:
        CompilationFailedException if the delegate fails
      Parameters:
        `source` - the source unit being customized, possibly `null`
        `context` - the current generator context
        `classNode` - the class node being customized

    - #### public void setBaseNameValidator(Closure<Boolean> baseNameValidator)

      Sets the predicate used to validate source base names.

      Parameters:
        `baseNameValidator` - the validator to use

    - #### public void setClassValidator(Closure<Boolean> classValidator)

      Sets the predicate used to validate class nodes.

      Parameters:
        `classValidator` - the validator to use

    - #### public void setExtensionValidator(Closure<Boolean> extensionValidator)

      Sets the predicate used to validate source file extensions.

      Parameters:
        `extensionValidator` - the validator to use

    - #### public void setSourceUnitValidator(Closure<Boolean> sourceUnitValidator)

      Sets the predicate used to validate whole source units.

      Parameters:
        `sourceUnitValidator` - the validator to use