Package org.codehaus.groovy.control

# Class StaticImportVisitor

java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeExpressionTransformer
org.codehaus.groovy.control.StaticImportVisitor

All Implemented Interfaces:
  `ExpressionTransformer`, `GroovyClassVisitor`, `GroovyCodeVisitor`, `ErrorCollecting`

public class StaticImportVisitor extends ClassCodeExpressionTransformer
Visitor to resolve constants and method calls from static imports.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StaticImportVisitor(ClassNode classNode, SourceUnit sourceUnit)`
  Creates a visitor that rewrites references resolved through static imports.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected SourceUnit`
  `getSourceUnit()`
  Returns the source unit currently being transformed.
  `Expression`
  `transform(Expression exp)`
  Rewrites expressions that may target statically imported members.
  `protected Expression`
  `transformBinaryExpression(BinaryExpression be)`
  Rewrites binary expressions that may reference statically imported members.
  `protected Expression`
  `transformClosureExpression(ClosureExpression ce)`
  Rewrites default parameter expressions inside closures.
  `protected Expression`
  `transformConstructorCallExpression(ConstructorCallExpression cce)`
  Rewrites named-argument constructor calls that use statically imported members.
  `protected Expression`
  `transformMethodCallExpression(MethodCallExpression mce)`
  Rewrites implicit-this calls that resolve to statically imported methods or properties.
  `protected Expression`
  `transformPropertyExpression(PropertyExpression pe)`
  Rewrites property expressions that may resolve through static imports.
  `protected Expression`
  `transformVariableExpression(VariableExpression ve)`
  Rewrites variable expressions that resolve to statically imported fields or accessors.
  `void`
  `visitAnnotations(AnnotatedNode node)`
  Marks annotation traversal so imported constants can be inlined safely.
  `void`
  `visitClass(ClassNode classNode, SourceUnit sourceUnit)`
  Deprecated.
  `protected void`
  `visitConstructorOrMethod(MethodNode node, boolean isConstructor)`
  Tracks the current method while transforming static-import references.

  ### Methods inherited from class org.codehaus.groovy.ast.ClassCodeExpressionTransformer

  `setSourcePosition, visitAnnotation, visitAssertStatement, visitCaseStatement, visitClosureExpression, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitProperty, visitReturnStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitWhileLoop`

  ### Methods inherited from class org.codehaus.groovy.ast.ClassCodeVisitorSupport

  `addError, visitAnnotations, visitBlockStatement, visitBreakStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitConstructor, visitContinueStatement, visitDeclarationExpression, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitStatement, visitStatementAnnotations, visitTryCatchFinally`

  ### Methods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport

  `afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBooleanExpression, visitBytecodeExpression, visitCastExpression, visitClassExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitEmptyStatement, visitFieldExpression, visitGStringExpression, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitTernaryExpression, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression`

  ### 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.ast.GroovyCodeVisitor

  `visit, visit, visitEmptyExpression, visitListOfExpressions`

- ## Constructor Details

  - ### StaticImportVisitor

    public StaticImportVisitor(ClassNode classNode, SourceUnit sourceUnit)
    Creates a visitor that rewrites references resolved through static imports.
    Parameters:
      `classNode` - the class currently being transformed
      `sourceUnit` - the source unit containing the class

- ## Method Details

  - ### visitClass

    @Deprecated public void visitClass(ClassNode classNode, SourceUnit sourceUnit)
    Deprecated.
    Call `StaticImportVisitor(ClassNode,SourceUnit)` then `ClassCodeVisitorSupport.visitClass(ClassNode)`.

  - ### visitConstructorOrMethod

    protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor)
    Tracks the current method while transforming static-import references.
    Overrides:
      `visitConstructorOrMethod` in class `ClassCodeExpressionTransformer`
    Parameters:
      `node` - the method or constructor being visited
      `isConstructor` - whether `node` is a constructor

  - ### visitAnnotations

    public void visitAnnotations(AnnotatedNode node)
    Marks annotation traversal so imported constants can be inlined safely.
    Overrides:
      `visitAnnotations` in class `ClassCodeVisitorSupport`
    Parameters:
      `node` - the annotated node whose annotations are being visited

  - ### transform

    public Expression transform(Expression exp)
    Rewrites expressions that may target statically imported members.
    Specified by:
      `transform` in interface `ExpressionTransformer`
    Overrides:
      `transform` in class `ClassCodeExpressionTransformer`
    Parameters:
      `exp` - the expression to transform
    Returns:
      the transformed expression

  - ### transformBinaryExpression

    protected Expression transformBinaryExpression(BinaryExpression be)
    Rewrites binary expressions that may reference statically imported members.
    Parameters:
      `be` - the binary expression to transform
    Returns:
      the transformed expression

  - ### transformVariableExpression

    protected Expression transformVariableExpression(VariableExpression ve)
    Rewrites variable expressions that resolve to statically imported fields or accessors.
    Parameters:
      `ve` - the variable expression to transform
    Returns:
      the transformed expression

  - ### transformMethodCallExpression

    protected Expression transformMethodCallExpression(MethodCallExpression mce)
    Rewrites implicit-this calls that resolve to statically imported methods or properties.
    Parameters:
      `mce` - the method call to transform
    Returns:
      the transformed expression

  - ### transformConstructorCallExpression

    protected Expression transformConstructorCallExpression(ConstructorCallExpression cce)
    Rewrites named-argument constructor calls that use statically imported members.
    Parameters:
      `cce` - the constructor call to transform
    Returns:
      the transformed expression

  - ### transformClosureExpression

    protected Expression transformClosureExpression(ClosureExpression ce)
    Rewrites default parameter expressions inside closures.
    Parameters:
      `ce` - the closure expression to transform
    Returns:
      the transformed expression

  - ### transformPropertyExpression

    protected Expression transformPropertyExpression(PropertyExpression pe)
    Rewrites property expressions that may resolve through static imports.
    Parameters:
      `pe` - the property expression to transform
    Returns:
      the transformed expression

  - ### getSourceUnit

    protected SourceUnit getSourceUnit()
    Returns the source unit currently being transformed.
    Specified by:
      `getSourceUnit` in class `ClassCodeVisitorSupport`
    Returns:
      the active source unit