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/sort_nodes.rb,
lib/rbi/rewriters/group_nodes.rb,
lib/rbi/rewriters/merge_trees.rb,
lib/rbi/rewriters/nest_singleton_methods.rb,
lib/rbi/rewriters/nest_non_public_methods.rb

Direct Known Subclasses

ConflictTree, Group, Scope, ScopeConflict, VisibilityGroup

Instance Attribute Summary collapse

Attributes inherited from NodeWithComments

#comments

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from NodeWithComments

#merge_with

Methods inherited from Node

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

Constructor Details

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

Returns a new instance of Tree.



98
99
100
101
102
# File 'lib/rbi/model.rb', line 98

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.



89
90
91
# File 'lib/rbi/model.rb', line 89

def nodes
  @nodes
end

Instance Method Details

#<<(node) ⇒ Object



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

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

#accept_printer(v) ⇒ Object



170
171
172
173
174
# File 'lib/rbi/printer.rb', line 170

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

#empty?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/rbi/model.rb', line 111

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



57
58
59
# File 'lib/rbi/index.rb', line 57

def index
  Index.index(self)
end

#merge(other) ⇒ Object



287
288
289
# File 'lib/rbi/rewriters/merge_trees.rb', line 287

def merge(other)
  Rewriters::Merge.merge_trees(self, other)
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)


177
178
179
# File 'lib/rbi/printer.rb', line 177

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

#sort_nodes!Object



79
80
81
82
# File 'lib/rbi/rewriters/sort_nodes.rb', line 79

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