private static void insertCommentsInNode(Node node,List<Comment> commentsToAttribute){
  if (commentsToAttribute.size() == 0)   return;
  List<Node> children=node.getChildrenNodes();
  PositionUtils.sortByBeginPosition(children);
  for (  Node child : children) {
    List<Comment> commentsInsideChild=new LinkedList<Comment>();
    for (    Comment c : commentsToAttribute) {
      if (PositionUtils.nodeContains(child,c,_doNotConsiderAnnotationsAsNodeStartForCodeAttribution)) {
        commentsInsideChild.add(c);
      }
    }
    commentsToAttribute.removeAll(commentsInsideChild);
    insertCommentsInNode(child,commentsInsideChild);
  }
  List<Comment> attributedComments=new LinkedList<Comment>();
  for (  Comment comment : commentsToAttribute) {
    if (comment.isLineComment()) {
      for (      Node child : children) {
        if (child.getEndLine() == comment.getBeginLine()) {
          if (attributeLineCommentToNodeOrChild(child,comment.asLineComment())) {
            attributedComments.add(comment);
          }
        }
      }
    }
  }
  Comment previousComment=null;
  attributedComments=new LinkedList<Comment>();
  List<Node> childrenAndComments=new LinkedList<Node>();
  childrenAndComments.addAll(children);
  childrenAndComments.addAll(commentsToAttribute);
  PositionUtils.sortByBeginPosition(childrenAndComments,_doNotConsiderAnnotationsAsNodeStartForCodeAttribution);
  for (  Node thing : childrenAndComments) {
    if (thing instanceof Comment) {
      previousComment=(Comment)thing;
      if (!previousComment.isOrphan()) {
        previousComment=null;
      }
    }
 else {
      if (previousComment != null && !thing.hasComment()) {
        if (!_doNotAssignCommentsPreceedingEmptyLines || !thereAreLinesBetween(previousComment,thing)) {
          thing.setComment(previousComment);
          attributedComments.add(previousComment);
          previousComment=null;
        }
      }
    }
  }
  commentsToAttribute.removeAll(attributedComments);
  for (  Comment c : commentsToAttribute) {
    if (c.isOrphan()) {
      node.addOrphanComment(c);
    }
  }
}

private static void insertCommentsInNode ( Node node , List < Comment > commentsToAttribute ) { if ( commentsToAttribute . size ( ) == 0 ) return ; List < Node > children = node . getChildrenNodes ( ) ; PositionUtils . sortByBeginPosition ( children ) ; for ( Node child : children ) { List < Comment > commentsInsideChild = new LinkedList < Comment > ( ) ; for ( Comment c : commentsToAttribute ) { if ( PositionUtils . nodeContains ( child , c , _doNotConsiderAnnotationsAsNodeStartForCodeAttribution ) ) { commentsInsideChild . add ( c ) ; } } commentsToAttribute . removeAll ( commentsInsideChild ) ; insertCommentsInNode ( child , commentsInsideChild ) ; } List < Comment > attributedComments = new LinkedList < Comment > ( ) ; for ( Comment comment : commentsToAttribute ) { if ( comment . isLineComment ( ) ) { for ( Node child : children ) { if ( child . getEndLine ( ) == comment . getBeginLine ( ) ) { if ( attributeLineCommentToNodeOrChild ( child , comment . asLineComment ( ) ) ) { attributedComments . add ( comment ) ; } } } } } Comment previousComment = null ; attributedComments = new LinkedList < Comment > ( ) ; List < Node > childrenAndComments = new LinkedList < Node > ( ) ; childrenAndComments . addAll ( children ) ; childrenAndComments . addAll ( commentsToAttribute ) ; PositionUtils . sortByBeginPosition ( childrenAndComments , _doNotConsiderAnnotationsAsNodeStartForCodeAttribution ) ; for ( Node thing : childrenAndComments ) { if ( thing instanceof Comment ) { previousComment = ( Comment ) thing ; if ( ! previousComment . isOrphan ( ) ) { previousComment = null ; } } else { if ( previousComment != null && ! thing . hasComment ( ) ) { if ( ! _doNotAssignCommentsPreceedingEmptyLines || ! thereAreLinesBetween ( previousComment , thing ) ) { thing . setComment ( previousComment ) ; attributedComments . add ( previousComment ) ; previousComment = null ; } } } } commentsToAttribute . removeAll ( attributedComments ) ; for ( Comment c : commentsToAttribute ) { if ( c . isOrphan ( ) ) { node . addOrphanComment ( c ) ; } } }
this method try to attributes the nodes received to child of the node . it returns the node that were not attributed .
