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 |
# 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 unless result.respond_to?(:isPresent) ? result.isPresent : result java_node = result.respond_to?(:get) ? result.get : result Node.new(java_node) rescue ::Java::JavaLang::IndexOutOfBoundsException nil end |
#child_by_field_name(name) ⇒ Node?
Get a child by field name
654 655 656 657 658 659 660 |
# File 'lib/tree_haver/backends/java.rb', line 654 def child_by_field_name(name) # jtreesitter 0.26.0: getChildByFieldName returns Optional<Node> result = @impl.getChildByFieldName(name) return unless result.respond_to?(:isPresent) ? result.isPresent : result java_node = result.respond_to?(:get) ? result.get : result 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
666 667 668 669 670 671 |
# File 'lib/tree_haver/backends/java.rb', line 666 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
683 684 685 |
# File 'lib/tree_haver/backends/java.rb', line 683 def end_byte @impl.endByte end |
#end_point ⇒ Hash
Get the end point (row, column)
698 699 700 701 |
# File 'lib/tree_haver/backends/java.rb', line 698 def end_point pt = @impl.endPoint {row: pt.row, column: pt.column} end |
#has_error? ⇒ Boolean
Check if this node has an error
706 707 708 |
# File 'lib/tree_haver/backends/java.rb', line 706 def has_error? @impl.hasError end |
#missing? ⇒ Boolean
Check if this node is missing
713 714 715 |
# File 'lib/tree_haver/backends/java.rb', line 713 def missing? @impl.isMissing end |
#named? ⇒ Boolean
Check if this is a named node
720 721 722 |
# File 'lib/tree_haver/backends/java.rb', line 720 def named? @impl.isNamed end |
#next_sibling ⇒ Node?
Get the next sibling node
738 739 740 741 742 743 744 |
# File 'lib/tree_haver/backends/java.rb', line 738 def next_sibling # jtreesitter 0.26.0: getNextSibling returns Optional<Node> result = @impl.getNextSibling return unless result.respond_to?(:isPresent) ? result.isPresent : result java_node = result.respond_to?(:get) ? result.get : result Node.new(java_node) end |
#parent ⇒ Node?
Get the parent node
727 728 729 730 731 732 733 |
# File 'lib/tree_haver/backends/java.rb', line 727 def parent # jtreesitter 0.26.0: getParent returns Optional<Node> result = @impl.getParent return unless result.respond_to?(:isPresent) ? result.isPresent : result java_node = result.respond_to?(:get) ? result.get : result Node.new(java_node) end |
#prev_sibling ⇒ Node?
Get the previous sibling node
749 750 751 752 753 754 755 |
# File 'lib/tree_haver/backends/java.rb', line 749 def prev_sibling # jtreesitter 0.26.0: getPrevSibling returns Optional<Node> result = @impl.getPrevSibling return unless result.respond_to?(:isPresent) ? result.isPresent : result java_node = result.respond_to?(:get) ? result.get : result Node.new(java_node) end |
#start_byte ⇒ Integer
Get the start byte position
676 677 678 |
# File 'lib/tree_haver/backends/java.rb', line 676 def start_byte @impl.startByte end |
#start_point ⇒ Hash
Get the start point (row, column)
690 691 692 693 |
# File 'lib/tree_haver/backends/java.rb', line 690 def start_point pt = @impl.startPoint {row: pt.row, column: pt.column} end |
#text ⇒ String
Get the text of this node
760 761 762 |
# File 'lib/tree_haver/backends/java.rb', line 760 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 |