Package: org.codehaus.groovy.control.customizers

## [Java] Class ImportCustomizer

- org.codehaus.groovy.control.customizers.ImportCustomizer

-     public class ImportCustomizer
      extends CompilationCustomizer

  This compilation customizer allows adding various types of imports to the compilation unit. Supports adding:

  - standard imports via addImports(String...) or addImport(String, String)
  - star imports via addStarImports(String...)
  - static imports via addStaticImport(String, String) or addStaticImport(String, String, String)
  - static star imports via addStaticStars(String...)
  - module imports via addModuleImports(String...)
  Since:
    1.8.0

- - ### Constructor Summary

    Constructors
    Constructor and description
    `ImportCustomizer()` Creates an import customizer that runs during conversion.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public ImportCustomizer` | `addImport(String alias, String className)` Adds a regular import with an explicit alias.
    `` | `public ImportCustomizer` | `addImports(String classNames)` Adds one or more regular imports.
    `` | `public ImportCustomizer` | `addModuleImports(String moduleNames)` Adds module imports.
    `` | `public ImportCustomizer` | `addStarImports(String packageNames)` Adds one or more star imports.
    `` | `public ImportCustomizer` | `addStaticImport(String className, String fieldName)` Adds a static import for a single member without an alias.
    `` | `public ImportCustomizer` | `addStaticImport(String alias, String className, String fieldName)` Adds a static import for a single member with an alias.
    `` | `public ImportCustomizer` | `addStaticStars(String classNames)` Adds one or more static star imports.
    `` | `public void` | `call(SourceUnit source, GeneratorContext context, ClassNode classNode)` Applies the configured imports to the module represented by the current class.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class CompilationCustomizer` | `getPhase`

- - ### Constructor Detail

    - #### public ImportCustomizer()

      Creates an import customizer that runs during conversion.

  - ### Method Detail

    - #### public ImportCustomizer addImport(String alias, String className)

      Adds a regular import with an explicit alias.

      Parameters:
        `alias` - the import alias
        `className` - the fully qualified class name to import
      Returns:
        this customizer

    - #### public ImportCustomizer addImports(String classNames)

      Adds one or more regular imports.

      Parameters:
        `classNames` - the fully qualified class names to import
      Returns:
        this customizer

    - #### public ImportCustomizer addModuleImports(String moduleNames)

      Adds module imports. Each module name (e.g. `"java.sql"`) is expanded at compilation time into star imports for all packages exported by that module, including packages from transitively required modules (per JEP 476).

      Parameters:
        `moduleNames` - the JPMS module names to import
      Since:
        6.0.0

    - #### public ImportCustomizer addStarImports(String packageNames)

      Adds one or more star imports.

      Parameters:
        `packageNames` - the package names to import from
      Returns:
        this customizer

    - #### public ImportCustomizer addStaticImport(String className, String fieldName)

      Adds a static import for a single member without an alias.

      Parameters:
        `className` - the fully qualified declaring class name
        `fieldName` - the static member name
      Returns:
        this customizer

    - #### public ImportCustomizer addStaticImport(String alias, String className, String fieldName)

      Adds a static import for a single member with an alias.

      Parameters:
        `alias` - the alias to expose
        `className` - the fully qualified declaring class name
        `fieldName` - the static member name
      Returns:
        this customizer

    - #### public ImportCustomizer addStaticStars(String classNames)

      Adds one or more static star imports.

      Parameters:
        `classNames` - the fully qualified class names to import members from
      Returns:
        this customizer

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

      Applies the configured imports to the module represented by the current class.

      Parameters:
        `source` - the source unit being customized
        `context` - the current generator context
        `classNode` - the class node being customized