public class ElementDelta extends java.lang.Object implements IElementDeltaImpl
IElementDeltaImpl
.
To create a delta tree, use ElementDelta.Builder
.
Note that, despite having a dependency on IResourceDelta
and IMarkerDelta
, this class can be used even when
org.eclipse.core.resources
bundle 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.Factory
in the model context.
Subclasses that introduce new fields should consider extending
the copyFrom_
method.
Modifier and Type | Class and Description |
---|---|
static class |
ElementDelta.Builder
Builds a tree of
ElementDelta objects based on elementary changes. |
static interface |
ElementDelta.Factory
Represents a factory for creating instances of
ElementDelta . |
Constructor and Description |
---|
ElementDelta(IElement element)
Constructs an initially empty delta for the given element.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
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.
|
ElementDelta |
findDelta_(IElement element)
Finds and returns the delta for the given element in this delta subtree
(subtree root included), or
null if 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.
|
IElement |
getElement_()
Returns the element that this delta describes a change to.
|
long |
getFlags_()
Returns flags which describe in more detail how an element has changed.
|
int |
getKind_()
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.
|
IElement |
getMovedFromElement_()
Returns an element describing this delta's element before it was moved
to its current location, or
null if the F_MOVED_FROM change flag is not set. |
IElement |
getMovedToElement_()
Returns an element describing this delta's element in its new location,
or
null if the F_MOVED_TO change 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 void |
insertSubTree_(ElementDelta delta)
Based on the given delta, creates a delta tree that can be directly
parented by this delta and
adds the created
tree as an affected child of this delta. |
protected void |
mergeWith_(ElementDelta delta)
Merges this delta with the given delta; the given delta is not modified
in any way.
|
protected boolean |
needsChildIndex_()
Returns whether an index needs to be used for child lookup.
|
protected ElementDelta |
newDelta_(IElement element)
Returns a new, initially empty delta for the given element.
|
protected void |
setAffectedChildren_(ElementDelta[] children)
Sets the affected children for this delta.
|
protected void |
setFlags_(long flags)
Sets the flags for this delta.
|
protected void |
setKind_(int kind)
Sets the kind of this delta.
|
protected void |
setMarkerDeltas_(org.eclipse.core.resources.IMarkerDelta[] markerDeltas)
Sets the marker deltas for this delta.
|
protected void |
setMovedFromElement_(IElement movedFromElement)
Sets an element describing this delta's element before it was moved
to its current location.
|
protected void |
setMovedToElement_(IElement movedToElement)
Sets an element describing this delta's element in its new location.
|
protected void |
setResourceDeltas_(org.eclipse.core.resources.IResourceDelta[] resourceDeltas)
Sets the resource deltas for this delta.
|
java.lang.String |
toString_(IContext context)
Returns a string representation of this element delta in a form suitable
for debugging purposes.
|
java.lang.String |
toString() |
protected void |
toStringChildren_(java.lang.StringBuilder builder,
IContext context) |
protected boolean |
toStringFlags_(java.lang.StringBuilder builder,
IContext context)
Appends a string representation for this delta's flags to the given
string builder.
|
protected void |
toStringKind_(java.lang.StringBuilder builder,
IContext context) |
protected void |
toStringResourceDeltas_(java.lang.StringBuilder builder,
IContext context) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isEmpty_
public ElementDelta(IElement element)
element
- not null
ElementDelta.Builder
public final IElement getElement_()
IElementDeltaImpl
getElement_
in interface IElementDeltaImpl
null
)public final int getKind_()
IElementDeltaImpl
ADDED
,
REMOVED
,
or CHANGED
.
Returns NO_CHANGE
if, and only if, the delta is empty.getKind_
in interface IElementDeltaImpl
public final long getFlags_()
IElementDeltaImpl
&
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 from 1L << 32
and includes the upper 32 bits of the
long
value. 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 flag F_MOVED_TO
, and IElementDeltaImpl.getMovedToElement_()
on A will return the handle for B. B will have
kind ADDED
, with flag F_MOVED_FROM
, and IElementDeltaImpl.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.)
getFlags_
in interface IElementDeltaImpl
public final ElementDelta findDelta_(IElement element)
IElementDeltaImpl
null
if 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.
findDelta_
in interface IElementDeltaImpl
element
- the element of the desired delta (may be null
,
in which case null
will be returned)null
if no such
delta can be foundpublic final ElementDelta[] getAffectedChildren_()
This implementation returns an array of exactly the same
runtime type as the array given in the most recent call to
setAffectedChildren_
.
getAffectedChildren_
in interface IElementDeltaImpl
null
). Clients must not modify
the returned array.public final ElementDelta[] getAddedChildren_()
This implementation returns an array of exactly the same
runtime type as the array given in the most recent call to
setAffectedChildren_
.
getAddedChildren_
in interface IElementDeltaImpl
null
). Clients must not modify
the returned array.public final ElementDelta[] getRemovedChildren_()
This implementation returns an array of exactly the same
runtime type as the array given in the most recent call to
setAffectedChildren_
.
getRemovedChildren_
in interface IElementDeltaImpl
null
). Clients must not modify
the returned array.public final ElementDelta[] getChangedChildren_()
This implementation returns an array of exactly the same
runtime type as the array given in the most recent call to
setAffectedChildren_
.
getChangedChildren_
in interface IElementDeltaImpl
null
). Clients must not modify
the returned array.public final IElement getMovedFromElement_()
IElementDeltaImpl
null
if the F_MOVED_FROM
change flag is not set.getMovedFromElement_
in interface IElementDeltaImpl
null
if the F_MOVED_FROM
change flag is not setIElementDeltaImpl.getMovedToElement_()
,
IElementDeltaImpl.getFlags_()
public final IElement getMovedToElement_()
IElementDeltaImpl
null
if the F_MOVED_TO
change flag is not set.getMovedToElement_
in interface IElementDeltaImpl
null
if the F_MOVED_TO
change flag is not setIElementDeltaImpl.getMovedFromElement_()
,
IElementDeltaImpl.getFlags_()
public final org.eclipse.core.resources.IMarkerDelta[] getMarkerDeltas_()
IElementDeltaImpl
Returns null
if no markers changed. Note that this is
an exception to the general convention of returning an empty array
rather than null
. This makes the method safe to call
even when org.eclipse.core.resources
bundle 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.
getMarkerDeltas_
in interface IElementDeltaImpl
null
if none.
Clients must not modify the returned array.public final org.eclipse.core.resources.IResourceDelta[] getResourceDeltas_()
IElementDeltaImpl
Returns null
if there were no such changes. Note that this
is an exception to the general convention of returning an empty array
rather than null
. This makes the method safe to call even
when org.eclipse.core.resources
bundle 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.
getResourceDeltas_
in interface IElementDeltaImpl
null
if none.
Clients must not modify the returned array.public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString_(IContext context)
IElementDeltaImpl
Implementations are encouraged to support common options defined in
ToStringOptions
and
interpret the FORMAT_STYLE
as follows:
toString_
in interface IElementDeltaImpl
context
- not null
null
)protected void toStringChildren_(java.lang.StringBuilder builder, IContext context)
protected void toStringResourceDeltas_(java.lang.StringBuilder builder, IContext context)
protected void toStringKind_(java.lang.StringBuilder builder, IContext context)
protected boolean toStringFlags_(java.lang.StringBuilder builder, IContext context)
builder
- a string builder to append the delta flags tocontext
- not null
true
if a flag was appended to the builder,
and false
if the builder was not modified by this methodgetFlags_()
protected ElementDelta newDelta_(IElement element)
This implementation uses ElementDelta.Factory
registered 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.
element
- not null
null
)protected boolean needsChildIndex_()
true
if the child index needs to be used,
and false
otherwiseprotected void setKind_(int kind)
This is a low-level mutator method. In particular, it is the caller's responsibility to ensure validity of the given value.
kind
- the delta kindgetKind_()
protected void setFlags_(long flags)
This is a low-level mutator method. In particular, it is the caller's responsibility to ensure validity of the given value.
flags
- the delta flagsgetFlags_()
protected void setMovedFromElement_(IElement movedFromElement)
This is a low-level mutator method. In particular, it is the caller's responsibility to set appropriate kind and flags for this delta.
movedFromElement
- an element describing this delta's element
before it was moved to its current locationgetMovedFromElement_()
protected void setMovedToElement_(IElement movedToElement)
This is a low-level mutator method. In particular, it is the caller's responsibility to set appropriate kind and flags for this delta.
movedToElement
- an element describing this delta's element
in its new locationgetMovedToElement_()
protected void setMarkerDeltas_(org.eclipse.core.resources.IMarkerDelta[] markerDeltas)
This is a low-level mutator method. In particular, it is the caller's responsibility to set appropriate kind and flags for this delta.
markerDeltas
- the marker deltasgetMarkerDeltas_()
protected void setResourceDeltas_(org.eclipse.core.resources.IResourceDelta[] resourceDeltas)
This is a low-level mutator method. In particular, it is the caller's responsibility to set appropriate kind and flags for this delta.
resourceDeltas
- the resource deltasgetResourceDeltas_()
protected void addResourceDelta_(org.eclipse.core.resources.IResourceDelta resourceDelta)
setResourceDeltas_
, this method can change this delta's kind and flags
as appropriate.
If the kind of this delta is ADDED
or REMOVED
,
this implementation returns without adding the given resource delta;
otherwise, it sets the kind of this delta to CHANGED
and
adds the F_CONTENT
change flag.
resourceDelta
- the resource delta to add (not null
)getResourceDeltas_()
protected void insertSubTree_(ElementDelta delta)
adds
the created
tree as an affected child of this delta.
Note that after calling insertSubTree_(delta)
there is no guarantee that
findDelta_(d.getElement_()) == d
or even that
findDelta_(d.getElement_()) != null
for any delta d
in the subtree delta
(subtree root included). For example, if this delta tree already contains
a delta for d.getElement_()
, that delta will be merged
with d
, which may even
result in a logically empty delta, i.e., no delta for the element.
delta
- the delta to insert (not null
)java.lang.IllegalArgumentException
- if the given delta cannot be rooted
in this deltaprotected void addAffectedChild_(ElementDelta child)
merges
the existing child delta with the given delta.
Note that in contrast to setAffectedChildren_
, 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 that
findDelta_(d.getElement_()) == d
or even that
findDelta_(d.getElement_()) != null
for any delta d
in the subtree delta
(subtree root included).
If the kind of this delta is ADDED
or REMOVED
,
this implementation returns without adding the given delta; otherwise,
it sets the kind of this delta to CHANGED
and adds the
F_CHILDREN
change flag and, if this delta's element is an
ISourceElement
, the F_FINE_GRAINED
change flag.
child
- the delta to add as an affected child (not null
)getAffectedChildren_()
,
insertSubTree_(ElementDelta)
protected void mergeWith_(ElementDelta delta)
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_
.
delta
- the delta to merge with (not null
)protected void copyFrom_(ElementDelta delta, boolean init)
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.
delta
- the delta to copy data from (not null
)init
- true
if this delta needs to be completely
(re-)initialized with data from the given delta; false
if this delta needs to be augmented with data from the given deltaprotected void setAffectedChildren_(ElementDelta[] children)
This is a low-level mutator method. In particular, it is the caller's responsibility to set appropriate kind and flags for this delta.
children
- the affected children (not null
)getAffectedChildren_()
Copyright (c) 2014, 2019 1C-Soft LLC and others. Made available under the Eclipse Public License 2.0