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 Details

    • SourceElementBody

      public SourceElementBody()
  • Method Details

    • 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 to ISourceConstruct[].

      Specified by:
      getChildren in interface ISourceElementInfo
      Overrides:
      getChildren in class Body
      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, or null 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 interface ISourceElementInfo
      Parameters:
      p - a source element's property (not null)
      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, or null if the element has no associated source code or if the snapshot is unknown.
      Specified by:
      getSnapshot in interface ISourceElementInfo
      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, or null 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 interface ISourceElementInfo
      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, or null 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 interface ISourceElementInfo
      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 (not null)
      value - a value for the given property (may be null)
      See Also:
    • setSnapshot

      public void setSnapshot(ISnapshot snapshot)
      Sets the source snapshot on which this object is based.
      Parameters:
      snapshot - may be null
      See Also:
    • setFullRange

      public void setFullRange(TextRange fullRange)
      Sets the text range of the whole element.
      Parameters:
      fullRange - may be null
      See Also:
    • setIdentifyingRange

      public void setIdentifyingRange(TextRange identifyingRange)
      Sets the text range of the element's identifier.
      Parameters:
      identifyingRange - may be null
      See Also:
    • 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 and F_FINE_GRAINED if there is a change in the value of one of the element's properties. For a source file, this implicitly includes a change in its source range or snapshot.

      Overrides:
      findContentChange in class Body
      Parameters:
      oldBody - the old version of the body (not null)
      element - the element this body corresponds to (not null)
      builder - represents the delta tree being built (not null)
    • isPropertyChanged

      protected boolean isPropertyChanged(String propertyName, Object newValue, 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 (not null)
      newValue - the new value of the property (may be null)
      oldValue - the old value of the property (may be null)
      Returns:
      true if the property has changed its value, and false otherwise
    • getPropertyValue

      protected final Object getPropertyValue(String propertyName)
    • getPropertyNames

      protected final Set<String> getPropertyNames()