Class ElementDelta
- java.lang.Object
-
- org.eclipse.handly.model.impl.support.ElementDelta
-
- All Implemented Interfaces:
IElementDelta,IElementDeltaImpl
public class ElementDelta extends java.lang.Object implements IElementDeltaImpl
A complete implementation ofIElementDeltaImpl. To create a delta tree, useElementDelta.Builder.Note that, despite having a dependency on
IResourceDeltaandIMarkerDelta, this class can be used even whenorg.eclipse.core.resourcesbundle is not available. This is based on the "outward impression" of late resolution of symbolic references a JVM must provide according to the JVMS.Clients can use this class as it stands or subclass it as circumstances warrant. Clients that subclass this class should consider registering an appropriate
ElementDelta.Factoryin the model context. Subclasses that introduce new fields should consider extending thecopyFrom_method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classElementDelta.BuilderBuilds a tree ofElementDeltaobjects based on elementary changes.static interfaceElementDelta.FactoryRepresents a factory for creating instances ofElementDelta.
-
Constructor Summary
Constructors Constructor Description ElementDelta(IElement element)Constructs an initially empty delta for the given element.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddAffectedChild_(ElementDelta child)Adds the given delta as an affected child of this delta if permitted by the current state of this delta.protected voidaddResourceDelta_(org.eclipse.core.resources.IResourceDelta resourceDelta)Adds the given resource delta to the collection of resource deltas of this delta if permitted by the current state of this delta.protected voidcopyFrom_(ElementDelta delta, boolean init)Copies data from the given delta to this delta; the given delta is not modified in any way.ElementDeltafindDelta_(IElement element)Finds and returns the delta for the given element in this delta subtree (subtree root included), ornullif no such delta can be found.ElementDelta[]getAddedChildren_()Returns element deltas for the immediate children that have been added.ElementDelta[]getAffectedChildren_()Returns element deltas for all affected (added, removed, or changed) immediate children.ElementDelta[]getChangedChildren_()Returns element deltas for the immediate children that have been changed.IElementgetElement_()Returns the element that this delta describes a change to.longgetFlags_()Returns flags which describe in more detail how an element has changed.intgetKind_()Returns the kind of this element delta.org.eclipse.core.resources.IMarkerDelta[]getMarkerDeltas_()Returns the changes to markers on the corresponding resource of this delta's element.IElementgetMovedFromElement_()Returns an element describing this delta's element before it was moved to its current location, ornullif theF_MOVED_FROMchange flag is not set.IElementgetMovedToElement_()Returns an element describing this delta's element in its new location, ornullif theF_MOVED_TOchange flag is not set.ElementDelta[]getRemovedChildren_()Returns element deltas for the immediate children that have been removed.org.eclipse.core.resources.IResourceDelta[]getResourceDeltas_()Returns the changes to children of the element's corresponding resource that cannot be described in terms of element deltas.protected voidinsertSubTree_(ElementDelta delta)Based on the given delta, creates a delta tree that can be directly parented by this delta andaddsthe created tree as an affected child of this delta.protected voidmergeWith_(ElementDelta delta)Merges this delta with the given delta; the given delta is not modified in any way.protected booleanneedsChildIndex_()Returns whether an index needs to be used for child lookup.protected ElementDeltanewDelta_(IElement element)Returns a new, initially empty delta for the given element.protected voidsetAffectedChildren_(ElementDelta[] children)Sets the affected children for this delta.protected voidsetFlags_(long flags)Sets the flags for this delta.protected voidsetKind_(int kind)Sets the kind of this delta.protected voidsetMarkerDeltas_(org.eclipse.core.resources.IMarkerDelta[] markerDeltas)Sets the marker deltas for this delta.protected voidsetMovedFromElement_(IElement movedFromElement)Sets an element describing this delta's element before it was moved to its current location.protected voidsetMovedToElement_(IElement movedToElement)Sets an element describing this delta's element in its new location.protected voidsetResourceDeltas_(org.eclipse.core.resources.IResourceDelta[] resourceDeltas)Sets the resource deltas for this delta.java.lang.StringtoString()java.lang.StringtoString_(IContext context)Returns a string representation of this element delta in a form suitable for debugging purposes.protected voidtoStringChildren_(java.lang.StringBuilder builder, IContext context)protected booleantoStringFlags_(java.lang.StringBuilder builder, IContext context)Appends a string representation for this delta's flags to the given string builder.protected voidtoStringKind_(java.lang.StringBuilder builder, IContext context)protected voidtoStringResourceDeltas_(java.lang.StringBuilder builder, IContext context)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.handly.model.impl.IElementDeltaImpl
isEmpty_
-
-
-
-
Constructor Detail
-
ElementDelta
public ElementDelta(IElement element)
Constructs an initially empty delta for the given element.- Parameters:
element- notnull- See Also:
ElementDelta.Builder
-
-
Method Detail
-
getElement_
public final IElement getElement_()
Description copied from interface:IElementDeltaImplReturns the element that this delta describes a change to.- Specified by:
getElement_in interfaceIElementDeltaImpl- Returns:
- the element that this delta describes a change to
(never
null)
-
getKind_
public final int getKind_()
Description copied from interface:IElementDeltaImplReturns the kind of this element delta. Normally, one ofADDED,REMOVED, orCHANGED. ReturnsNO_CHANGEif, and only if, the delta is empty.- Specified by:
getKind_in interfaceIElementDeltaImpl- Returns:
- the kind of this element delta
-
getFlags_
public final long getFlags_()
Description copied from interface:IElementDeltaImplReturns flags which describe in more detail how an element has changed. Such flags should be tested using the&operator. For example:if ((flags & F_CONTENT) != 0) // a content change
Some change flags make sense for most models and are predefined in
IElementDeltaConstants, while others are model-specific and are defined by the model implementor. The range for model-specific change flags starts from1L << 32and includes the upper 32 bits of thelongvalue. The lower 32 bits are reserved for predefined generic change flags.Move operations are indicated by special change flags. If an element is moved from A to B (with no other changes to A or B), then A will have kind
REMOVED, with flagF_MOVED_TO, andIElementDeltaImpl.getMovedToElement_()on A will return the handle for B. B will have kindADDED, with flagF_MOVED_FROM, andIElementDeltaImpl.getMovedFromElement_()on B will return the handle for A. (Note that the handle for A in this case represents an element that no longer exists.)- Specified by:
getFlags_in interfaceIElementDeltaImpl- Returns:
- flags that describe how an element has changed
-
findDelta_
public final ElementDelta findDelta_(IElement element)
Description copied from interface:IElementDeltaImplFinds and returns the delta for the given element in this delta subtree (subtree root included), ornullif no such delta can be found.This is a convenience method to avoid manual traversal of the delta tree in cases where the listener is only interested in changes to particular elements. Calling this method will generally be faster than manually traversing the delta to a particular descendant.
- Specified by:
findDelta_in interfaceIElementDeltaImpl- Parameters:
element- the element of the desired delta (may benull, in which casenullwill be returned)- Returns:
- the delta for the given element, or
nullif no such delta can be found
-
getAffectedChildren_
public final ElementDelta[] getAffectedChildren_()
Returns element deltas for all affected (added, removed, or changed) immediate children.This implementation returns an array of exactly the same runtime type as the array given in the most recent call to
setAffectedChildren_.- Specified by:
getAffectedChildren_in interfaceIElementDeltaImpl- Returns:
- element deltas for all affected immediate children
(never
null). Clients must not modify the returned array.
-
getAddedChildren_
public final ElementDelta[] getAddedChildren_()
Returns element deltas for the immediate children that have been added.This implementation returns an array of exactly the same runtime type as the array given in the most recent call to
setAffectedChildren_.- Specified by:
getAddedChildren_in interfaceIElementDeltaImpl- Returns:
- element deltas for the immediate children that have been added
(never
null). Clients must not modify the returned array.
-
getRemovedChildren_
public final ElementDelta[] getRemovedChildren_()
Returns element deltas for the immediate children that have been removed.This implementation returns an array of exactly the same runtime type as the array given in the most recent call to
setAffectedChildren_.- Specified by:
getRemovedChildren_in interfaceIElementDeltaImpl- Returns:
- element deltas for the immediate children that have been removed
(never
null). Clients must not modify the returned array.
-
getChangedChildren_
public final ElementDelta[] getChangedChildren_()
Returns element deltas for the immediate children that have been changed.This implementation returns an array of exactly the same runtime type as the array given in the most recent call to
setAffectedChildren_.- Specified by:
getChangedChildren_in interfaceIElementDeltaImpl- Returns:
- element deltas for the immediate children that have been changed
(never
null). Clients must not modify the returned array.
-
getMovedFromElement_
public final IElement getMovedFromElement_()
Description copied from interface:IElementDeltaImplReturns an element describing this delta's element before it was moved to its current location, ornullif theF_MOVED_FROMchange flag is not set.- Specified by:
getMovedFromElement_in interfaceIElementDeltaImpl- Returns:
- an element describing this delta's element before it was moved
to its current location, or
nullif theF_MOVED_FROMchange flag is not set - See Also:
IElementDeltaImpl.getMovedToElement_(),IElementDeltaImpl.getFlags_()
-
getMovedToElement_
public final IElement getMovedToElement_()
Description copied from interface:IElementDeltaImplReturns an element describing this delta's element in its new location, ornullif theF_MOVED_TOchange flag is not set.- Specified by:
getMovedToElement_in interfaceIElementDeltaImpl- Returns:
- an element describing this delta's element in its new location,
or
nullif theF_MOVED_TOchange flag is not set - See Also:
IElementDeltaImpl.getMovedFromElement_(),IElementDeltaImpl.getFlags_()
-
getMarkerDeltas_
public final org.eclipse.core.resources.IMarkerDelta[] getMarkerDeltas_()
Description copied from interface:IElementDeltaImplReturns the changes to markers on the corresponding resource of this delta's element.Returns
nullif no markers changed. Note that this is an exception to the general convention of returning an empty array rather thannull. This makes the method safe to call even whenorg.eclipse.core.resourcesbundle is not available.Note that marker deltas, like element deltas, are generally only valid for the dynamic scope of change notification. Clients must not hang on to these objects.
- Specified by:
getMarkerDeltas_in interfaceIElementDeltaImpl- Returns:
- the marker deltas, or
nullif none. Clients must not modify the returned array.
-
getResourceDeltas_
public final org.eclipse.core.resources.IResourceDelta[] getResourceDeltas_()
Description copied from interface:IElementDeltaImplReturns the changes to children of the element's corresponding resource that cannot be described in terms of element deltas.Returns
nullif there were no such changes. Note that this is an exception to the general convention of returning an empty array rather thannull. This makes the method safe to call even whenorg.eclipse.core.resourcesbundle is not available.Note that resource deltas, like element deltas, are generally only valid for the dynamic scope of change notification. Clients must not hang on to these objects.
- Specified by:
getResourceDeltas_in interfaceIElementDeltaImpl- Returns:
- the resource deltas, or
nullif none. Clients must not modify the returned array.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString_
public java.lang.String toString_(IContext context)
Description copied from interface:IElementDeltaImplReturns a string representation of this element delta in a form suitable for debugging purposes. Clients can influence the result with format options specified in the given context; unrecognized options are ignored and an empty context is permitted.Implementations are encouraged to support common options defined in
ToStringOptionsand interpret theFORMAT_STYLEas follows:- Specified by:
toString_in interfaceIElementDeltaImpl- Parameters:
context- notnull- Returns:
- a string representation of this element delta
(never
null)
-
toStringChildren_
protected void toStringChildren_(java.lang.StringBuilder builder, IContext context)
-
toStringResourceDeltas_
protected void toStringResourceDeltas_(java.lang.StringBuilder builder, IContext context)
-
toStringKind_
protected void toStringKind_(java.lang.StringBuilder builder, IContext context)
-
toStringFlags_
protected boolean toStringFlags_(java.lang.StringBuilder builder, IContext context)Appends a string representation for this delta's flags to the given string builder.- Parameters:
builder- a string builder to append the delta flags tocontext- notnull- Returns:
trueif a flag was appended to the builder, andfalseif the builder was not modified by this method- See Also:
getFlags_()
-
newDelta_
protected ElementDelta newDelta_(IElement element)
Returns a new, initially empty delta for the given element.This implementation uses
ElementDelta.Factoryregistered in the element's model context. If no delta factory is registered in the model context, a new instance of this class (i.e.,ElementDelta) is returned.- Parameters:
element- notnull- Returns:
- a new, initially empty delta for the given element
(never
null)
-
needsChildIndex_
protected boolean needsChildIndex_()
Returns whether an index needs to be used for child lookup.- Returns:
trueif the child index needs to be used, andfalseotherwise
-
setKind_
protected void setKind_(int kind)
Sets the kind of this delta.This is a low-level mutator method. In particular, it is the caller's responsibility to ensure validity of the given value.
- Parameters:
kind- the delta kind- See Also:
getKind_()
-
setFlags_
protected void setFlags_(long flags)
Sets the flags for this delta.This is a low-level mutator method. In particular, it is the caller's responsibility to ensure validity of the given value.
- Parameters:
flags- the delta flags- See Also:
getFlags_()
-
setMovedFromElement_
protected void setMovedFromElement_(IElement movedFromElement)
Sets an element describing this delta's element before it was moved to its current location.This is a low-level mutator method. In particular, it is the caller's responsibility to set appropriate kind and flags for this delta.
- Parameters:
movedFromElement- an element describing this delta's element before it was moved to its current location- See Also:
getMovedFromElement_()
-
setMovedToElement_
protected void setMovedToElement_(IElement movedToElement)
Sets an element describing this delta's element in its new location.This is a low-level mutator method. In particular, it is the caller's responsibility to set appropriate kind and flags for this delta.
- Parameters:
movedToElement- an element describing this delta's element in its new location- See Also:
getMovedToElement_()
-
setMarkerDeltas_
protected void setMarkerDeltas_(org.eclipse.core.resources.IMarkerDelta[] markerDeltas)
Sets the marker deltas for this delta. Clients must not modify the given array afterwards.This is a low-level mutator method. In particular, it is the caller's responsibility to set appropriate kind and flags for this delta.
- Parameters:
markerDeltas- the marker deltas- See Also:
getMarkerDeltas_()
-
setResourceDeltas_
protected void setResourceDeltas_(org.eclipse.core.resources.IResourceDelta[] resourceDeltas)
Sets the resource deltas for this delta. Clients must not modify the given array afterwards.This is a low-level mutator method. In particular, it is the caller's responsibility to set appropriate kind and flags for this delta.
- Parameters:
resourceDeltas- the resource deltas- See Also:
getResourceDeltas_()
-
addResourceDelta_
protected void addResourceDelta_(org.eclipse.core.resources.IResourceDelta resourceDelta)
Adds the given resource delta to the collection of resource deltas of this delta if permitted by the current state of this delta. Note that in contrast tosetResourceDeltas_, this method can change this delta's kind and flags as appropriate.If the kind of this delta is
ADDEDorREMOVED, this implementation returns without adding the given resource delta; otherwise, it sets the kind of this delta toCHANGEDand adds theF_CONTENTchange flag.- Parameters:
resourceDelta- the resource delta to add (notnull)- See Also:
getResourceDeltas_()
-
insertSubTree_
protected void insertSubTree_(ElementDelta delta)
Based on the given delta, creates a delta tree that can be directly parented by this delta andaddsthe created tree as an affected child of this delta.Note that after calling
insertSubTree_(delta)there is no guarantee thatfindDelta_(d.getElement_()) == d
or even that
findDelta_(d.getElement_()) != null
for any delta
din the subtreedelta(subtree root included). For example, if this delta tree already contains a delta ford.getElement_(), that delta will bemergedwithd, which may even result in a logically empty delta, i.e., no delta for the element.- Parameters:
delta- the delta to insert (notnull)- Throws:
java.lang.IllegalArgumentException- if the given delta cannot be rooted in this delta
-
addAffectedChild_
protected void addAffectedChild_(ElementDelta child)
Adds the given delta as an affected child of this delta if permitted by the current state of this delta. If this delta already contains a child delta for the same element as the given delta,mergesthe existing child delta with the given delta. Note that in contrast tosetAffectedChildren_, this method can change this delta's kind and flags as appropriate.It is the caller's responsibility to ensure that the given delta can be directly parented by this delta.
Note that after calling
addAffectedChild_(delta)there is no guarantee thatfindDelta_(d.getElement_()) == d
or even that
findDelta_(d.getElement_()) != null
for any delta
din the subtreedelta(subtree root included).If the kind of this delta is
ADDEDorREMOVED, this implementation returns without adding the given delta; otherwise, it sets the kind of this delta toCHANGEDand adds theF_CHILDRENchange flag and, if this delta's element is anISourceElement, theF_FINE_GRAINEDchange flag.- Parameters:
child- the delta to add as an affected child (notnull)- See Also:
getAffectedChildren_(),insertSubTree_(ElementDelta)
-
mergeWith_
protected void mergeWith_(ElementDelta delta)
Merges this delta with the given delta; the given delta is not modified in any way.It is the caller's responsibility to ensure that the given delta pertains to the same element as this delta.
This implementation implements merge semantics in terms of calls to
copyFrom_.- Parameters:
delta- the delta to merge with (notnull)
-
copyFrom_
protected void copyFrom_(ElementDelta delta, boolean init)
Copies data from the given delta to this delta; the given delta is not modified in any way.It is the caller's responsibility to ensure that the given delta pertains to the same element as this delta.
Subclasses that introduce new fields should consider extending this method.
- Parameters:
delta- the delta to copy data from (notnull)init-trueif this delta needs to be completely (re-)initialized with data from the given delta;falseif this delta needs to be augmented with data from the given delta
-
setAffectedChildren_
protected void setAffectedChildren_(ElementDelta[] children)
Sets the affected children for this delta. Clients must not modify the given array afterwards.This is a low-level mutator method. In particular, it is the caller's responsibility to set appropriate kind and flags for this delta.
- Parameters:
children- the affected children (notnull)- See Also:
getAffectedChildren_()
-
-