Class Verifier

java.lang.Object
org.codehaus.groovy.classgen.Verifier
All Implemented Interfaces:
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
  • MethodHandles.Lookup getter
  • Field Details

  • Constructor Details

    • Verifier

      public Verifier()
  • Method Details

    • getClassNode

      public ClassNode getClassNode()
    • setClassNode

      protected void setClassNode(ClassNode classNode)
    • getMethodNode

      public MethodNode getMethodNode()
    • visitClass

      public void visitClass(ClassNode node)
      Description copied from interface: GroovyClassVisitor
      Visit a ClassNode.
      Specified by:
      visitClass in interface GroovyClassVisitor
    • getFinalVariablesCallback

      protected FinalVariableAnalyzer.VariableNotFinalCallback getFinalVariablesCallback()
    • addDefaultConstructor

      protected void addDefaultConstructor(ClassNode node)
    • addGroovyObjectInterfaceAndMethods

      protected void addGroovyObjectInterfaceAndMethods(ClassNode node, String classInternalName)
    • addMethod

      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.
    • addMethod$$bridge

      protected void addMethod$$bridge(ClassNode node, boolean shouldBeSynthetic, String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code)
    • addTimeStamp

      @Deprecated protected void addTimeStamp(ClassNode node)
      Deprecated.
    • visitConstructor

      public void visitConstructor(ConstructorNode node)
      Description copied from interface: GroovyClassVisitor
      Visit a ConstructorNode.
      Specified by:
      visitConstructor in interface GroovyClassVisitor
    • visitMethod

      public void visitMethod(MethodNode node)
      Description copied from interface: GroovyClassVisitor
      Visit a MethodNode.
      Specified by:
      visitMethod in interface GroovyClassVisitor
    • addReturnIfNeeded

      protected void addReturnIfNeeded(MethodNode node)
    • visitField

      public void visitField(FieldNode node)
      Description copied from interface: GroovyClassVisitor
      Visit a FieldNode.
      Specified by:
      visitField in interface GroovyClassVisitor
    • visitProperty

      public void visitProperty(PropertyNode node)
      Description copied from interface: GroovyClassVisitor
      Visit a PropertyNode.
      Specified by:
      visitProperty in interface GroovyClassVisitor
    • addPropertyMethod

      protected void addPropertyMethod(MethodNode method)
    • addDefaultParameterMethods

      protected void addDefaultParameterMethods(ClassNode type)
      Creates a new method for each combination of default parameter expressions.
    • addDefaultParameterConstructors

      protected void addDefaultParameterConstructors(ClassNode type)
      Creates a new constructor for each combination of default parameter expressions.
    • addConstructor

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

      protected void addDefaultParameters(List<? extends MethodNode> methods, Verifier.DefaultArgsAction action)
      Creates a new helper method for each combination of default parameter expressions.
    • addDefaultParameters

      protected void addDefaultParameters(Verifier.DefaultArgsAction action, MethodNode method)
    • addClosureCode

      protected void addClosureCode(InnerClassNode node)
    • addInitialization

      protected void addInitialization(ClassNode node)
    • addInitialization

      protected void addInitialization(ClassNode node, ConstructorNode constructorNode)
    • addFieldInitialization

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

      public static String capitalize(String name)
      Capitalizes the start of the given bean property name.
    • createGetterBlock

      protected Statement createGetterBlock(PropertyNode propertyNode, FieldNode field)
    • createSetterBlock

      protected Statement createSetterBlock(PropertyNode propertyNode, FieldNode field)
    • visitGenericType

      public void visitGenericType(GenericsType genericsType)
    • getTimestampFromFieldName

      public static Long getTimestampFromFieldName(String fieldName)
    • getTimestamp

      public static long getTimestamp(Class<?> clazz)
    • addCovariantMethods

      protected void addCovariantMethods(ClassNode classNode)
    • transformToPrimitiveConstantIfPossible

      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.