Class ImmutableTypes

java.lang.Object
org.apache.groovy.internal.util.ImmutableTypes

public final class ImmutableTypes extends Object
The types and marker annotations Groovy treats as immutable, shared by the @Immutable family of transforms and by the runtime (GROOVY-12390).

Lives outside the AST packages on purpose: GStringImpl consults it for every GString with a non-trivial value, and reaching it through the transform utilities would initialise the compiler's ClassHelper, with its reflective model of the JDK types, in an application that never compiles anything. Internal to the runtime, not a public API.

  • Method Details

    • isBuiltinImmutable

      public static boolean isBuiltinImmutable(String typeName)
      Whether a type name is one of the JDK types Groovy treats as immutable.
      Parameters:
      typeName - the fully qualified type name
      Returns:
      true for a built-in immutable type
    • isImmutableMarker

      public static boolean isImmutableMarker(String annotationName)
      Whether an annotation name marks its target as immutable.
      Parameters:
      annotationName - the fully qualified annotation type name
      Returns:
      true for a recognised immutable marker
    • hasImmutableAnnotation

      public static boolean hasImmutableAnnotation(Class<?> clazz)
      Whether a class carries a recognised immutable marker annotation.
      Parameters:
      clazz - the class to inspect
      Returns:
      true when a marker is present
    • builtinOrMarkedImmutableClass

      public static boolean builtinOrMarkedImmutableClass(Class<?> clazz)
      Whether a class is built in as immutable or carries an immutable marker annotation.
      Parameters:
      clazz - the class to inspect
      Returns:
      true when the class is considered immutable