Class ImportCustomizer
java.lang.Object
org.codehaus.groovy.control.customizers.CompilationCustomizer
org.codehaus.groovy.control.customizers.ImportCustomizer
- All Implemented Interfaces:
CompilationUnit.IPrimaryClassNodeOperation
This compilation customizer allows adding various types of imports to the compilation unit. Supports adding:
- standard imports via
addImports(String...)oraddImport(String, String) - star imports via
addStarImports(String...) - static imports via
addStaticImport(String, String)oraddStaticImport(String, String, String) - static star imports via
addStaticStars(String...) - module imports via
addModuleImports(String...)
- Since:
- 1.8.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an import customizer that runs during conversion. -
Method Summary
Modifier and TypeMethodDescriptionAdds a regular import with an explicit alias.addImports(String... classNames) Adds one or more regular imports.addModuleImports(String... moduleNames) Adds module imports.addStarImports(String... packageNames) Adds one or more star imports.addStaticImport(String className, String fieldName) Adds a static import for a single member without an alias.addStaticImport(String alias, String className, String fieldName) Adds a static import for a single member with an alias.addStaticStars(String... classNames) Adds one or more static star imports.voidcall(SourceUnit source, GeneratorContext context, ClassNode classNode) Applies the configured imports to the module represented by the current class.Methods inherited from class org.codehaus.groovy.control.customizers.CompilationCustomizer
getPhaseMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.control.CompilationUnit.IPrimaryClassNodeOperation
doPhaseOperation, needSortedInput
-
Constructor Details
-
ImportCustomizer
public ImportCustomizer()Creates an import customizer that runs during conversion.
-
-
Method Details
-
call
Applies the configured imports to the module represented by the current class.- Parameters:
source- the source unit being customizedcontext- the current generator contextclassNode- the class node being customized
-
addImport
Adds a regular import with an explicit alias.- Parameters:
alias- the import aliasclassName- the fully qualified class name to import- Returns:
- this customizer
-
addStaticImport
Adds a static import for a single member without an alias.- Parameters:
className- the fully qualified declaring class namefieldName- the static member name- Returns:
- this customizer
-
addStaticImport
Adds a static import for a single member with an alias.- Parameters:
alias- the alias to exposeclassName- the fully qualified declaring class namefieldName- the static member name- Returns:
- this customizer
-
addImports
Adds one or more regular imports.- Parameters:
classNames- the fully qualified class names to import- Returns:
- this customizer
-
addStarImports
Adds one or more star imports.- Parameters:
packageNames- the package names to import from- Returns:
- this customizer
-
addStaticStars
Adds one or more static star imports.- Parameters:
classNames- the fully qualified class names to import members from- Returns:
- this customizer
-
addModuleImports
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
-