Class 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
    Added code includes:
    • Methods needed to implement GroovyObject
    • Property accessor methods
    • Covariant methods
    • Additional methods/constructors as needed for default parameters
    • Constructor Detail

      • Verifier

        public Verifier()
    • Method Detail

      • getClassNode

        public ClassNode getClassNode()
      • setClassNode

        protected void setClassNode​(ClassNode classNode)
      • getMethodNode

        public MethodNode getMethodNode()
      • 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.
      • addReturnIfNeeded

        protected void addReturnIfNeeded​(MethodNode node)
      • addPropertyMethod

        protected void addPropertyMethod​(MethodNode method)
      • addDefaultParameterMethods

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

        protected void addDefaultParameterConstructors​(ClassNode node)
        Creates a new constructor for each combination of default parameter expressions.
      • addDefaultParameters

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

        protected void addClosureCode​(InnerClassNode node)
      • addInitialization

        protected void addInitialization​(ClassNode node)
      • 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.
      • 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.