Class SourceElementBody
- java.lang.Object
-
- org.eclipse.handly.model.impl.support.Body
-
- org.eclipse.handly.model.impl.support.SourceElementBody
-
- All Implemented Interfaces:
ISourceElementInfo
public class SourceElementBody extends Body implements ISourceElementInfo
Holds cached structure and properties for a source element.This implementation is not synchronized. If multiple threads access a source element body concurrently, and at least one of them modifies the body, it must be synchronized externally. Note, however, that the typical usage pattern is that a source element body is not modified after initialization.
Clients can use this class as it stands or subclass it as circumstances warrant.
-
-
Constructor Summary
Constructors Constructor Description SourceElementBody()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
findContentChange(Body oldBody, IElement element, IElementDeltaBuilder builder)
Finds whether this body has had a content change.<T> T
get(Property<T> p)
Returns the cached value for the given property, ornull
if no value is set.ISourceConstruct[]
getChildren()
Returns the child elements for this body.TextRange
getFullRange()
Returns the text range of the whole element, ornull
if none.TextRange
getIdentifyingRange()
Returns the text range of the element's identifier, ornull
if none.protected java.util.Set<java.lang.String>
getPropertyNames()
protected java.lang.Object
getPropertyValue(java.lang.String propertyName)
ISnapshot
getSnapshot()
Returns the source snapshot on which this object is based, ornull
if the element has no associated source code or if the snapshot is unknown.protected boolean
isPropertyChanged(java.lang.String propertyName, java.lang.Object newValue, java.lang.Object oldValue)
Returns whether the given property has changed its value.<T> void
set(Property<T> p, T value)
Sets the cached value for the given property.void
setFullRange(TextRange fullRange)
Sets the text range of the whole element.void
setIdentifyingRange(TextRange identifyingRange)
Sets the text range of the element's identifier.void
setSnapshot(ISnapshot snapshot)
Sets the source snapshot on which this object is based.-
Methods inherited from class org.eclipse.handly.model.impl.support.Body
addChild, removeChild, setChildren
-
-
-
-
Method Detail
-
getChildren
public ISourceConstruct[] getChildren()
Returns the child elements for this body.This implementation returns an array of exactly the same runtime type as the array given in the most recent call to
setChildren
if that type is assignable toISourceConstruct[]
.- Specified by:
getChildren
in interfaceISourceElementInfo
- Overrides:
getChildren
in classBody
- Returns:
- the child elements for this body (never
null
). Clients must not modify the returned array.
-
get
public <T> T get(Property<T> p)
Description copied from interface:ISourceElementInfo
Returns the cached value for the given property, ornull
if no value is set.To find the value to which the given property object is mapped, implementations of this method may use an identity-based lookup, name-based lookup, or anything in-between. Clients need to use unique property instances with unique names for unambiguous identification of a mapping.
Note that the result correlates to a source
snapshot
(if there is one) and may be inconsistent with the current source contents.- Specified by:
get
in interfaceISourceElementInfo
- Parameters:
p
- a source element's property (notnull
)- Returns:
- the cached value for the given property, or
null
if no value is set. Clients must not modify the returned value even if mutation is technically possible (e.g., for a non-empty array).
-
getSnapshot
public ISnapshot getSnapshot()
Description copied from interface:ISourceElementInfo
Returns the source snapshot on which this object is based, ornull
if the element has no associated source code or if the snapshot is unknown.- Specified by:
getSnapshot
in interfaceISourceElementInfo
- Returns:
- the source snapshot on which this object is based,
or
null
if the element has no associated source code or if the snapshot is unknown
-
getFullRange
public TextRange getFullRange()
Description copied from interface:ISourceElementInfo
Returns the text range of the whole element, ornull
if none.Note that the result correlates to a source
snapshot
(if there is one) and may be inconsistent with the current source contents.- Specified by:
getFullRange
in interfaceISourceElementInfo
- Returns:
- the text range associated with the whole element,
or
null
if none
-
getIdentifyingRange
public TextRange getIdentifyingRange()
Description copied from interface:ISourceElementInfo
Returns the text range of the element's identifier, ornull
if none.Note that the result correlates to a source
snapshot
(if there is one) and may be inconsistent with the current source contents.- Specified by:
getIdentifyingRange
in interfaceISourceElementInfo
- Returns:
- the text range associated with the element's identifier,
or
null
if none
-
set
public <T> void set(Property<T> p, T value)
Sets the cached value for the given property.- Parameters:
p
- a source element's property (notnull
)value
- a value for the given property (may benull
)- See Also:
get(Property)
-
setSnapshot
public void setSnapshot(ISnapshot snapshot)
Sets the source snapshot on which this object is based.- Parameters:
snapshot
- may benull
- See Also:
getSnapshot()
-
setFullRange
public void setFullRange(TextRange fullRange)
Sets the text range of the whole element.- Parameters:
fullRange
- may benull
- See Also:
getFullRange()
-
setIdentifyingRange
public void setIdentifyingRange(TextRange identifyingRange)
Sets the text range of the element's identifier.- Parameters:
identifyingRange
- may benull
- See Also:
getIdentifyingRange()
-
findContentChange
public void findContentChange(Body oldBody, IElement element, IElementDeltaBuilder builder)
Finds whether this body has had a content change.Implementations can compare this body and the given old body and, if there are differences (excepting children), insert an appropriate change delta (such as
F_CONTENT
) for the given element into the delta tree being built. Implementations should not take changes in children into account.This implementation inserts a change delta with flags
F_CONTENT
andF_FINE_GRAINED
if there is achange
in thevalue
of one of the element'sproperties
. For a source file, this implicitly includes a change in its sourcerange
orsnapshot
.- Overrides:
findContentChange
in classBody
- Parameters:
oldBody
- the old version of the body (notnull
)element
- the element this body corresponds to (notnull
)builder
- represents the delta tree being built (notnull
)
-
isPropertyChanged
protected boolean isPropertyChanged(java.lang.String propertyName, java.lang.Object newValue, java.lang.Object oldValue)
Returns whether the given property has changed its value.This implementation compares the new value and the old value for equality; arrays are compared with
Arrays.equals
.- Parameters:
propertyName
- the name of the property (notnull
)newValue
- the new value of the property (may benull
)oldValue
- the old value of the property (may benull
)- Returns:
true
if the property has changed its value, andfalse
otherwise
-
getPropertyValue
protected final java.lang.Object getPropertyValue(java.lang.String propertyName)
-
getPropertyNames
protected final java.util.Set<java.lang.String> getPropertyNames()
-
-