Class: TreeHaver::Backends::Java::Node
- Inherits:
-
Object
- Object
- TreeHaver::Backends::Java::Node
- Defined in:
- lib/tree_haver/backends/java.rb
Overview
Wrapper for java-tree-sitter Node
Instance Attribute Summary collapse
-
#impl ⇒ Object
readonly
Returns the value of attribute impl.
Instance Method Summary collapse
-
#child(index) ⇒ Node?
Get a child by index.
-
#child_by_field_name(name) ⇒ Node?
Get a child by field name.
-
#child_count ⇒ Integer
Get the number of children.
-
#each {|Node| ... } ⇒ void
Iterate over children.
-
#end_byte ⇒ Integer
Get the end byte position.
-
#end_point ⇒ Hash
Get the end point (row, column).
-
#has_error? ⇒ Boolean
Check if this node has an error.
-
#initialize(impl) ⇒ Node
constructor
private
A new instance of Node.
-
#missing? ⇒ Boolean
Check if this node is missing.
-
#named? ⇒ Boolean
Check if this is a named node.
-
#next_sibling ⇒ Node?
Get the next sibling node.
-
#parent ⇒ Node?
Get the parent node.
-
#prev_sibling ⇒ Node?
Get the previous sibling node.
-
#start_byte ⇒ Integer
Get the start byte position.
-
#start_point ⇒ Hash
Get the start point (row, column).
-
#text ⇒ String
Get the text of this node.
-
#type ⇒ String
Get the type of this node.
Constructor Details
#initialize(impl) ⇒ 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.
Returns a new instance of Node.
618 619 620 |
# File 'lib/tree_haver/backends/java.rb', line 618 def initialize(impl) @impl = impl end |
Instance Attribute Details
#impl ⇒ Object (readonly)
Returns the value of attribute impl.
615 616 617 |
# File 'lib/tree_haver/backends/java.rb', line 615 def impl @impl end |
Instance Method Details
#child(index) ⇒ Node?
Get a child by index
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 |
# File 'lib/tree_haver/backends/java.rb', line 640 def child(index) # jtreesitter 0.26.0: getChild returns Optional<Node> or throws IndexOutOfBoundsException result = @impl.getChild(index) return if result.nil? # Handle Java Optional if result.respond_to?(:isPresent) return unless result.isPresent java_node = result.get else # Direct Node return (some jtreesitter versions) java_node = result end Node.new(java_node) rescue ::Java::JavaLang::IndexOutOfBoundsException nil end |
#child_by_field_name(name) ⇒ Node?
Get a child by field name
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 |
# File 'lib/tree_haver/backends/java.rb', line 663 def child_by_field_name(name) # jtreesitter 0.26.0: getChildByFieldName returns Optional<Node> # However, some versions or scenarios may return null directly result = @impl.getChildByFieldName(name) return if result.nil? # Handle Java Optional if result.respond_to?(:isPresent) return unless result.isPresent java_node = result.get else # Direct Node return (some jtreesitter versions) java_node = result end Node.new(java_node) end |
#child_count ⇒ Integer
Get the number of children
632 633 634 |
# File 'lib/tree_haver/backends/java.rb', line 632 def child_count @impl.childCount end |
#each {|Node| ... } ⇒ void
This method returns an undefined value.
Iterate over children
685 686 687 688 689 690 |
# File 'lib/tree_haver/backends/java.rb', line 685 def each return enum_for(:each) unless block_given? child_count.times do |i| yield child(i) end end |
#end_byte ⇒ Integer
Get the end byte position
702 703 704 |
# File 'lib/tree_haver/backends/java.rb', line 702 def end_byte @impl.endByte end |
#end_point ⇒ Hash
Get the end point (row, column)
717 718 719 720 |
# File 'lib/tree_haver/backends/java.rb', line 717 def end_point pt = @impl.endPoint {row: pt.row, column: pt.column} end |
#has_error? ⇒ Boolean
Check if this node has an error
725 726 727 |
# File 'lib/tree_haver/backends/java.rb', line 725 def has_error? @impl.hasError end |
#missing? ⇒ Boolean
Check if this node is missing
732 733 734 |
# File 'lib/tree_haver/backends/java.rb', line 732 def missing? @impl.isMissing end |
#named? ⇒ Boolean
Check if this is a named node
739 740 741 |
# File 'lib/tree_haver/backends/java.rb', line 739 def named? @impl.isNamed end |
#next_sibling ⇒ Node?
Get the next sibling node
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 |
# File 'lib/tree_haver/backends/java.rb', line 765 def next_sibling # jtreesitter 0.26.0: getNextSibling returns Optional<Node> result = @impl.getNextSibling return if result.nil? # Handle Java Optional if result.respond_to?(:isPresent) return unless result.isPresent java_node = result.get else java_node = result end Node.new(java_node) end |
#parent ⇒ Node?
Get the parent node
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
# File 'lib/tree_haver/backends/java.rb', line 746 def parent # jtreesitter 0.26.0: getParent returns Optional<Node> result = @impl.getParent return if result.nil? # Handle Java Optional if result.respond_to?(:isPresent) return unless result.isPresent java_node = result.get else java_node = result end Node.new(java_node) end |
#prev_sibling ⇒ Node?
Get the previous sibling node
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
# File 'lib/tree_haver/backends/java.rb', line 784 def prev_sibling # jtreesitter 0.26.0: getPrevSibling returns Optional<Node> result = @impl.getPrevSibling return if result.nil? # Handle Java Optional if result.respond_to?(:isPresent) return unless result.isPresent java_node = result.get else java_node = result end Node.new(java_node) end |
#start_byte ⇒ Integer
Get the start byte position
695 696 697 |
# File 'lib/tree_haver/backends/java.rb', line 695 def start_byte @impl.startByte end |
#start_point ⇒ Hash
Get the start point (row, column)
709 710 711 712 |
# File 'lib/tree_haver/backends/java.rb', line 709 def start_point pt = @impl.startPoint {row: pt.row, column: pt.column} end |
#text ⇒ String
Get the text of this node
803 804 805 |
# File 'lib/tree_haver/backends/java.rb', line 803 def text @impl.text.to_s end |
#type ⇒ String
Get the type of this node
625 626 627 |
# File 'lib/tree_haver/backends/java.rb', line 625 def type @impl.type end |