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.



530
531
532
# File 'lib/tree_haver/backends/java.rb', line 530

def initialize(impl)
  @impl = impl
end

Instance Attribute Details

#implObject (readonly)

Returns the value of attribute impl.



527
528
529
# File 'lib/tree_haver/backends/java.rb', line 527

def impl
  @impl
end

Instance Method Details

#child(index) ⇒ Node

Get a child by index

Parameters:

  • index (Integer)

    the child index

Returns:

  • (Node)

    the child node



552
553
554
# File 'lib/tree_haver/backends/java.rb', line 552

def child(index)
  Node.new(@impl.child(index))
end

#child_countInteger

Get the number of children

Returns:

  • (Integer)

    child count



544
545
546
# File 'lib/tree_haver/backends/java.rb', line 544

def child_count
  @impl.childCount
end

#each {|Node| ... } ⇒ void

This method returns an undefined value.

Iterate over children

Yields:

  • (Node)

    each child node



560
561
562
563
564
565
# File 'lib/tree_haver/backends/java.rb', line 560

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



577
578
579
# File 'lib/tree_haver/backends/java.rb', line 577

def end_byte
  @impl.endByte
end

#end_pointHash

Get the end point (row, column)

Returns:

  • (Hash)

    with :row and :column keys



592
593
594
595
# File 'lib/tree_haver/backends/java.rb', line 592

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



600
601
602
# File 'lib/tree_haver/backends/java.rb', line 600

def has_error?
  @impl.hasError
end

#missing?Boolean

Check if this node is missing

Returns:

  • (Boolean)

    true if this is a MISSING node



607
608
609
# File 'lib/tree_haver/backends/java.rb', line 607

def missing?
  @impl.isMissing
end

#start_byteInteger

Get the start byte position

Returns:

  • (Integer)

    start byte



570
571
572
# File 'lib/tree_haver/backends/java.rb', line 570

def start_byte
  @impl.startByte
end

#start_pointHash

Get the start point (row, column)

Returns:

  • (Hash)

    with :row and :column keys



584
585
586
587
# File 'lib/tree_haver/backends/java.rb', line 584

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



614
615
616
# File 'lib/tree_haver/backends/java.rb', line 614

def text
  @impl.text.to_s
end

#typeString

Get the type of this node

Returns:

  • (String)

    the node type



537
538
539
# File 'lib/tree_haver/backends/java.rb', line 537

def type
  @impl.type
end