Class: TreeHaver::Backends::Java::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_haver/backends/java.rb

Overview

Wrapper for java-tree-sitter Node

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#implObject (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

Parameters:

  • index (Integer)

    the child index

Returns:

  • (Node, nil)

    the child node or nil if index out of bounds



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

Parameters:

  • name (String)

    the field name

Returns:

  • (Node, nil)

    the child node or nil if not found



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_countInteger

Get the number of children

Returns:

  • (Integer)

    child count



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

Yields:

  • (Node)

    each child node



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_byteInteger

Get the end byte position

Returns:

  • (Integer)

    end byte



683
684
685
# File 'lib/tree_haver/backends/java.rb', line 683

def end_byte
  @impl.endByte
end

#end_pointHash

Get the end point (row, column)

Returns:

  • (Hash)

    with :row and :column keys



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

Returns:

  • (Boolean)

    true if the node or any descendant 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

Returns:

  • (Boolean)

    true if this is a MISSING node



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

Returns:

  • (Boolean)

    true if this is a named node



720
721
722
# File 'lib/tree_haver/backends/java.rb', line 720

def named?
  @impl.isNamed
end

#next_siblingNode?

Get the next sibling node

Returns:

  • (Node, nil)

    the next sibling or nil if none



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

#parentNode?

Get the parent node

Returns:

  • (Node, nil)

    the parent node or nil if this is the root



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_siblingNode?

Get the previous sibling node

Returns:

  • (Node, nil)

    the previous sibling or nil if none



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_byteInteger

Get the start byte position

Returns:

  • (Integer)

    start byte



676
677
678
# File 'lib/tree_haver/backends/java.rb', line 676

def start_byte
  @impl.startByte
end

#start_pointHash

Get the start point (row, column)

Returns:

  • (Hash)

    with :row and :column keys



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

#textString

Get the text of this node

Returns:

  • (String)

    the source text



760
761
762
# File 'lib/tree_haver/backends/java.rb', line 760

def text
  @impl.text.to_s
end

#typeString

Get the type of this node

Returns:

  • (String)

    the node type



625
626
627
# File 'lib/tree_haver/backends/java.rb', line 625

def type
  @impl.type
end