Class StaticTypesClosureWriter

java.lang.Object
org.codehaus.groovy.classgen.asm.ClosureWriter
org.codehaus.groovy.classgen.asm.sc.StaticTypesClosureWriter

public class StaticTypesClosureWriter extends ClosureWriter
Writer responsible for generating closure classes in statically compiled mode.
  • Constructor Details

    • StaticTypesClosureWriter

      public StaticTypesClosureWriter(WriterController wc)
      Creates a closure writer for statically compiled code generation.
  • Method Details

    • isPackTriggered

      protected boolean isPackTriggered(ClosureExpression expression, boolean annotated)
      Description copied from class: ClosureWriter
      Whether a packable, non-escaping closure literal should actually be packed. Dynamic compilation has no proof of delegate-independence, so the only trigger is the @PackedClosures trust assertion; StaticTypesClosureWriter overrides this to add the groovy.target.closure.pack flag and the delegate-independence proof.
      Overrides:
      isPackTriggered in class ClosureWriter
      annotated - whether a non-DISABLED @PackedClosures is in scope
    • triggerDeclineReason

      protected String triggerDeclineReason(ClosureExpression expression)
      Description copied from class: ClosureWriter
      A trigger-specific decline reason for ClosureWriter.declineReason(org.codehaus.groovy.ast.expr.ClosureExpression), or null if the trigger did not decline this closure. The dynamic path trusts the annotation except for a body that calls a method on a closure object; the static writer overrides this for a delegate-resolved body.
      Overrides:
      triggerDeclineReason in class ClosureWriter
    • readOnlyCaptureType

      protected ClassNode readOnlyCaptureType(String name, ClassNode declaredType, Variable variable)
      Description copied from class: ClosureWriter
      The declared type of a read-only (by-value) capture parameter on the hoisted method. The dynamic writer types it as Object; the static writer overrides this to the capture's declared/flow-inferred type so the body compiles with static dispatch. This is the seam that keeps @CompileStatic-specific typing out of the general (dynamic) emitter.
      Overrides:
      readOnlyCaptureType in class ClosureWriter
    • markHoistedBody

      protected void markHoistedBody(MethodNode hoisted)
      Description copied from class: ClosureWriter
      Marks the hoisted body's compilation mode; the static writer overrides this to compile it statically.
      Overrides:
      markHoistedBody in class ClosureWriter
    • packedClosureUsesDelegateGuard

      protected boolean packedClosureUsesDelegateGuard()
      Description copied from class: ClosureWriter
      Whether the packed adapter installs the runtime delegate guard. The dynamic trust path needs it (an unverifiable assertion must fail fast on misuse); the static writer proved independence, so it overrides this to false and a caller-set delegate is then stored and ignored.
      Overrides:
      packedClosureUsesDelegateGuard in class ClosureWriter
    • hoistedBodyUsesReceiver

      protected boolean hoistedBodyUsesReceiver(ClosureExpression expression)
      Whether the body, nested closures included, uses its this object: this, an instance field or property, an implicit-this call of an instance method, or the creation of an inner class instance, which passes this as its enclosing instance (an instance of a static nested class takes none). A closure class casts getThisObject() to the enclosing class for these, except for the methods of Object, which it calls on the uncast this object; those count too, as the hoisted body can only call them on an instance of the enclosing class. Static members and extension methods (the println family) do not count.
      Overrides:
      hoistedBodyUsesReceiver in class ClosureWriter
    • createClosureClass

      protected ClassNode createClosureClass(ClosureExpression expression, int mods)
      Creates a new inner class node representing the compiled form of a closure expression.
      Overrides:
      createClosureClass in class ClosureWriter
      Parameters:
      expression - the closure expression to compile
      mods - the access modifiers for the generated class
      Returns:
      the newly created closure class node