Beispiel #1
0
 /**
  * Returns comments for the given node.
  *
  * @param node the node
  * @param pos the position of the comments
  * @return All comments assigned to the node at this position
  * @since 5.3
  */
 public List<IASTComment> getComments(IASTNode node, CommentPosition pos) {
   switch (pos) {
     case leading:
       return fCommentMap.getLeadingCommentsForNode(node);
     case trailing:
       return fCommentMap.getTrailingCommentsForNode(node);
     case freestanding:
       return fCommentMap.getFreestandingCommentsForNode(node);
   }
   return fCommentMap.getLeadingCommentsForNode(node);
 }
Beispiel #2
0
 /**
  * Assigns the comment to the node.
  *
  * @param node the node.
  * @param comment the comment to be attached to the node at the given position.
  * @param pos the position of the comment.
  * @since 5.3
  */
 public void addComment(IASTNode node, IASTComment comment, CommentPosition pos) {
   switch (pos) {
     case leading:
       fCommentMap.addLeadingCommentToNode(node, comment);
       break;
     case trailing:
       fCommentMap.addTrailingCommentToNode(node, comment);
       break;
     case freestanding:
       fCommentMap.addFreestandingCommentToNode(node, comment);
       break;
   }
 }
Beispiel #3
0
  private int getOffsetIncludingComments(IASTNode node) {
    int nodeOffset = offset(node);

    List<IASTComment> comments = commentMap.getAllCommentsForNode(node);
    if (!comments.isEmpty()) {
      int startOffset = nodeOffset;
      for (IASTComment comment : comments) {
        int commentOffset = offset(comment);
        if (commentOffset < startOffset) {
          startOffset = commentOffset;
        }
      }
      nodeOffset = startOffset;
    }
    return nodeOffset;
  }
Beispiel #4
0
 private int getEndOffsetIncludingTrailingComments(IASTNode node) {
   int endOffset = 0;
   while (true) {
     IASTFileLocation fileLocation = node.getFileLocation();
     if (fileLocation != null) endOffset = Math.max(endOffset, endOffset(fileLocation));
     List<IASTComment> comments = commentMap.getTrailingCommentsForNode(node);
     if (!comments.isEmpty()) {
       for (IASTComment comment : comments) {
         int commentEndOffset = endOffset(comment);
         if (commentEndOffset >= endOffset) {
           endOffset = commentEndOffset;
         }
       }
     }
     IASTNode[] children = node.getChildren();
     if (children.length == 0) break;
     node = children[children.length - 1];
   }
   return endOffset;
 }