Package: org.codehaus.groovy.classgen.asm

## [Java] Class PeepholeOptimizingClassVisitor

- org.codehaus.groovy.classgen.asm.PeepholeOptimizingClassVisitor

-     public final class PeepholeOptimizingClassVisitor
      extends org.objectweb.asm.ClassVisitor

  Class-level installation point for Groovy's single-pass bytecode peephole layer.

  Wraps each org.objectweb.asm.MethodVisitor returned by the delegate's visitMethod(int, String, String, String, String[]) with PeepholeOptimizingMethodVisitor, so every method body receives the same stack-local compaction — user methods, constructors, static initializers, and synthetic helpers alike (MOP bridges, call-site array initializers, `class$`/`$get$` resolvers, large-list init chunks, and so on).

  Centralizing the wrap here avoids ad-hoc `new PeepholeOptimizingMethodVisitor(...)` at individual emission sites and keeps compaction in lockstep with OperandStack, which emits integer and other primitive constants via `visitLdcInsn` and relies on the peephole visitor to narrow them to `ICONST_*`, `BIPUSH`, `SIPUSH`, etc.

  Installed once by WriterController when the class visitor chain is built (optionally outside a `LoggableClassVisitor` / `TraceClassVisitor` pair used for classgen logging). Field and attribute visits are left unchanged; only method bodies are optimized.

  See Also:
    PeepholeOptimizingMethodVisitor
    WriterController
  Since:
    6.0.0

- - ### Constructor Summary

    Constructors
    Constructor and description
    `PeepholeOptimizingClassVisitor(org.objectweb.asm.ClassVisitor classVisitor)` Creates a visitor that peephole-optimizes every method written to `classVisitor`.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public org.objectweb.asm.MethodVisitor` | `visitMethod(int access, String name, String descriptor, String signature, String[] exceptions)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class org.objectweb.asm.ClassVisitor` | `org.objectweb.asm.ClassVisitor#equals(java.lang.Object), org.objectweb.asm.ClassVisitor#getClass(), org.objectweb.asm.ClassVisitor#getDelegate(), org.objectweb.asm.ClassVisitor#hashCode(), org.objectweb.asm.ClassVisitor#notify(), org.objectweb.asm.ClassVisitor#notifyAll(), org.objectweb.asm.ClassVisitor#toString(), org.objectweb.asm.ClassVisitor#visit(int, int, java.lang.String, java.lang.String, java.lang.String, [Ljava.lang.String;), org.objectweb.asm.ClassVisitor#visitAnnotation(java.lang.String, boolean), org.objectweb.asm.ClassVisitor#visitAttribute(org.objectweb.asm.Attribute), org.objectweb.asm.ClassVisitor#visitEnd(), org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object), org.objectweb.asm.ClassVisitor#visitInnerClass(java.lang.String, java.lang.String, java.lang.String, int), org.objectweb.asm.ClassVisitor#visitMethod(int, java.lang.String, java.lang.String, java.lang.String, [Ljava.lang.String;), org.objectweb.asm.ClassVisitor#visitModule(java.lang.String, int, java.lang.String), org.objectweb.asm.ClassVisitor#visitNestHost(java.lang.String), org.objectweb.asm.ClassVisitor#visitNestMember(java.lang.String), org.objectweb.asm.ClassVisitor#visitOuterClass(java.lang.String, java.lang.String, java.lang.String), org.objectweb.asm.ClassVisitor#visitPermittedSubclass(java.lang.String), org.objectweb.asm.ClassVisitor#visitRecordComponent(java.lang.String, java.lang.String, java.lang.String), org.objectweb.asm.ClassVisitor#visitSource(java.lang.String, java.lang.String), org.objectweb.asm.ClassVisitor#visitTypeAnnotation(int, org.objectweb.asm.TypePath, java.lang.String, boolean), org.objectweb.asm.ClassVisitor#wait(), org.objectweb.asm.ClassVisitor#wait(long), org.objectweb.asm.ClassVisitor#wait(long, int)`

- - ### Constructor Detail

    - #### public PeepholeOptimizingClassVisitor(org.objectweb.asm.ClassVisitor classVisitor)

      Creates a visitor that peephole-optimizes every method written to `classVisitor`.

      Parameters:
        `classVisitor` - the next visitor in the class-generation chain (typically a org.objectweb.asm.ClassWriter, optionally preceded by logging / tracing adapters)

  - ### Method Detail

    - #### public org.objectweb.asm.MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions)

      When the delegate returns a non-`null` visitor, the result is a PeepholeOptimizingMethodVisitor (or the same instance if the delegate already wrapped the method). A `null` from the delegate is propagated unchanged so methods can still be skipped per the ASM contract.