private static int compareNodePositions(ASTNode node1, ASTNode node2) {
    if (node1 == node2) return 0;
    
    int o1 = node1.getStartOffsetInParent();
    int o2 = node2.getStartOffsetInParent();
    return o1 != o2 ? Integer.compare(o1, o2) : Integer.compare(getChildIndex(node1), getChildIndex(node2));
  }
private static int compareNodePositions(ASTNode node1, ASTNode node2)