Class: RBI::Rewriters::Merge::ConflictTreeMerger
- Defined in:
- lib/rbi/rewriters/merge_trees.rb
Overview
Merge adjacent conflict trees
Transform this: ~~~rb class Foo
<<<<<<< left
def m1; end
=======
def m1(a); end
>>>>>>> right
<<<<<<< left
def m2(a); end
=======
def m2; end
>>>>>>> right
end ~~~
Into this: ~~~rb class Foo
<<<<<<< left
def m1; end
def m2(a); end
=======
def m1(a); end
def m2; end
>>>>>>> right
end ~~~
Instance Method Summary collapse
Methods inherited from Visitor
Instance Method Details
#visit(node) ⇒ Object
247 248 249 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 247 def visit(node) visit_all(node.nodes) if node.is_a?(Tree) end |
#visit_all(nodes) ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 252 def visit_all(nodes) last_conflict_tree = T.let(nil, T.nilable(ConflictTree)) nodes.dup.each do |node| if node.is_a?(ConflictTree) if last_conflict_tree merge_conflict_trees(last_conflict_tree.left, node.left) merge_conflict_trees(last_conflict_tree.right, node.right) node.detach next else last_conflict_tree = node end end visit(node) end end |