Package org.codehaus.groovy.control.customizers

# Class ImportCustomizer

java.lang.Object
org.codehaus.groovy.control.customizers.CompilationCustomizer
org.codehaus.groovy.control.customizers.ImportCustomizer

All Implemented Interfaces:
  `CompilationUnit.IPrimaryClassNodeOperation`

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
  Description
  `ImportCustomizer()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ImportCustomizer`
  `addImport(String alias, String className)`
  `ImportCustomizer`
  `addImports(String... classNames)`
  `ImportCustomizer`
  `addModuleImports(String... moduleNames)`
  Adds module imports.
  `ImportCustomizer`
  `addStarImports(String... packageNames)`
  `ImportCustomizer`
  `addStaticImport(String className, String fieldName)`
  `ImportCustomizer`
  `addStaticImport(String alias, String className, String fieldName)`
  `ImportCustomizer`
  `addStaticStars(String... classNames)`
  `void`
  `call(SourceUnit source, GeneratorContext context, ClassNode classNode)`

  ### Methods inherited from class org.codehaus.groovy.control.customizers.CompilationCustomizer

  `getPhase`

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

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

  ### Methods inherited from interface org.codehaus.groovy.control.CompilationUnit.IPrimaryClassNodeOperation

  `doPhaseOperation, needSortedInput`

- ## Constructor Details

  - ### ImportCustomizer

    public ImportCustomizer()

- ## Method Details

  - ### call

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

  - ### addImport

    public ImportCustomizer addImport(String alias, String className)

  - ### addStaticImport

    public ImportCustomizer addStaticImport(String className, String fieldName)

  - ### addStaticImport

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

  - ### addImports

    public ImportCustomizer addImports(String... classNames)

  - ### addStarImports

    public ImportCustomizer addStarImports(String... packageNames)

  - ### addStaticStars

    public ImportCustomizer addStaticStars(String... classNames)

  - ### addModuleImports

    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