예제 #1
0
  public int getOffsetIncludingComments(IASTNode node) {
    int offset = ASTNodes.offset(node);

    // TODO(sprigogin): Iterate backwards and stop at the first blank line.
    List<IASTComment> comments = leadingMap.get(node);
    if (comments != null && !comments.isEmpty()) {
      for (IASTComment comment : comments) {
        int commentOffset = ASTNodes.offset(comment);
        if (commentOffset < offset) {
          offset = commentOffset;
        }
      }
    }
    return offset;
  }
예제 #2
0
 public int getEndOffsetIncludingComments(IASTNode node) {
   int endOffset = 0;
   while (true) {
     IASTFileLocation fileLocation = node.getFileLocation();
     if (fileLocation != null)
       endOffset =
           Math.max(endOffset, fileLocation.getNodeOffset() + fileLocation.getNodeLength());
     List<IASTComment> comments = trailingMap.get(node);
     if (comments != null && !comments.isEmpty()) {
       for (IASTComment comment : comments) {
         int commentEndOffset = ASTNodes.endOffset(comment);
         if (commentEndOffset >= endOffset) {
           endOffset = commentEndOffset;
         }
       }
     }
     IASTNode[] children = node.getChildren();
     if (children.length == 0) break;
     node = children[children.length - 1];
   }
   return endOffset;
 }