Class: RBI::Tree

Inherits:
NodeWithComments show all
Extended by:
T::Sig
Defined in:
lib/rbi/index.rb,
lib/rbi/model.rb,
lib/rbi/printer.rb,
lib/rbi/rewriters/annotate.rb,
lib/rbi/rewriters/deannotate.rb,
lib/rbi/rewriters/sort_nodes.rb,
lib/rbi/rewriters/group_nodes.rb,
lib/rbi/rewriters/merge_trees.rb,
lib/rbi/rewriters/add_sig_templates.rb,
lib/rbi/rewriters/nest_singleton_methods.rb,
lib/rbi/rewriters/nest_non_public_methods.rb

Instance Attribute Summary collapse

Attributes inherited from NodeWithComments

#comments

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from NodeWithComments

#annotations, #merge_with

Methods inherited from Node

#compatible_with?, #detach, #group_kind, #merge_with, #parent_conflict_tree, #parent_scope, #print, #print_blank_line_before, #replace, #string

Constructor Details

#initialize(loc: nil, comments: [], &block) ⇒ Tree

Returns a new instance of Tree.



115
116
117
118
119
# File 'lib/rbi/model.rb', line 115

def initialize(loc: nil, comments: [], &block)
  super(loc: loc, comments: comments)
  @nodes = T.let([], T::Array[Node])
  block&.call(self)
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



106
107
108
# File 'lib/rbi/model.rb', line 106

def nodes
  @nodes
end

Instance Method Details

#<<(node) ⇒ Object



122
123
124
125
# File 'lib/rbi/model.rb', line 122

def <<(node)
  node.parent_tree = self
  @nodes << node
end

#accept_printer(v) ⇒ Object



196
197
198
199
200
# File 'lib/rbi/printer.rb', line 196

def accept_printer(v)
  v.visit_all(comments)
  v.printn if !comments.empty? && !empty?
  v.visit_all(nodes)
end

#add_sig_templates!(with_todo_comment: true) ⇒ Object



66
67
68
69
# File 'lib/rbi/rewriters/add_sig_templates.rb', line 66

def add_sig_templates!(with_todo_comment: true)
  visitor = Rewriters::AddSigTemplates.new(with_todo_comment: with_todo_comment)
  visitor.visit(self)
end

#annotate!(annotation, annotate_scopes: false, annotate_properties: false) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/rbi/rewriters/annotate.rb', line 48

def annotate!(annotation, annotate_scopes: false, annotate_properties: false)
  visitor = Rewriters::Annotate.new(
    annotation,
    annotate_scopes: annotate_scopes,
    annotate_properties: annotate_properties
  )
  visitor.visit(self)
end

#deannotate!(annotation) ⇒ Object



40
41
42
43
# File 'lib/rbi/rewriters/deannotate.rb', line 40

def deannotate!(annotation)
  visitor = Rewriters::Deannotate.new(annotation)
  visitor.visit(self)
end

#empty?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/rbi/model.rb', line 128

def empty?
  nodes.empty?
end

#group_nodes!Object



38
39
40
41
# File 'lib/rbi/rewriters/group_nodes.rb', line 38

def group_nodes!
  visitor = Rewriters::GroupNodes.new
  visitor.visit(self)
end

#indexObject



64
65
66
# File 'lib/rbi/index.rb', line 64

def index
  Index.index(self)
end

#merge(other, left_name: "left", right_name: "right", keep: Rewriters::Merge::Keep::NONE) ⇒ Object



318
319
320
# File 'lib/rbi/rewriters/merge_trees.rb', line 318

def merge(other, left_name: "left", right_name: "right", keep: Rewriters::Merge::Keep::NONE)
  Rewriters::Merge.merge_trees(self, other, left_name: left_name, right_name: right_name, keep: keep)
end

#nest_non_public_methods!Object



45
46
47
48
# File 'lib/rbi/rewriters/nest_non_public_methods.rb', line 45

def nest_non_public_methods!
  visitor = Rewriters::NestNonPublicMethods.new
  visitor.visit(self)
end

#nest_singleton_methods!Object



35
36
37
38
# File 'lib/rbi/rewriters/nest_singleton_methods.rb', line 35

def nest_singleton_methods!
  visitor = Rewriters::NestSingletonMethods.new
  visitor.visit(self)
end

#oneline?Boolean

Returns:

  • (Boolean)


203
204
205
# File 'lib/rbi/printer.rb', line 203

def oneline?
  comments.empty? && empty?
end

#sort_nodes!Object



89
90
91
92
# File 'lib/rbi/rewriters/sort_nodes.rb', line 89

def sort_nodes!
  visitor = Rewriters::SortNodes.new
  visitor.visit(self)
end