Class Rewriting.Context
-
Method Summary
Modifier and TypeMethodDescriptionvoidEnforces that the current original object is replaced during rewriting, regardless of whether its neighborhood has changed.Returns the static environment of this rewriting process.longReturns the number of steps performed so far by this rewriting process.booleanChecks whether this rewriting process is currently inclined to create a new result object rather than share an original.popCycleEntry(O original, @Opt A argument) Forgets an object as the entry point of a cycle.voidCompletes the local rewriting process for the neighborhood of an object, and discards the result.popNeighborhood(Supplier<O> newResult) Completes the local rewriting process for the neighborhood of an object, and returns the result.voidpushCycleEntry(O original, @Opt A argument, O result) Records an object as the entry point of a cycle.voidpushNeighborhood(O original) Starts the local rewriting process for the neighborhood of an object.Rewrites an object and its neighbors recursively.rewriteOrNull(@Opt O original, @Opt A argument) Rewrites an object and its neighbors recursively, or leaves anullreference unchanged.
-
Method Details
-
getEnvironment
Returns the static environment of this rewriting process.This is the data that is available for all steps of the process.
- Returns:
- the static environment of this rewriting process, or
nullif not applicable
-
getStepCounter
public long getStepCounter()Returns the number of steps performed so far by this rewriting process.- Returns:
- the number of steps performed so far by this rewriting process
-
isChanged
public boolean isChanged()Checks whether this rewriting process is currently inclined to create a new result object rather than share an original.- Returns:
trueif eithershareOriginalsis set tofalse, subobjects in the current neighborhood have been replaced, orforceReplacement()has been called in the current neighborhood;falseotherwise
-
pushCycleEntry
Records an object as the entry point of a cycle.This method should be invoked at the beginning of a rewriting step for a potential cycle entry point. It requires a new, preliminary result object to have been created already. Initialization of its neighborhood references can be deferred.
An invocation of this method must be balanced with a later invocation of
popCycleEntry(O, A). Otherwise, behavior is unspecified.An object may not be simultaneously recorded as the entry point of several equivalent (same-argument) cycles.
- Parameters:
original- the original object to rewriteargument- the dynamic argument to the rewriting, ornullif not applicableresult- the new preliminary result, with some neighbor references still uninitialized- Throws:
IllegalStateException- if an equivalent cycle is already recorded- See Also:
-
popCycleEntry
Forgets an object as the entry point of a cycle.This method should be invoked at the end of a rewriting step for a potential cycle entry point, after the preliminary result has been initialized completely by recursive rewriting.
An invocation of this method must be balanced with an earlier invocation of
pushCycleEntry(O, A, O). Otherwise, behavior is unspecified.- Parameters:
original- the original object to rewriteargument- the dynamic argument to the rewriting, ornullif not applicable- Returns:
- the recorded result
- Throws:
IllegalStateException- if no such cycle is recorded- See Also:
-
rewrite
Rewrites an object and its neighbors recursively.- If the original object is the recorded entry point of a cycle, a reference to the associated preliminary result is returned.
- Otherwise, if internal sharing is enabled, and the original object has been rewritten with the same argument before, a reference to the cached result is returned.
- Otherwise, the step function of this rewriting process is invoked to compute a result.
If the sharing of original objects in the result is enabled, and this method returns an object that is distinct from the original, it is recorded that the current neighborhood has changed, and hence that the parent original may not be shared.
- Parameters:
original- the original object to rewriteargument- the dynamic argument to the rewriting, ornullif not applicable- Returns:
- the rewritten result; either a back-reference to a cycle entry, or a shared reference to the original, or a newly computed object
-
rewriteOrNull
Rewrites an object and its neighbors recursively, or leaves anullreference unchanged.- Parameters:
original- the original object to rewrite, ornullargument- the dynamic argument to the rewriting, ornullif not applicable- Returns:
- the result of
rewrite(original, argument), ornull, respectively
-
pushNeighborhood
Starts the local rewriting process for the neighborhood of an object.An invocation of this method must be balanced with a later invocation of either
popNeighborhood(Supplier)orpopNeighborhood(). Otherwise, behavior is unspecified.- Parameters:
original- the original object to rewrite
-
popNeighborhood
Completes the local rewriting process for the neighborhood of an object, and returns the result.An invocation of this method must be balanced with an earlier invocation of
pushNeighborhood(O). Otherwise, behavior is unspecified.This method either returns the original object recorded with the corresponding invocation of
pushNeighborhood(O), or uses the given supplier for a new result:- If some recursive
rewritehas returned a result that is different from the respective original, orforceReplacement()has been called, then the supplier is used. - Otherwise, the original is returned.
Note that this change tracking is local: recursive sub-neighborhoods, with their own pair of
push--popoperations, do not interfere.- Parameters:
newResult- a supplier to use if the result has not been pre-recorded- Returns:
- the rewriting result; either the original object if no changes
have been detected, or otherwise supplied by
newResult - Throws:
NullPointerException- ifnewResultis null
- If some recursive
-
popNeighborhood
public void popNeighborhood()Completes the local rewriting process for the neighborhood of an object, and discards the result.An invocation of this method must be balanced with an earlier invocation of
pushNeighborhood(O). Otherwise, behavior is unspecified. -
forceReplacement
public void forceReplacement()Enforces that the current original object is replaced during rewriting, regardless of whether its neighborhood has changed.This method should be invoked between balanced invocations of
pushNeighborhood(O)andpopNeighborhood(Supplier)to enforce the creation of a new, unshared result.
-