Class RecordBaseASTStubber

java.lang.Object
org.codehaus.groovy.transform.AbstractASTTransformation
org.codehaus.groovy.transform.RecordBaseASTStubber
All Implemented Interfaces:
ASTTransformation, ErrorCollecting

public class RecordBaseASTStubber extends AbstractASTTransformation
Joint-compilation stubber for RecordBase. For emulated records (target < JDK16 or explicit mode = EMULATE) it produces the same Java-callable surface that the runtime transform produces at SEMANTIC_ANALYSIS:
  • Property modifier flips so the stub generator's Verifier sub-pass emits componentName() accessors instead of getComponentName() and skips setter synthesis on the (now-final) properties.
  • Stub placeholders for the Groovy-specific record convenience methods — getAt(int), toList(), toMap(), size(), plus the opt-in copyWith(Map) and components() when enabled via @RecordOptions.

The "should we add this?" predicates are shared with the full transform via package-private statics on RecordTypeASTTransformation, so the stub never exposes a method the runtime won't add (matching the same subset invariant as @Delegate's shared filter helpers).

The canonical constructor on the stub comes transitively from the existing @TupleConstructor stubber, which @RecordType's @AnnotationCollector pulls in.

Native records. When the class would compile as a native JVM record (target >= JDK16 and mode != EMULATE), the stub generator already renders record Foo(...) syntax via the back-channel introduced by GROOVY-11974, and javac synthesises the canonical constructor and component accessors itself. This stubber detects that case via RecordTypeASTTransformation.wouldBeNativeRecord(org.codehaus.groovy.ast.ClassNode, java.lang.String) and bails out; applying property modifier flips or stubbing convenience methods on a native-record AST would interfere with subsequent record-component processing.

Since:
6.0.0
  • Constructor Details

    • RecordBaseASTStubber

      public RecordBaseASTStubber()
  • Method Details

    • visit

      public void visit(ASTNode[] nodes, SourceUnit source)
      Description copied from interface: ASTTransformation
      The method is invoked when an AST Transformation is active. For local transformations, it is invoked once each time the local annotation is encountered. For global transformations, it is invoked once for every source unit, which is typically a source file.
      Parameters:
      nodes - The ASTnodes when the call was triggered. Element 0 is the AnnotationNode that triggered this annotation to be activated. Element 1 is the AnnotatedNode decorated, such as a MethodNode or ClassNode. For global transformations it is usually safe to ignore this parameter.
      source - The source unit being compiled. The source unit may contain several classes. For global transformations, information about the AST can be retrieved from this object.