Class: TreeHaver::Backends::Java::Tree
- Inherits:
-
Object
- Object
- TreeHaver::Backends::Java::Tree
- Defined in:
- lib/tree_haver/backends/java.rb
Overview
Wrapper for java-tree-sitter Tree
Instance Attribute Summary collapse
-
#impl ⇒ Object
readonly
Returns the value of attribute impl.
Instance Method Summary collapse
-
#edit(start_byte:, old_end_byte:, new_end_byte:, start_point:, old_end_point:, new_end_point:) ⇒ void
Mark the tree as edited for incremental re-parsing.
-
#initialize(impl) ⇒ Tree
constructor
private
A new instance of Tree.
-
#root_node ⇒ Node
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.
560 561 562 |
# File 'lib/tree_haver/backends/java.rb', line 560 def initialize(impl) @impl = impl end |
Instance Attribute Details
#impl ⇒ Object (readonly)
Returns the value of attribute impl.
557 558 559 |
# File 'lib/tree_haver/backends/java.rb', line 557 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 returns an undefined value.
Mark the tree as edited for incremental re-parsing
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/tree_haver/backends/java.rb', line 590 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
Get the root node of the tree
568 569 570 571 572 573 574 575 576 577 578 579 |
# File 'lib/tree_haver/backends/java.rb', line 568 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 |