Package: org.codehaus.groovy.classgen

## [Java] Class Verifier

- org.codehaus.groovy.classgen.Verifier

- All Implemented Interfaces and Traits:
    GroovyClassVisitor, org.objectweb.asm.Opcodes

      public class Verifier
      extends Object
      implements GroovyClassVisitor, org.objectweb.asm.Opcodes

  Verifies the AST node and adds any default AST code before bytecode generation occurs.

  Checks include:

  - Methods with duplicate signatures
  - Duplicate interfaces
  - Reassigned final variables/parameters
  - Uninitialized variables
  - Bad code in object initializers or constructors
  - Mismatches in modifiers or return types between implementations and interfaces/abstract classes
  - Invalid record component names
  Added code includes:
  - Methods needed to implement GroovyObject
  - Property accessor methods
  - Covariant methods
  - Additional methods/constructors as needed for default parameters

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `interface` | `Verifier.DefaultArgsAction` | Strategy invoked for each synthetic method or constructor generated for default arguments.

  - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static String` | `DEFAULT_PARAMETER_GENERATED` | Metadata key marking methods generated to support default arguments.
    `static String` | `INITIAL_EXPRESSION` | Metadata key used to retain a property's original initializer expression.
    `static String` | `STATIC_METACLASS_BOOL` | Synthetic field name used to cache static metaclass initialization checks.
    `static String` | `SWAP_INIT` | Metadata key used when swapping initializer statements during verification.
    `static String` | `__TIMESTAMP` | Synthetic timestamp field used for backwards-compatible script metadata.
    `static String` | `__TIMESTAMP__` | Alternate synthetic timestamp field retained for binary compatibility.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected void` | `addClosureCode(InnerClassNode node)` Adds the synthetic support code required by a generated closure class.
    `` | `protected void` | `addConstructor(Parameter[] newParams, ConstructorNode ctor, Statement code, ClassNode type)` Adds a synthetic constructor variant for default arguments.
    `` | `protected void` | `addCovariantMethods(ClassNode classNode)` Adds bridge methods needed to support covariant overrides.
    `` | `protected void` | `addDefaultConstructor(ClassNode node)` Adds a synthetic no-arg constructor when the class requires one.
    `` | `protected void` | `addDefaultParameterConstructors(ClassNode type)` Creates a new constructor for each combination of default parameter expressions.
    `` | `protected void` | `addDefaultParameterMethods(ClassNode type)` Creates a new method for each combination of default parameter expressions.
    `` | `protected void` | `addDefaultParameters(List<? extends MethodNode> methods, Verifier.DefaultArgsAction action)` Creates a new helper method for each combination of default parameter expressions.
    `` | `protected void` | `addDefaultParameters(Verifier.DefaultArgsAction action, MethodNode method)` Applies default-argument generation to a single method or constructor.
    `` | `protected void` | `addFieldInitialization(List list, List staticList, FieldNode fieldNode, boolean isEnumClassNode, List initStmtsAfterEnumValuesInit, Set explicitStaticPropsInEnum)` Routes a field initializer into the appropriate instance or static initialization block.
    `` | `protected void` | `addGroovyObjectInterfaceAndMethods(ClassNode node, String classInternalName)` Adds the `GroovyObject` contract and supporting methods when needed.
    `` | `protected void` | `addInitialization(ClassNode node)` Adds object and static initializer wiring for the supplied class.
    `` | `protected void` | `addInitialization(ClassNode node, ConstructorNode constructorNode)` Adds initializer statements to the supplied constructor context.
    `` | `protected MethodNode` | `addMethod(ClassNode node, boolean shouldBeSynthetic, String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code)` Helper method to add a new method to a ClassNode.
    `` | `protected void` | `addPropertyMethod(MethodNode method)` Registers a generated property accessor or mutator with the current class.
    `` | `protected void` | `addReturnIfNeeded(MethodNode node)` Ensures the supplied method has an explicit return statement when required.
    `` | `protected void` | `addTimeStamp(ClassNode node)` Adds legacy synthetic timestamp fields for scripts and generated classes.
    `` | `public static String` | `capitalize(String name)` Capitalizes the start of the given bean property name.
    `` | `protected Statement` | `createGetterBlock(PropertyNode propertyNode, FieldNode field)` Creates the bytecode-backed statement block for a generated property getter.
    `` | `protected Statement` | `createSetterBlock(PropertyNode propertyNode, FieldNode field)` Creates the bytecode-backed statement block for a generated property setter.
    `` | `public ClassNode` | `getClassNode()` Returns the class node currently being verified.
    `` | `protected VariableNotFinalCallback` | `getFinalVariablesCallback()` Creates the callback used when final-variable analysis finds invalid assignments.
    `` | `public MethodNode` | `getMethodNode()` Returns the method node currently being verified.
    `` | `public static long` | `getTimestamp(Class<?> clazz)` Looks up the synthetic timestamp stored on a generated class.
    `` | `public static Long` | `getTimestampFromFieldName(String fieldName)` Extracts a timestamp value from a synthetic timestamp field name.
    `` | `protected void` | `setClassNode(ClassNode classNode)` Sets the class node to be verified.
    `` | `public static ConstantExpression` | `transformToPrimitiveConstantIfPossible(ConstantExpression constantExpression)` When constant expressions are created, the value is always wrapped to a non-primitive type.
    `` | `public void` | `visitClass(ClassNode node)` * Visit a ClassNode.
    `` | `public void` | `visitConstructor(ConstructorNode node)` * Visit a ConstructorNode.
    `` | `public void` | `visitField(FieldNode node)` * Visit a FieldNode.
    `` | `public void` | `visitGenericType(GenericsType genericsType)` Extension point invoked when traversing a generic type; the default implementation does nothing.
    `` | `public void` | `visitMethod(MethodNode node)` * Visit a MethodNode.
    `` | `public void` | `visitProperty(PropertyNode node)` * Visit a PropertyNode.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### public static final String DEFAULT_PARAMETER_GENERATED

      Metadata key marking methods generated to support default arguments.

    - #### public static final String INITIAL_EXPRESSION

      Metadata key used to retain a property's original initializer expression.

    - #### public static final String STATIC_METACLASS_BOOL

      Synthetic field name used to cache static metaclass initialization checks.

    - #### public static final String SWAP_INIT

      Metadata key used when swapping initializer statements during verification.

    - #### public static final String __TIMESTAMP

      Synthetic timestamp field used for backwards-compatible script metadata.

    - #### public static final String __TIMESTAMP__

      Alternate synthetic timestamp field retained for binary compatibility.

  - ### Method Detail

    - #### protected void addClosureCode(InnerClassNode node)

      Adds the synthetic support code required by a generated closure class.

      Parameters:
        `node` - the closure class node

    - #### protected void addConstructor(Parameter[] newParams, ConstructorNode ctor, Statement code, ClassNode type)

      Adds a synthetic constructor variant for default arguments.

      Parameters:
        `newParams` - the parameters of the generated constructor
        `ctor` - the source constructor
        `code` - the generated constructor body
        `type` - the declaring type

    - #### protected void addCovariantMethods(ClassNode classNode)

      Adds bridge methods needed to support covariant overrides.

      Parameters:
        `classNode` - the class being enhanced

    - #### protected void addDefaultConstructor(ClassNode node)

      Adds a synthetic no-arg constructor when the class requires one.

      Parameters:
        `node` - the class being verified

    - #### protected void addDefaultParameterConstructors(ClassNode type)

      Creates a new constructor for each combination of default parameter expressions.

    - #### protected void addDefaultParameterMethods(ClassNode type)

      Creates a new method for each combination of default parameter expressions.

    - #### protected void addDefaultParameters(List<? extends MethodNode> methods, Verifier.DefaultArgsAction action)

      Creates a new helper method for each combination of default parameter expressions.

    - #### protected void addDefaultParameters(Verifier.DefaultArgsAction action, MethodNode method)

      Applies default-argument generation to a single method or constructor.

      Parameters:
        `action` - the generation strategy
        `method` - the method or constructor to expand

    - #### protected void addFieldInitialization(List list, List staticList, FieldNode fieldNode, boolean isEnumClassNode, List initStmtsAfterEnumValuesInit, Set explicitStaticPropsInEnum)

      Routes a field initializer into the appropriate instance or static initialization block.

      Parameters:
        `list` - the instance-initializer statements
        `staticList` - the static-initializer statements
        `fieldNode` - the field whose initializer is being processed
        `isEnumClassNode` - whether the declaring class is an enum
        `initStmtsAfterEnumValuesInit` - enum statements that must run after constant initialization
        `explicitStaticPropsInEnum` - explicitly declared static enum properties

    - #### protected void addGroovyObjectInterfaceAndMethods(ClassNode node, String classInternalName)

      Adds the `GroovyObject` contract and supporting methods when needed.

      Parameters:
        `node` - the class being enhanced
        `classInternalName` - the internal JVM name of the class

    - #### protected void addInitialization(ClassNode node)

      Adds object and static initializer wiring for the supplied class.

      Parameters:
        `node` - the class being enhanced

    - #### protected void addInitialization(ClassNode node, ConstructorNode constructorNode)

      Adds initializer statements to the supplied constructor context.

      Parameters:
        `node` - the class being enhanced
        `constructorNode` - the constructor receiving initialization code

    - #### protected MethodNode addMethod(ClassNode node, boolean shouldBeSynthetic, String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code)

      Helper method to add a new method to a ClassNode. Depending on the shouldBeSynthetic flag the call will either be made to ClassNode.addSyntheticMethod() or ClassNode.addMethod(). If a non-synthetic method is to be added the ACC_SYNTHETIC modifier is removed if it has been accidentally supplied.

    - #### protected void addPropertyMethod(MethodNode method)

      Registers a generated property accessor or mutator with the current class.

      Parameters:
        `method` - the generated property method

    - #### protected void addReturnIfNeeded(MethodNode node)

      Ensures the supplied method has an explicit return statement when required.

      Parameters:
        `node` - the method to normalize

    - #### @Deprecated(since = "2.4.0")
      protected void addTimeStamp(ClassNode node)

      Adds legacy synthetic timestamp fields for scripts and generated classes.

      Parameters:
        `node` - the class being enhanced

    - #### public static String capitalize(String name)

      Capitalizes the start of the given bean property name.

    - #### protected Statement createGetterBlock(PropertyNode propertyNode, FieldNode field)

      Creates the bytecode-backed statement block for a generated property getter.

      Parameters:
        `propertyNode` - the property being served
        `field` - the backing field
      Returns:
        the generated getter body

    - #### protected Statement createSetterBlock(PropertyNode propertyNode, FieldNode field)

      Creates the bytecode-backed statement block for a generated property setter.

      Parameters:
        `propertyNode` - the property being updated
        `field` - the backing field
      Returns:
        the generated setter body

    - #### public ClassNode getClassNode()

      Returns the class node currently being verified.

      Returns:
        the current class node

    - #### protected VariableNotFinalCallback getFinalVariablesCallback()

      Creates the callback used when final-variable analysis finds invalid assignments.

      Returns:
        the callback passed to FinalVariableAnalyzer

    - #### public MethodNode getMethodNode()

      Returns the method node currently being verified.

      Returns:
        the current method node

    - #### public static long getTimestamp(Class<?> clazz)

      Looks up the synthetic timestamp stored on a generated class.

      Parameters:
        `clazz` - the generated class to inspect
      Returns:
        the stored timestamp, or `Long.MAX_VALUE` if none is available

    - #### public static Long getTimestampFromFieldName(String fieldName)

      Extracts a timestamp value from a synthetic timestamp field name.

      Parameters:
        `fieldName` - the field name to inspect
      Returns:
        the parsed timestamp, or `null` if the name is not a timestamp field

    - #### protected void setClassNode(ClassNode classNode)

      Sets the class node to be verified.

      Parameters:
        `classNode` - the class node to verify

    - #### public static ConstantExpression transformToPrimitiveConstantIfPossible(ConstantExpression constantExpression)

      When constant expressions are created, the value is always wrapped to a non-primitive type. Some constant expressions are optimized to return primitive types, but not all primitives are handled. This method guarantees to return a similar constant expression but with a primitive type instead of a boxed type.

      Additionally, single char strings are converted to 'char' types.
      Parameters:
        `constantExpression` - a constant expression
      Returns:
        the same instance of constant expression if the type is already primitive, or a primitive constant if possible.

    - #### public void visitClass(ClassNode node)

      * Visit a ClassNode.

    - #### public void visitConstructor(ConstructorNode node)

      * Visit a ConstructorNode.

    - #### public void visitField(FieldNode node)

      * Visit a FieldNode.

    - #### public void visitGenericType(GenericsType genericsType)

      Extension point invoked when traversing a generic type; the default implementation does nothing.

    - #### public void visitMethod(MethodNode node)

      * Visit a MethodNode.

    - #### public void visitProperty(PropertyNode node)

      * Visit a PropertyNode.