@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
public class ImmutableASTTransformation
extends AbstractASTTransformation
implements CompilationUnitAware
Handles generation of code for the
| Modifiers | Name | Description |
|---|---|---|
static String |
IMMUTABLE_BREADCRUMB |
Node-metadata key set to Boolean.TRUE on a field whose property was made immutable. |
static ClassNode |
MY_TYPE |
Redirect node for ImmutableBase. |
| Fields inherited from class | Fields |
|---|---|
class AbstractASTTransformation |
RETENTION_CLASSNODE, sourceUnit |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static Object |
checkImmutable(String className, String fieldName, Object field)This method exists to be binary compatible with 1.7 - 1.8.6 compiled code and is since 2.5.0 used by code produced by ImmutablePropertyHandler |
|
public static Object |
checkImmutable(Class<?> clazz, String fieldName, Object field)For compatibility with pre 2.5 compiled classes |
|
public static Object |
checkImmutable(Class<?> clazz, String fieldName, Object field, List<String> knownImmutableFieldNames, List<Class> knownImmutableClasses)Returns field when it may be stored in an immutable object, or a
defensive copy when it is a collection declared as a Collection.
|
|
public static void |
checkPropNames(Object instance, Map<String, Object> args)Called during named-arguments constructor execution to check given names. |
|
public String |
getAnnotationName() |
|
public void |
setCompilationUnit(CompilationUnit unit) |
|
public void |
visit(ASTNode[] nodes, SourceUnit source) |
Node-metadata key set to Boolean.TRUE on a field whose property was
made immutable. @IndexedProperty reads it and skips the generated setter.
Redirect node for ImmutableBase. makeWithoutCaching with
generics omitted builds a fresh node that redirects to the cached class,
so this is not the shared ClassNode.
This method exists to be binary compatible with 1.7 - 1.8.6 compiled code and is since 2.5.0 used by code produced by ImmutablePropertyHandler
For compatibility with pre 2.5 compiled classes
Returns field when it may be stored in an immutable object, or a
defensive copy when it is a collection declared as a Collection.
null, an enum constant, a built-in or marked immutable class, a name
present in knownImmutableFieldNames, and a runtime class present in
knownImmutableClasses are returned as given. So is a runtime class
that carries an annotation whose class name starts with
groovy.transform.Immutable. A Collection whose declared field
type is a Collection is returned as
DefaultGroovyMethods.asImmutable, an unmodifiable copy;
the original collection is not modified. A collection whose declared type is
itself built-in, marked immutable, or listed in knownImmutableClasses
is returned as given. A missing declared field is ignored and the value is
then rejected.
A value that is not accepted as immutable fails with RuntimeException.
clazz - the immutable class that declares fieldNamefieldName - the property or field being assignedfield - the value being assigned; null is accepted and returnedknownImmutableFieldNames - field names that skip the checkknownImmutableClasses - runtime classes, and some declared collection types, that skip the checkfield, or an unmodifiable copy of a declared collectionCalled during named-arguments constructor execution to check given names.