Class: TreeHaver::Backends::Java::Tree Private
- Inherits:
-
Object
- Object
- TreeHaver::Backends::Java::Tree
- Defined in:
- lib/tree_haver/backends/java.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Java backend tree wrapper (raw backend tree)
This is a raw backend tree that wraps a jtreesitter Tree object via JRuby's Java interop. It is NOT intended for direct use by application code.
Architecture Note
Unlike pure-Ruby backends (Citrus, Parslet, Prism, Psych) which define Tree
classes that inherit from TreeHaver::Base::Tree, tree-sitter backends (MRI,
Rust, FFI, Java) define raw wrapper classes that get wrapped by TreeHaver::Tree.
The wrapping hierarchy is:
Java::Tree (this class) → TreeHaver::Tree → Base::Tree
When you use TreeHaver::Parser#parse, the returned tree is already wrapped
in TreeHaver::Tree, which provides the full unified API including:
#source- The original source text#root_node- Returns aTreeHaver::Node(not rawJava::Node)#errors,#warnings,#comments- Parse diagnostics#edit- Mark tree as edited for incremental parsing#to_s,#inspect- String representations
This raw class only implements methods that require direct calls to jtreesitter.
The wrapper adds Ruby-level conveniences and stores the source text needed for
Node#text extraction.
Instance Attribute Summary collapse
- #impl ⇒ Object readonly private
Instance Method Summary collapse
-
#edit(start_byte:, old_end_byte:, new_end_byte:, start_point:, old_end_point:, new_end_point:) ⇒ void
private
Mark the tree as edited for incremental re-parsing.
-
#initialize(impl) ⇒ Tree
constructor
private
A new instance of Tree.
-
#root_node ⇒ Node
private
Get the root node of the tree.
Constructor Details
#initialize(impl) ⇒ Tree
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Tree.
617 618 619 |
# File 'lib/tree_haver/backends/java.rb', line 617 def initialize(impl) @impl = impl end |
Instance Attribute Details
#impl ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
614 615 616 |
# File 'lib/tree_haver/backends/java.rb', line 614 def impl @impl end |
Instance Method Details
#edit(start_byte:, old_end_byte:, new_end_byte:, start_point:, old_end_point:, new_end_point:) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Mark the tree as edited for incremental re-parsing
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 |
# File 'lib/tree_haver/backends/java.rb', line 649 def edit(start_byte:, old_end_byte:, new_end_byte:, start_point:, old_end_point:, new_end_point:) point_class = Java.java_classes[:Point] input_edit_class = Java.java_classes[:InputEdit] start_pt = point_class.new(start_point[:row], start_point[:column]) old_end_pt = point_class.new(old_end_point[:row], old_end_point[:column]) new_end_pt = point_class.new(new_end_point[:row], new_end_point[:column]) input_edit = input_edit_class.new( start_byte, old_end_byte, new_end_byte, start_pt, old_end_pt, new_end_pt ) @impl.edit(input_edit) end |
#root_node ⇒ Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the root node of the tree
625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/tree_haver/backends/java.rb', line 625 def root_node result = @impl.rootNode # jtreesitter 0.26.0: rootNode() may return Optional<Node> or Node directly java_node = if result.respond_to?(:isPresent) raise TreeHaver::Error, 'Tree has no root node' unless result.isPresent result.get else result end raise TreeHaver::Error, 'Tree has no root node' unless java_node Node.new(java_node) end |