Class: RBI::Rewriters::Annotate

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

Instance Method Summary collapse

Methods inherited from Visitor

#visit_all, #visit_file

Constructor Details

#initialize(annotation, annotate_scopes: false, annotate_properties: false) ⇒ Annotate

: (String annotation, ?annotate_scopes: bool, ?annotate_properties: bool) -> void



8
9
10
11
12
13
# File 'lib/rbi/rewriters/annotate.rb', line 8

def initialize(annotation, annotate_scopes: false, annotate_properties: false)
  super()
  @annotation = annotation
  @annotate_scopes = annotate_scopes
  @annotate_properties = annotate_properties
end

Instance Method Details

#visit(node) ⇒ Object

: (Node? node) -> void



17
18
19
20
21
22
23
24
25
# File 'lib/rbi/rewriters/annotate.rb', line 17

def visit(node)
  case node
  when Scope
    annotate_node(node) if @annotate_scopes || root?(node)
  when Const, Attr, Method, TStructField, TypeMember
    annotate_node(node) if @annotate_properties
  end
  visit_all(node.nodes) if node.is_a?(Tree)
end