Package org.codehaus.groovy.ast
Class ImportNode
java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.AnnotatedNode
org.codehaus.groovy.ast.ImportNode
- All Implemented Interfaces:
GroovydocHolder<AnnotatedNode>,NodeMetaDataHandler
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.
- See Also:
-
Field Summary
Fields inherited from interface groovy.lang.groovydoc.GroovydocHolder
DOC_COMMENT -
Constructor Summary
ConstructorsConstructorDescriptionImportNode(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 alias) Creates an import for a single type (e.g.,import pack.Typeorimport pack.Type as Alias).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.nameorimport static pack.Type.name as alias). -
Method Summary
Modifier and TypeMethodDescriptionbooleangetAlias()Returns 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.getText()Generates the text representation of this import statement as it would appear in source code.getType()Returns theClassNodebeing imported or providing static members.inthashCode()booleanisStar()booleanisStatic()voidUpdates theClassNodebeing imported.voidvisit(GroovyCodeVisitor visitor) Accepts a code visitor for AST traversal and transformation.Methods inherited from class org.codehaus.groovy.ast.AnnotatedNode
addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSyntheticMethods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePositionMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Constructor Details
-
ImportNode
Creates an import for a single type (e.g.,import pack.Typeorimport pack.Type as Alias).- Parameters:
type- theClassNodebeing imported (never null)alias- an optional alias name, or null if no alias is specified- Throws:
NullPointerException- if type is null
-
ImportNode
Creates an import for all types in a package (e.g.,import pack.*).- Parameters:
packageName- the fully qualified package name (never null)- Throws:
NullPointerException- if packageName is null
-
ImportNode
Creates a static wildcard import for all static members of a type (e.g.,import static pack.Type.*).- Parameters:
type- theClassNodewhose static members are imported (never null)- Throws:
NullPointerException- if type is null
-
ImportNode
Creates a static import for a specific field or method of a type (e.g.,import static pack.Type.nameorimport static pack.Type.name as alias).- Parameters:
type- theClassNodecontaining 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 specified- Throws:
NullPointerException- if type or fieldName is null
-
-
Method Details
-
getText
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. -
isStar
public boolean isStar() -
isStatic
public boolean isStatic() -
getAlias
Returns the alias name for this import, if specified.- Returns:
- the alias, or null if no alias is provided
-
getClassName
Returns the fully qualified class name of the imported type.- Returns:
- the class name, or null if this import refers to a package
-
getFieldName
Returns the name of the static field or method being imported via static import.- Returns:
- the field name, or null if this is not a static field/method import
-
getPackageName
Returns the package name for a wildcard import, or the package containing the imported type or static member.- Returns:
- the package name, or null if this import references a specific type
-
getType
Returns theClassNodebeing imported or providing static members.- Returns:
- the imported type, or null if this is a package-level wildcard import
-
setType
Updates theClassNodebeing imported. This may be used during compilation phases to replace placeholder types with resolved types.- Parameters:
type- the newClassNode(never null)- Throws:
NullPointerException- if type is null
-
equals
-
hashCode
public int hashCode() -
visit
Description copied from class:ASTNodeAccepts a code visitor for AST traversal and transformation. Subclasses must implement this method to support visitor pattern-based processing. The visitor pattern enables decoupling of AST structure from processing logic.- Overrides:
visitin classASTNode- Parameters:
visitor- theGroovyCodeVisitorto process this node
-