Class ChangeCollector

Direct Known Subclasses:

public class ChangeCollector extends Object
Listens on changes on the spoon model and remembers them
  • Constructor Details

    • ChangeCollector

      public ChangeCollector()
  • Method Details

    • getChangeCollector

      public static @Nullable ChangeCollector getChangeCollector(Environment env)
      env - to be checked Environment
      ChangeCollector attached to the `env` or null if there is none
    • runWithoutChangeListener

      public static void runWithoutChangeListener(Environment env, Runnable runnable)
      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()
      env - Spoon environment
      runnable - the code to be run
    • attachTo

      public ChangeCollector attachTo(Environment env)
      Attaches itself to CtModel to listen to all changes of it's child elements TODO: it would be nicer if we might listen on changes on CtElement
      env - to be attached to Environment
      this to support fluent API
    • getDirectChanges

      public Set<CtRole> getDirectChanges(CtElement currentElement)
      currentElement - the CtElement whose changes has to be checked
      set of CtRoles in direct children on of `currentElement` where something has changed since this ChangeCollector was attached The 'directly' means that value of attribute of `currentElement` was changed. Use getChanges(CtElement) to detect changes in child elements too
    • getChanges

      public Set<CtRole> getChanges(CtElement currentElement)
      Return the set of CtRoles for which children have changed from `currentElement` since this ChangeCollector was attached Warning: change in IMPLICIT are ignored
      currentElement - the CtElement whose changes has to be checked
    • onChange

      protected void onChange(CtElement currentElement, CtRole role)
      Called whenever anything changes in the spoon model
      currentElement - the modified element
      role - the modified attribute of that element