Class: RBI::Rewriters::TranslateRBSSigs

Inherits:
Visitor
  • Object
show all
Defined in:
lib/rbi/rewriters/translate_rbs_sigs.rb

Overview

Translate all RBS signature comments to Sorbet RBI signatures

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Methods inherited from Visitor

#visit_all, #visit_file

Instance Method Details

#visit(node) ⇒ Object

: (Node? node) -> void



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rbi/rewriters/translate_rbs_sigs.rb', line 12

def visit(node)
  return unless node

  case node
  when Tree
    visit_all(node.nodes)
  when AttrAccessor, AttrReader, AttrWriter
    rbs_comments = extract_rbs_comments(node)
    rbs_comments.each do |comment|
      node.sigs << translate_rbs_attr_type(node, comment)
    end
  when Method
    rbs_comments = extract_rbs_comments(node)
    rbs_comments.each do |comment|
      node.sigs << translate_rbs_method_type(node, comment)
    end
  end
end