public class ImportNode
extends AnnotatedNode
Represents an import statement in Groovy source code, supporting single-type imports, wildcard imports, and static imports. Provides a unified representation for different import styles with methods to query import type and generate display text.
| Constructor and description |
|---|
ImportNode(ClassNode type, String alias)Creates an import for a single type (e.g., import pack.Type or import pack.Type as Alias). |
ImportNode(String packageName)Creates an import for all types in a package (e.g., import pack.*). |
ImportNode(ClassNode type)Creates a static wildcard import for all static members of a type (e.g., import static pack.Type.*). |
ImportNode(ClassNode type, String fieldName, String alias)Creates a static import for a specific field or method of a type (e.g., import static pack.Type.name
or import static pack.Type.name as alias). |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public boolean |
equals(Object that) |
|
public String |
getAlias()Returns the alias name for this import, if specified. |
|
public String |
getClassName()Returns the fully qualified class name of the imported type. |
|
public String |
getFieldName()Returns the name of the static field or method being imported via static import. |
|
public String |
getPackageName()Returns the package name for a wildcard import, or the package containing the imported type or static member. |
|
public String |
getText()Generates the text representation of this import statement as it would appear in source code. |
|
public ClassNode |
getType()Returns the ClassNode being imported or providing static members. |
|
public int |
hashCode() |
|
public boolean |
isStar() |
|
public boolean |
isStatic() |
|
public void |
setType(ClassNode type)Updates the ClassNode being imported. |
|
public void |
visit(GroovyCodeVisitor visitor) |
| Methods inherited from class | Name |
|---|---|
class AnnotatedNode |
addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic |
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit |
Creates an import for a single type (e.g., import pack.Type or import pack.Type as Alias).
type - the ClassNode being imported (never null)alias - an optional alias name, or null if no alias is specified Creates an import for all types in a package (e.g., import pack.*).
packageName - the fully qualified package name (never null) Creates a static wildcard import for all static members of a type (e.g., import static pack.Type.*).
type - the ClassNode whose static members are imported (never null) Creates a static import for a specific field or method of a type (e.g., import static pack.Type.name
or import static pack.Type.name as alias).
type - the ClassNode containing the static member (never null)fieldName - the name of the static field or method being imported (never null)alias - an optional alias name, or null if no alias is specifiedReturns the alias name for this import, if specified.
Returns the fully qualified class name of the imported type.
Returns the name of the static field or method being imported via static import.
Returns the package name for a wildcard import, or the package containing the imported type or static member.
Generates the text representation of this import statement as it would appear in source code. For example: "import java.util.List", "import static java.util.Collections.*", etc.
Returns the ClassNode being imported or providing static members.
Updates the ClassNode being imported. This may be used during compilation phases to replace placeholder types with resolved types.
type - the new ClassNode (never null)Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.