Class: TreeHaver::Backends::Java::Node Private
- Inherits:
-
Object
- Object
- TreeHaver::Backends::Java::Node
- 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 node wrapper (raw backend node)
This is a raw backend node that wraps a jtreesitter Node object via JRuby's Java interop. It provides the minimal interface needed for tree-sitter operations but is NOT intended for direct use by application code.
Architecture Note
Unlike pure-Ruby backends (Citrus, Parslet, Prism, Psych) which define Node
classes that inherit from TreeHaver::Base::Node, tree-sitter backends (MRI,
Rust, FFI, Java) define raw wrapper classes that get wrapped by TreeHaver::Node.
The wrapping hierarchy is:
Java::Node (this class) → TreeHaver::Node → Base::Node
When you use TreeHaver::Parser#parse, the returned tree's nodes are already
wrapped in TreeHaver::Node, which provides the full unified API including:
#children- Array of child nodes#text- Extract text from source#first_child,#last_child- Convenience accessors#start_line,#end_line- 1-based line numbers#source_position- Hash with position info#each,#map, etc. - Enumerable methods#to_s,#inspect- String representations
This raw class only implements methods that require direct calls to jtreesitter. The wrapper adds Ruby-level conveniences.
Instance Attribute Summary collapse
- #impl ⇒ Object readonly private
Instance Method Summary collapse
-
#child(index) ⇒ Node?
private
Get a child by index.
-
#child_by_field_name(name) ⇒ Node?
private
Get a child by field name.
-
#child_count ⇒ Integer
private
Get the number of children.
-
#each {|Node| ... } ⇒ void
private
Iterate over children.
-
#end_byte ⇒ Integer
private
Get the end byte position.
-
#end_point ⇒ Hash
private
Get the end point (row, column).
-
#has_error? ⇒ Boolean
private
Check if this node has an error.
-
#initialize(impl) ⇒ Node
constructor
private
A new instance of Node.
-
#missing? ⇒ Boolean
private
Check if this node is missing.
-
#named? ⇒ Boolean
private
Check if this is a named node.
-
#next_sibling ⇒ Node?
private
Get the next sibling node.
-
#parent ⇒ Node?
private
Get the parent node.
-
#prev_sibling ⇒ Node?
private
Get the previous sibling node.
-
#start_byte ⇒ Integer
private
Get the start byte position.
-
#start_point ⇒ Hash
private
Get the start point (row, column).
-
#text ⇒ String
private
Get the text of this node.
-
#type ⇒ String
private
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.
706 707 708 |
# File 'lib/tree_haver/backends/java.rb', line 706 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.
703 704 705 |
# File 'lib/tree_haver/backends/java.rb', line 703 def impl @impl end |
Instance Method Details
#child(index) ⇒ 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 a child by index
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
# File 'lib/tree_haver/backends/java.rb', line 728 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?
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 a child by field name
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 |
# File 'lib/tree_haver/backends/java.rb', line 752 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
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 number of children
720 721 722 |
# File 'lib/tree_haver/backends/java.rb', line 720 def child_count @impl.childCount end |
#each {|Node| ... } ⇒ 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.
Iterate over children
775 776 777 778 779 780 781 |
# File 'lib/tree_haver/backends/java.rb', line 775 def each return enum_for(:each) unless block_given? child_count.times do |i| yield child(i) end end |
#end_byte ⇒ Integer
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 end byte position
793 794 795 |
# File 'lib/tree_haver/backends/java.rb', line 793 def end_byte @impl.endByte end |
#end_point ⇒ Hash
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 end point (row, column)
808 809 810 811 |
# File 'lib/tree_haver/backends/java.rb', line 808 def end_point pt = @impl.endPoint { row: pt.row, column: pt.column } end |
#has_error? ⇒ Boolean
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.
Check if this node has an error
816 817 818 |
# File 'lib/tree_haver/backends/java.rb', line 816 def has_error? @impl.hasError end |
#missing? ⇒ Boolean
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.
Check if this node is missing
823 824 825 |
# File 'lib/tree_haver/backends/java.rb', line 823 def missing? @impl.isMissing end |
#named? ⇒ Boolean
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.
Check if this is a named node
830 831 832 |
# File 'lib/tree_haver/backends/java.rb', line 830 def named? @impl.isNamed end |
#next_sibling ⇒ 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 next sibling node
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
# File 'lib/tree_haver/backends/java.rb', line 857 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?
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 parent node
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 |
# File 'lib/tree_haver/backends/java.rb', line 837 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?
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 previous sibling node
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 |
# File 'lib/tree_haver/backends/java.rb', line 877 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
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 start byte position
786 787 788 |
# File 'lib/tree_haver/backends/java.rb', line 786 def start_byte @impl.startByte end |
#start_point ⇒ Hash
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 start point (row, column)
800 801 802 803 |
# File 'lib/tree_haver/backends/java.rb', line 800 def start_point pt = @impl.startPoint { row: pt.row, column: pt.column } end |
#text ⇒ String
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 text of this node
897 898 899 |
# File 'lib/tree_haver/backends/java.rb', line 897 def text @impl.text.to_s end |
#type ⇒ String
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 type of this node
713 714 715 |
# File 'lib/tree_haver/backends/java.rb', line 713 def type @impl.type end |