Class: RBI::Node
- Inherits:
-
Object
show all
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/rbi/model.rb,
lib/rbi/printer.rb,
lib/rbi/rewriters/group_nodes.rb,
lib/rbi/rewriters/merge_trees.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(loc: nil) ⇒ Node
Returns a new instance of Node.
18
19
20
21
|
# File 'lib/rbi/model.rb', line 18
def initialize(loc: nil)
@parent_tree = nil
@loc = loc
end
|
Instance Attribute Details
#loc ⇒ Object
Returns the value of attribute loc.
15
16
17
|
# File 'lib/rbi/model.rb', line 15
def loc
@loc
end
|
#parent_tree ⇒ Object
Returns the value of attribute parent_tree.
12
13
14
|
# File 'lib/rbi/model.rb', line 12
def parent_tree
@parent_tree
end
|
Instance Method Details
#accept_printer(v) ⇒ Object
124
|
# File 'lib/rbi/printer.rb', line 124
def accept_printer(v); end
|
#compatible_with?(_other) ⇒ Boolean
283
284
285
|
# File 'lib/rbi/rewriters/merge_trees.rb', line 283
def compatible_with?(_other)
true
end
|
#detach ⇒ Object
24
25
26
27
28
29
|
# File 'lib/rbi/model.rb', line 24
def detach
tree = parent_tree
return unless tree
tree.nodes.delete(self)
self.parent_tree = nil
end
|
#merge_with(other) ⇒ Object
289
|
# File 'lib/rbi/rewriters/merge_trees.rb', line 289
def merge_with(other); end
|
#oneline? ⇒ Boolean
149
150
151
|
# File 'lib/rbi/printer.rb', line 149
def oneline?
true
end
|
#parent_conflict_tree ⇒ Object
292
293
294
295
296
297
298
299
|
# File 'lib/rbi/rewriters/merge_trees.rb', line 292
def parent_conflict_tree
parent = T.let(parent_tree, T.nilable(Node))
while parent
return parent if parent.is_a?(ConflictTree)
parent = parent.parent_tree
end
nil
end
|
#parent_scope ⇒ Object
43
44
45
46
47
|
# File 'lib/rbi/model.rb', line 43
def parent_scope
parent = T.let(parent_tree, T.nilable(Tree))
parent = parent.parent_tree until parent.is_a?(Scope) || parent.nil?
parent
end
|
#print(out: $stdout, indent: 0, print_locs: false) ⇒ Object
127
128
129
130
|
# File 'lib/rbi/printer.rb', line 127
def print(out: $stdout, indent: 0, print_locs: false)
p = Printer.new(out: out, indent: indent, print_locs: print_locs)
p.visit(self)
end
|
#print_blank_line_before(v) ⇒ Object
140
141
142
143
144
145
146
|
# File 'lib/rbi/printer.rb', line 140
def print_blank_line_before(v)
previous_node = v.previous_node
return unless previous_node
return if previous_node.is_a?(BlankLine)
return if previous_node.oneline? && oneline?
v.printn
end
|
#replace(node) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/rbi/model.rb', line 32
def replace(node)
tree = parent_tree
raise unless tree
index = tree.nodes.index(self)
raise unless index
tree.nodes[index] = node
node.parent_tree = tree
self.parent_tree = nil
end
|
#string(indent: 0, print_locs: false) ⇒ Object
133
134
135
136
137
|
# File 'lib/rbi/printer.rb', line 133
def string(indent: 0, print_locs: false)
out = StringIO.new
print(out: out, indent: indent, print_locs: print_locs)
out.string
end
|