Class StaticImportVisitor

All Implemented Interfaces:
ExpressionTransformer, GroovyClassVisitor, GroovyCodeVisitor, ErrorCollecting

public class StaticImportVisitor extends ClassCodeExpressionTransformer
Visitor to resolve constants and method calls from static imports.
  • 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.
    • 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