Package spoon.support.modelobs
Class ChangeCollector
java.lang.Object
spoon.support.modelobs.ChangeCollector
- Direct Known Subclasses:
SourceFragmentCreator
Listens on changes on the spoon model and remembers them
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionattachTo(Environment env)
static @Nullable ChangeCollector
getChanges(CtElement currentElement)
Return the set ofCtRole
s for which children have changed from `currentElement` since thisChangeCollector
was attached Warning: change in IMPLICIT are ignoredgetDirectChanges(CtElement currentElement)
protected void
Called whenever anything changes in the spoon modelstatic void
runWithoutChangeListener(Environment env, Runnable runnable)
Allows to run code using change collector switched off.
-
Constructor Details
-
ChangeCollector
public ChangeCollector()
-
-
Method Details
-
getChangeCollector
- Parameters:
env
- to be checkedEnvironment
- Returns:
ChangeCollector
attached to the `env` or null if there is none
-
runWithoutChangeListener
Allows to run code using change collector switched off. It means that any change of spoon model done by the `runnable` is ignored by the change collector. Note: it is actually needed to wrap CtElement#toString() calls which sometime modifies spoon model. See TestSniperPrinter#testPrintChangedReferenceBuilder()- Parameters:
env
- Spoon environmentrunnable
- the code to be run
-
attachTo
Attaches itself toCtModel
to listen to all changes of it's child elements TODO: it would be nicer if we might listen on changes onCtElement
- Parameters:
env
- to be attached toEnvironment
- Returns:
- this to support fluent API
-
getDirectChanges
- Parameters:
currentElement
- theCtElement
whose changes has to be checked- Returns:
- set of
CtRole
s in direct children on of `currentElement` where something has changed since thisChangeCollector
was attached The 'directly' means that value of attribute of `currentElement` was changed. UsegetChanges(CtElement)
to detect changes in child elements too
-
getChanges
Return the set ofCtRole
s for which children have changed from `currentElement` since thisChangeCollector
was attached Warning: change in IMPLICIT are ignored- Parameters:
currentElement
- theCtElement
whose changes has to be checked
-
onChange
Called whenever anything changes in the spoon model- Parameters:
currentElement
- the modified elementrole
- the modified attribute of that element
-