Class ImmutablePropertyUtils

java.lang.Object
org.apache.groovy.ast.tools.ImmutablePropertyUtils

public class ImmutablePropertyUtils extends Object
Utility methods for immutable-property analysis and code generation.
  • Field Details

    • IMMUTABLE_OPTIONS_TYPE

      public static final ClassNode IMMUTABLE_OPTIONS_TYPE
      The ImmutableOptions annotation type used to configure immutable-property handling.
  • Method Details

    • cloneArrayOrCloneableExpr

      public static Expression cloneArrayOrCloneableExpr(Expression expr, ClassNode type)
      Creates an expression that clones an array or Cloneable value and casts it back to the requested type.
      Parameters:
      expr - the expression producing the original value
      type - the expected result type
      Returns:
      an expression that performs the clone operation
    • implementsCloneable

      public static boolean implementsCloneable(ClassNode fieldType)
      Checks whether the supplied type implements Cloneable.
      Parameters:
      fieldType - the type to inspect
      Returns:
      true if the type implements Cloneable
    • cloneDateExpr

      public static Expression cloneDateExpr(Expression origDate)
      Creates an expression that clones a Date value.
      Parameters:
      origDate - the date expression to clone
      Returns:
      an expression that creates a defensive date copy
    • derivesFromDate

      public static boolean derivesFromDate(ClassNode fieldType)
      Checks whether the supplied type derives from Date.
      Parameters:
      fieldType - the type to inspect
      Returns:
      true if the type derives from Date
    • createErrorMessage

      public static String createErrorMessage(String className, String fieldName, String typeName, String mode)
      Creates the standard error message for an unsupported immutable property type.
      Parameters:
      className - the immutable class being processed
      fieldName - the property name
      typeName - the unsupported type name
      mode - the operation being performed
      Returns:
      the formatted error message
    • isKnownImmutableType

      public static boolean isKnownImmutableType(ClassNode fieldType, List<String> knownImmutableClasses)
      Checks whether the supplied type is acceptable for an immutable property.
      Parameters:
      fieldType - the type to inspect
      knownImmutableClasses - additional immutable type names supplied by configuration
      Returns:
      true if the type is supported by immutable-property handling
    • isBuiltinImmutable

      public static boolean isBuiltinImmutable(String typeName)
      Checks whether the supplied type name is one of the built-in immutable types.
      Parameters:
      typeName - the type name to inspect
      Returns:
      true if the type is treated as built-in immutable
    • builtinOrMarkedImmutableClass

      public static boolean builtinOrMarkedImmutableClass(Class<?> clazz)
      Checks whether the supplied class is built in as immutable or carries an immutable marker annotation.
      Parameters:
      clazz - the class to inspect
      Returns:
      true if the class is treated as immutable
    • getKnownImmutables

      public static List<String> getKnownImmutables(AbstractASTTransformation xform, ClassNode cNode)
      Extracts configured immutable property names from ImmutableOptions.
      Parameters:
      xform - the transform reporting configuration errors
      cNode - the annotated class node
      Returns:
      the configured immutable property names
    • getKnownImmutableClasses

      public static List<String> getKnownImmutableClasses(AbstractASTTransformation xform, ClassNode cNode)
      Extracts configured immutable helper classes from ImmutableOptions.
      Parameters:
      xform - the transform reporting configuration errors
      cNode - the annotated class node
      Returns:
      the configured immutable class names