Class: SorbetAutoTyper::SourceRewriter

Inherits:
Parser::TreeRewriter
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/sorbet_auto_typer/source_rewriter.rb

Instance Method Summary collapse

Constructor Details

#initialize(traces) ⇒ SourceRewriter

Returns a new instance of SourceRewriter.



10
11
12
13
14
# File 'lib/sorbet_auto_typer/source_rewriter.rb', line 10

def initialize(traces)
  @traces = traces
  @in_sclass = T.let(false, T::Boolean)
  @signature_counter = 0
end

Instance Method Details

#on_class(node) ⇒ Object



24
25
26
27
28
# File 'lib/sorbet_auto_typer/source_rewriter.rb', line 24

def on_class(node)
  maybe_extend_t_sig(node, (node.children[1] || node.children[0]).loc.expression) do
    super
  end
end

#on_def(node) ⇒ Object



40
41
42
43
# File 'lib/sorbet_auto_typer/source_rewriter.rb', line 40

def on_def(node)
  insert_signature_for_method(node.children[0], node)
  super
end

#on_defs(node) ⇒ Object



45
46
47
48
49
50
# File 'lib/sorbet_auto_typer/source_rewriter.rb', line 45

def on_defs(node)
  in_sclass do
    insert_signature_for_method(node.children[1], node)
    super
  end
end

#on_module(node) ⇒ Object



17
18
19
20
21
# File 'lib/sorbet_auto_typer/source_rewriter.rb', line 17

def on_module(node)
  maybe_extend_t_sig(node, node.children[0].loc.name) do
    super
  end
end

#on_sclass(node) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/sorbet_auto_typer/source_rewriter.rb', line 31

def on_sclass(node)
  maybe_extend_t_sig(node, node.children[0].loc.expression) do
    in_sclass do
      super
    end
  end
end