RECODER 0.92

recoder.service
Class ChangeHistory

java.lang.Object
  extended by recoder.AbstractService
      extended by recoder.service.ChangeHistory
All Implemented Interfaces:
Service

public class ChangeHistory
extends AbstractService

Keeps records on the syntactical changes that occured after the last validation of the model. All transformations should inform this instance of their changes that are visible to the model. In addition, the change history allows to define top-level transformation sequences and perform rollbacks on these.

Since:
0.5
Author:
AL, RN

Field Summary
 
Fields inherited from class recoder.AbstractService
serviceConfiguration
 
Constructor Summary
ChangeHistory(ServiceConfiguration config)
          Creates a new change history for the given configuration.
 
Method Summary
 void addChangeHistoryListener(ChangeHistoryListener chl)
          Adds a change history listener to the history.
 void addModelUpdateListener(ModelUpdateListener l)
          Adds a model update listener to the history.
 void attached(ProgramElement root)
          Informs the change history of the addition of a new subtree given by its root element.
 void begin(Transformation transformation)
          Reports the start of a new transformation.
 void commit()
          Flushes all transformation sequences making them irreversible.
 void detached(ProgramElement root, int pos)
          Informs the change history of the deletion of a subtree given by its root element.
 void detached(ProgramElement root, NonTerminalProgramElement parent, int pos)
          Informs the change history of the deletion of a subtree given by its root element.
 boolean isReported(Transformation transformation)
          Checks if the given transformation is reported in this history and can be rolled back.
 boolean needsUpdate()
          Checks if there are changes in the change queue.
 void removeChangeHistoryListener(ChangeHistoryListener chl)
          Removes a change history listener from the history.
 void removeModelUpdateListener(ModelUpdateListener l)
          Removes a model update listener from the history.
 void replaced(ProgramElement root, ProgramElement replacement)
          Informs the change history of the replacement of a subtree by another one given by their root elements.
 void rollback()
          Removes all transformations in the stack and reverts all changes that have not been committed yet.
 void rollback(Transformation transformation)
          Removes the last transformations and reverts all their changes until the given transformation has been rolled back.
 void updateModel()
          Notifies all listeners of the current changes and resets the lists.
 
Methods inherited from class recoder.AbstractService
getServiceConfiguration, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChangeHistory

public ChangeHistory(ServiceConfiguration config)
Creates a new change history for the given configuration.

Method Detail

addChangeHistoryListener

public void addChangeHistoryListener(ChangeHistoryListener chl)
Adds a change history listener to the history.

Parameters:
chl - a listener.

removeChangeHistoryListener

public void removeChangeHistoryListener(ChangeHistoryListener chl)
Removes a change history listener from the history.

Parameters:
chl - a listener.

addModelUpdateListener

public void addModelUpdateListener(ModelUpdateListener l)
Adds a model update listener to the history.

Parameters:
mul - a listener.

removeModelUpdateListener

public void removeModelUpdateListener(ModelUpdateListener l)
Removes a model update listener from the history.

Parameters:
mul - a listener.

attached

public void attached(ProgramElement root)
Informs the change history of the addition of a new subtree given by its root element.

Parameters:
root - the root of the change.

detached

public void detached(ProgramElement root,
                     NonTerminalProgramElement parent,
                     int pos)
Informs the change history of the deletion of a subtree given by its root element. In case that the detached element is reattached, the former parent is given explicitly.

Parameters:
root - the root of the detached subtree.
parent - the former parent of the detached subtree; may be null only if the root is a compilation unit.
pos - the positional code of the root in its former parent, as obtained by NonTerminalProgramElement.getChildPositionCode(recoder.java.ProgramElement); the code may be arbitrary if the root is a compilation unit.

detached

public void detached(ProgramElement root,
                     int pos)
Informs the change history of the deletion of a subtree given by its root element. This method assumes that the parent link of the root element still points to the old parent.

Parameters:
root - the root of the detached subtree.
pos - the positional code of the root in its former parent, as obtained by NonTerminalProgramElement.getChildPositionCode(recoder.java.ProgramElement); the code may be arbitrary if the root is a compilation unit.

replaced

public void replaced(ProgramElement root,
                     ProgramElement replacement)
Informs the change history of the replacement of a subtree by another one given by their root elements. The replacement must have a valid parent.

Parameters:
root - the root of a subtree that has been replaced.
replacement - the root of a subtree that took over the role of the former tree.

needsUpdate

public final boolean needsUpdate()
Checks if there are changes in the change queue.

Returns:
true, if there are changes left in the queue, false otherwise.

updateModel

public final void updateModel()
Notifies all listeners of the current changes and resets the lists. Services that require up to date information should call this method before accessing their cache or precalculated information.


begin

public void begin(Transformation transformation)
Reports the start of a new transformation. After initialization or commit(), a dummy transformation is inserted which is automatically overwritten if a new transformation begins and the default transformation report sequence is still empty.

Parameters:
transformation - the transformation that begins.
Since:
0.53

rollback

public void rollback(Transformation transformation)
              throws NoSuchTransformationException
Removes the last transformations and reverts all their changes until the given transformation has been rolled back. The given transformation is removed.

Throws:
NoSuchTransformationException - if the given transformation is not known, for instance if it has already been removed.
Since:
0.53

rollback

public void rollback()
Removes all transformations in the stack and reverts all changes that have not been committed yet.

Since:
0.53
See Also:
commit()

isReported

public boolean isReported(Transformation transformation)
Checks if the given transformation is reported in this history and can be rolled back.

Parameters:
transformation - the transformation to locate.
Returns:
true, if the given transformation can be rolled back, false otherwise.
Since:
0.53

commit

public void commit()
Flushes all transformation sequences making them irreversible.

Since:
0.53

RECODER 0.92