Package org.apache.groovy.ast.tools
Class ImmutablePropertyUtils
java.lang.Object
org.apache.groovy.ast.tools.ImmutablePropertyUtils
Utility methods for immutable-property analysis and code generation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ClassNodeTheImmutableOptionsannotation type used to configure immutable-property handling. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanbuiltinOrMarkedImmutableClass(Class<?> clazz) Checks whether the supplied class is built in as immutable or carries an immutable marker annotation.static ExpressioncloneArrayOrCloneableExpr(Expression expr, ClassNode type) Creates an expression that clones an array orCloneablevalue and casts it back to the requested type.static ExpressioncloneDateExpr(Expression origDate) Creates an expression that clones aDatevalue.static StringcreateErrorMessage(String className, String fieldName, String typeName, String mode) Creates the standard error message for an unsupported immutable property type.static booleanderivesFromDate(ClassNode fieldType) Checks whether the supplied type derives fromDate.getKnownImmutableClasses(AbstractASTTransformation xform, ClassNode cNode) Extracts configured immutable helper classes fromImmutableOptions.getKnownImmutables(AbstractASTTransformation xform, ClassNode cNode) Extracts configured immutable property names fromImmutableOptions.static booleanimplementsCloneable(ClassNode fieldType) Checks whether the supplied type implementsCloneable.static booleanisBuiltinImmutable(String typeName) Checks whether the supplied type name is one of the built-in immutable types.static booleanisKnownImmutableType(ClassNode fieldType, List<String> knownImmutableClasses) Checks whether the supplied type is acceptable for an immutable property.
-
Field Details
-
IMMUTABLE_OPTIONS_TYPE
TheImmutableOptionsannotation type used to configure immutable-property handling.
-
-
Method Details
-
cloneArrayOrCloneableExpr
Creates an expression that clones an array orCloneablevalue and casts it back to the requested type.- Parameters:
expr- the expression producing the original valuetype- the expected result type- Returns:
- an expression that performs the clone operation
-
implementsCloneable
Checks whether the supplied type implementsCloneable.- Parameters:
fieldType- the type to inspect- Returns:
trueif the type implementsCloneable
-
cloneDateExpr
Creates an expression that clones aDatevalue.- Parameters:
origDate- the date expression to clone- Returns:
- an expression that creates a defensive date copy
-
derivesFromDate
Checks whether the supplied type derives fromDate.- Parameters:
fieldType- the type to inspect- Returns:
trueif the type derives fromDate
-
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 processedfieldName- the property nametypeName- the unsupported type namemode- the operation being performed- Returns:
- the formatted error message
-
isKnownImmutableType
Checks whether the supplied type is acceptable for an immutable property.- Parameters:
fieldType- the type to inspectknownImmutableClasses- additional immutable type names supplied by configuration- Returns:
trueif the type is supported by immutable-property handling
-
isBuiltinImmutable
Checks whether the supplied type name is one of the built-in immutable types.- Parameters:
typeName- the type name to inspect- Returns:
trueif the type is treated as built-in immutable
-
builtinOrMarkedImmutableClass
Checks whether the supplied class is built in as immutable or carries an immutable marker annotation.- Parameters:
clazz- the class to inspect- Returns:
trueif the class is treated as immutable
-
getKnownImmutables
Extracts configured immutable property names fromImmutableOptions.- Parameters:
xform- the transform reporting configuration errorscNode- 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 fromImmutableOptions.- Parameters:
xform- the transform reporting configuration errorscNode- the annotated class node- Returns:
- the configured immutable class names
-