in experimental/piranha_playground/rule_inference/static_inference.py [0:0]
def find_nodes_to_change(self, node_before: Node, node_after: Node):
"""
Function to find nodes to change if there's only one diverging node.
:param node_before: The node before the change.
:param node_after: The node after the change.
:return: The nodes that need to be changed.
"""
diverging_nodes = []
if node_before.type == node_after.type:
# Check if there's only one and only one diverging node
# If there's more than one, then we can't do anything
diverging_nodes = [
(child_before, child_after)
for child_before, child_after in zip(
node_before.named_children, node_after.named_children
)
if NodeUtils.convert_to_source(child_before)
!= NodeUtils.convert_to_source(child_after)
]
if (
len(diverging_nodes) == 1
and node_before.child_count == node_after.child_count
):
return self.find_nodes_to_change(*diverging_nodes[0])
return node_before, node_after