Class Tree

java.lang.Object
io.github.treesitter.jtreesitter.Tree
All Implemented Interfaces:
AutoCloseable, Cloneable

@NullMarked public final class Tree extends Object implements AutoCloseable, Cloneable
A class that represents a syntax tree.
  • Method Details

    • getLanguage

      public Language getLanguage()
      Get the language that was used to parse the syntax tree.
    • getText

      public @Nullable String getText()
      Get the source code of the syntax tree, if available.
    • getRootNode

      public Node getRootNode()
      Get the root node of the syntax tree.
    • getRootNodeWithOffset

      public @Nullable Node getRootNodeWithOffset(@Unsigned int bytes, Point extent)
      Get the root node of the syntax tree, but with its position shifted forward by the given offset.
    • getIncludedRanges

      public List<Range> getIncludedRanges()
      Get the included ranges of the syntax tree.
    • getChangedRanges

      public List<Range> getChangedRanges(Tree newTree)
      Compare an old edited syntax tree to a new syntax tree representing the same document.

      For this to work correctly, this tree must have been edited such that its ranges match up to the new tree.

      Returns:
      A list of ranges whose syntactic structure has changed.
    • edit

      public void edit(InputEdit edit)
      Edit the syntax tree to keep it in sync with source code that has been modified.
    • walk

      public TreeCursor walk()
      Create a new tree cursor starting from the root node of the tree.
    • clone

      public Tree clone()
      Create a shallow copy of the syntax tree.
      Implementation Note:
      You need to clone a tree in order to use it on more than one thread at a time, as Tree objects are not thread safe.
    • close

      public void close() throws RuntimeException
      Specified by:
      close in interface AutoCloseable
      Throws:
      RuntimeException
    • toString

      public String toString()
      Overrides:
      toString in class Object