Class OldVariableGenerationUtility
java.lang.Object
org.apache.groovy.contracts.generation.OldVariableGenerationUtility
Central place where code generation for the old closure variable takes place.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSynthetic helper method name used to compute theoldvariable map for postconditions. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddOldVariableMethodNode(ClassNode classNode) Creates a synthetic method handling generation of the old variable map.static ExpressionsnapshotExpression(ClassNode type, Expression value) Returns an expression that snapshotsvalue(of declared typetype) for storage in theoldmap.
-
Field Details
-
OLD_VARIABLES_METHOD
Synthetic helper method name used to compute theoldvariable map for postconditions.- See Also:
-
-
Constructor Details
-
OldVariableGenerationUtility
public OldVariableGenerationUtility()
-
-
Method Details
-
addOldVariableMethodNode
Creates a synthetic method handling generation of the old variable map. If a super class declares the same synthetic method it will be called and the results will be merged.- Parameters:
classNode- which contains postconditions, so an old variable generating method makes sense here.
-
snapshotExpression
Returns an expression that snapshotsvalue(of declared typetype) for storage in theoldmap. The snapshot is only a defensive copy when one is needed and possible:- a value of a known-immutable type (per
ImmutablePropertyUtils: primitives/wrappers,String,BigInteger/BigDecimal, thejava.time.*types, enums,@Immutable/@KnownImmutabletypes, ...) is stored by reference, since it cannot change; - a mutable
Cloneablevalue is defensively copied with a null-safeclone(), so an in-place change in the method body is not also seen throughold; - any other value (e.g. a non-cloneable collection or a user type) cannot be generically copied, so its reference is stored as a best effort.
@Immutablerather than an ad-hoc list.- Parameters:
type- the declared type of the value being snapshottedvalue- the expression producing the value to snapshot- Returns:
- the snapshot expression
- a value of a known-immutable type (per
-