Class SourceSection

java.lang.Object
com.oracle.truffle.api.source.SourceSection

public abstract class SourceSection extends Object
Description of contiguous section of text within a Source of program code.; supports multiple modes of access to the text and its location.

Two available source sections are considered equal if their sources, start and length are equal. Unavailable source sections are compared by identity. Source sections can be used as keys in hash maps.

Since:
0.8 or earlier
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract boolean
     
    abstract CharSequence
    Returns the source code fragment described by this section.
    abstract int
    Returns the index of the text position immediately following the last character in the section.
    abstract int
    Returns the 0-based index of the first character in this section.
    abstract int
    Returns the length of this section in characters.
    abstract int
    Returns the 1-based column number of the last character in this section (inclusive).
    abstract int
    Returns 1-based line number of the last character in this section (inclusive).
    final Source
    Representation of the source program that contains this section.
    abstract int
    Returns the 1-based column number of the first character in this section (inclusive).
    abstract int
    Returns 1-based line number of the first character in this section (inclusive).
    abstract boolean
    Returns true if this section has a character index information, false otherwise.
    abstract boolean
    Returns true if this section has a column number information, false otherwise.
    abstract int
     
    abstract boolean
    Returns true if this section has a line number information, false otherwise.
    abstract boolean
    Returns whether this is a special instance that signifies that source information is available.
    final String
    Returns an implementation-defined string representation of this source section to be used for debugging purposes only.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • isAvailable

      public abstract boolean isAvailable()
      Returns whether this is a special instance that signifies that source information is available. Unavailable source sections can be created using Source.createUnavailableSection(). Available source sections are never equal to unavailable source sections. Unavailable source sections return the same indices and lengths as empty source sections starting at character index 0.
      Since:
      0.18
      See Also:
    • hasLines

      public abstract boolean hasLines()
      Returns true if this section has a line number information, false otherwise. When true, getStartLine() and getEndLine() return valid line numbers, when false, getStartLine() and getEndLine() return 1.
      Since:
      19.0
    • hasColumns

      public abstract boolean hasColumns()
      Returns true if this section has a column number information, false otherwise. When true, hasLines() is true as well, getStartColumn() and getEndColumn() return valid column numbers. When false, getStartColumn() and getEndColumn() return 1.
      Since:
      19.0
    • hasCharIndex

      public abstract boolean hasCharIndex()
      Returns true if this section has a character index information, false otherwise. When true, getCharIndex(), getCharEndIndex() and getCharLength() return valid character indices, when false, getCharIndex(), getCharEndIndex() and getCharLength() return 0.
      Since:
      19.0
    • getSource

      public final Source getSource()
      Representation of the source program that contains this section.
      Returns:
      the source object
      Since:
      0.8 or earlier
    • getStartLine

      public abstract int getStartLine()
      Returns 1-based line number of the first character in this section (inclusive). Returns 1 for out of bounds or unavailable source sections, or source sections not having lines.
      Returns:
      the starting line number
      Since:
      0.8 or earlier
      See Also:
    • getStartColumn

      public abstract int getStartColumn()
      Returns the 1-based column number of the first character in this section (inclusive). Returns 1 for out of bounds or unavailable source sections, or source sections not having columns.
      Returns:
      the starting column number
      Since:
      0.8 or earlier
      See Also:
    • getEndLine

      public abstract int getEndLine()
      Returns 1-based line number of the last character in this section (inclusive). Returns 1 for out of bounds or unavailable source sections, or source sections not having lines.
      Returns:
      the starting line number
      Since:
      0.8 or earlier
      See Also:
    • getEndColumn

      public abstract int getEndColumn()
      Returns the 1-based column number of the last character in this section (inclusive). Returns 1 for out of bounds or unavailable source sections, or source sections not having columns.
      Returns:
      the starting column number
      Since:
      0.8 or earlier
      See Also:
    • getCharIndex

      public abstract int getCharIndex()
      Returns the 0-based index of the first character in this section. Returns 0 for unavailable source sections, or sections not having character index. The returned index might be out of bounds of the source code if assertions (-ea) are not enabled.
      Returns:
      the starting character index
      Since:
      0.8 or earlier
      See Also:
    • getCharLength

      public abstract int getCharLength()
      Returns the length of this section in characters. Returns 0 for unavailable source sections, or sections not having character index. The returned length might be out of bounds of the source code if assertions (-ea) are not enabled.
      Returns:
      the number of characters in the section
      Since:
      0.8 or earlier
      See Also:
    • getCharEndIndex

      public abstract int getCharEndIndex()
      Returns the index of the text position immediately following the last character in the section. Returns 0 for unavailable source sections, or sections not having character index. The returned index might be out of bounds of the source code if assertions (-ea) are not enabled.
      Returns:
      the end position of the section
      Since:
      0.8 or earlier
      See Also:
    • getCharacters

      public abstract CharSequence getCharacters()
      Returns the source code fragment described by this section. Returns an empty character sequence for out of bounds or unavailable source sections, or sections whose source does not have characters.
      Returns:
      the code as a CharSequence
      Since:
      0.28
      See Also:
    • toString

      public final String toString()
      Returns an implementation-defined string representation of this source section to be used for debugging purposes only.
      Overrides:
      toString in class Object
      Since:
      0.8 or earlier
      See Also:
    • hashCode

      public abstract int hashCode()
      Overrides:
      hashCode in class Object
      Since:
      0.8 or earlier
    • equals

      public abstract boolean equals(Object obj)
      Overrides:
      equals in class Object
      Since:
      0.8 or earlier