Class SourceElementBody
- All Implemented Interfaces:
ISourceElementInfo
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
findContentChange
(Body oldBody, IElement element, IElementDeltaBuilder builder) Finds whether this body has had a content change.<T> T
Returns the cached value for the given property, ornull
if no value is set.Returns the child elements for this body.Returns the text range of the whole element, ornull
if none.Returns the text range of the element's identifier, ornull
if none.protected final Object
getPropertyValue
(String propertyName) 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
(String propertyName, Object newValue, Object oldValue) Returns whether the given property has changed its value.<T> void
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
-
Constructor Details
-
SourceElementBody
public SourceElementBody()
-
-
Method Details
-
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
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
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
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
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
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:
-
setSnapshot
Sets the source snapshot on which this object is based.- Parameters:
snapshot
- may benull
- See Also:
-
setFullRange
Sets the text range of the whole element.- Parameters:
fullRange
- may benull
- See Also:
-
setIdentifyingRange
Sets the text range of the element's identifier.- Parameters:
identifyingRange
- may benull
- See Also:
-
findContentChange
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
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
-
getPropertyNames
-