/** * Comments are attributed to the thing the comment and are removed from * allComments. */ private static void insertCommentsInCu(CompilationUnit cu, CommentsCollection commentsCollection){ if (commentsCollection.size()==0) return; // I should sort all the direct children and the comments, if a comment is the first thing then it // a comment to the CompilationUnit // FIXME if there is no package it could be also a comment to the following class... // so I could use some heuristics in these cases to distinguish the two cases List<Comment> comments = commentsCollection.getAll(); sortByBeginPosition(comments); List<Node> children = cu.getChildrenNodes(); sortByBeginPosition(children); if (cu.getPackage()!=null && (children.size()==0 || areInOrder(comments.get(0), children.get(0)))){ cu.setComment(comments.get(0)); comments.remove(0); } insertCommentsInNode(cu,comments); }