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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionattachTo(Environment env)static @Nullable ChangeCollectorgetChanges(CtElement currentElement)Return the set ofCtRoles for which children have changed from `currentElement` since thisChangeCollectorwas attached Warning: change in IMPLICIT are ignoredgetDirectChanges(CtElement currentElement)protected voidCalled whenever anything changes in the spoon modelstatic voidrunWithoutChangeListener(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:
ChangeCollectorattached 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 toCtModelto 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- theCtElementwhose changes has to be checked- Returns:
- set of
CtRoles in direct children on of `currentElement` where something has changed since thisChangeCollectorwas 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 ofCtRoles for which children have changed from `currentElement` since thisChangeCollectorwas attached Warning: change in IMPLICIT are ignored- Parameters:
currentElement- theCtElementwhose 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
-