Class InnerClassVisitorHelper

All Implemented Interfaces:
GroovyClassVisitor, GroovyCodeVisitor, ErrorCollecting
Direct Known Subclasses:
InnerClassCompletionVisitor, InnerClassVisitor

public abstract class InnerClassVisitorHelper extends ClassCodeVisitorSupport
Abstract base class providing helper methods for inner class visitors. This class contains utility methods for generating dispatcher code that allows inner classes to access members of their enclosing classes.
  • Constructor Details

    • InnerClassVisitorHelper

      public InnerClassVisitorHelper()
  • Method Details

    • addFieldInit

      protected static void addFieldInit(Parameter p, FieldNode fn, BlockStatement block)
      Adds a statement to initialize a field from a constructor parameter.
      Parameters:
      p - the parameter to read from
      fn - the field to initialize
      block - the block statement to add the initialization to
    • setPropertyGetterDispatcher

      protected static void setPropertyGetterDispatcher(BlockStatement block, Expression target, Parameter[] parameters)
      Generates property getter dispatcher code for dynamic property access.
      Parameters:
      block - the block to add the dispatcher code to
      target - the target object to get the property from
      parameters - the dispatcher method parameters (property name)
    • setPropertySetterDispatcher

      protected static void setPropertySetterDispatcher(BlockStatement block, Expression target, Parameter[] parameters)
      Generates property setter dispatcher code for dynamic property access.
      Parameters:
      block - the block to add the dispatcher code to
      target - the target object to set the property on
      parameters - the dispatcher method parameters (property name, value)
    • setMethodDispatcherCode

      protected static void setMethodDispatcherCode(BlockStatement block, Expression target, Parameter[] parameters)
      Generates method dispatcher code for dynamic method invocation. Handles both single arguments and spread arguments.
      Parameters:
      block - the block to add the dispatcher code to
      target - the target object to invoke methods on
      parameters - the dispatcher method parameters (method name, arguments)
    • getClassNode

      protected static ClassNode getClassNode(ClassNode cn, boolean isStatic)
      Returns the class node to expose when wiring dispatch methods for an inner class.
      Parameters:
      cn - the enclosing class node
      isStatic - whether the generated access is static
      Returns:
      the effective dispatch receiver type
    • getObjectDistance

      protected static int getObjectDistance(ClassNode cn)
      Calculates the inheritance distance from the supplied type to Object.
      Parameters:
      cn - the class node to measure
      Returns:
      the number of superclass hops to Object
    • isStatic

      protected static boolean isStatic(InnerClassNode cn)
      Determines whether the supplied inner class behaves as a static nested class.
      Parameters:
      cn - the inner class node to test
      Returns:
      true if no outer-instance field is required
    • shouldHandleImplicitThisForInnerClass

      protected static boolean shouldHandleImplicitThisForInnerClass(ClassNode cn)
      Determines whether synthetic outer-instance handling should be applied to the inner class.
      Parameters:
      cn - the class node to test
      Returns:
      true if implicit this$0 handling is required