private static void insertCommentsInCu(CompilationUnit cu,CommentsCollection commentsCollection){
  if (commentsCollection.size() == 0)   return;
  List<Comment> comments=commentsCollection.getAll();
  PositionUtils.sortByBeginPosition(comments);
  List<Node> children=cu.getChildrenNodes();
  PositionUtils.sortByBeginPosition(children);
  if (cu.getPackage() != null && (children.size() == 0 || PositionUtils.areInOrder(comments.get(0),children.get(0)))) {
    cu.setComment(comments.get(0));
    comments.remove(0);
  }
  insertCommentsInNode(cu,comments);
}

private static void insertCommentsInCu ( CompilationUnit cu , CommentsCollection commentsCollection ) { if ( commentsCollection . size ( ) == 0 ) return ; List < Comment > comments = commentsCollection . getAll ( ) ; PositionUtils . sortByBeginPosition ( comments ) ; List < Node > children = cu . getChildrenNodes ( ) ; PositionUtils . sortByBeginPosition ( children ) ; if ( cu . getPackage ( ) != null && ( children . size ( ) == 0 || PositionUtils . areInOrder ( comments . get ( 0 ) , children . get ( 0 ) ) ) ) { cu . setComment ( comments . get ( 0 ) ) ; comments . remove ( 0 ) ; } insertCommentsInNode ( cu , comments ) ; }
comments are attributed to the thing the comment and are removed from allcomments .
