Class SourceRange

  • All Implemented Interfaces:
    ISourceRange

    public final class SourceRange
    extends java.lang.Object
    implements ISourceRange
    A source range defines an element's source coordinates relative to its source buffer.
    Since:
    3.6
    See Also:
    ISourceRange
    • Constructor Summary

      Constructors 
      Constructor Description
      SourceRange​(int offset, int length)
      Instantiate a new source range using the given offset and the given length.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      int getLength()
      Returns the number of characters of the source code for this element, relative to the source buffer in which this element is contained.
      int getOffset()
      Returns the 0-based index of the first character of the source code for this element, relative to the source buffer in which this element is contained.
      int hashCode()  
      static boolean isAvailable​(ISourceRange range)
      Helper method that answers whether a valid source range is available in the given ISourceRange.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • SourceRange

        public SourceRange​(int offset,
                           int length)
        Instantiate a new source range using the given offset and the given length.
        Parameters:
        offset - the given offset
        length - the given length
    • Method Detail

      • isAvailable

        public static boolean isAvailable​(ISourceRange range)
        Helper method that answers whether a valid source range is available in the given ISourceRange. When an element has no associated source code, Java Model APIs may return either null or a range of [-1, 0] to indicate an invalid range. This utility method can be used to detect that case.
        Parameters:
        range - a source range, can be null
        Returns:
        true iff range is not null and range.getOffset() is not -1
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getLength

        public int getLength()
        Description copied from interface: ISourceRange
        Returns the number of characters of the source code for this element, relative to the source buffer in which this element is contained.
        Specified by:
        getLength in interface ISourceRange
        Returns:
        the number of characters of the source code for this element, relative to the source buffer in which this element is contained
        See Also:
        ISourceRange
      • getOffset

        public int getOffset()
        Description copied from interface: ISourceRange
        Returns the 0-based index of the first character of the source code for this element, relative to the source buffer in which this element is contained. However, if the element has no associated source code, an implementation may return -1.
        Specified by:
        getOffset in interface ISourceRange
        Returns:
        the 0-based index of the first character of the source code for this element, relative to the source buffer in which this element is contained. However, if the element has no associated source code, an implementation may return -1.
        See Also:
        ISourceRange
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object