Exemple #1
0
 /**
  * Get comment, but no more than a maximum number of characters.
  *
  * @return Start of comment, with ellipses appended if trunceted; null, if node has no comment.
  */
 public static String getCommentStart(ConstNode node, boolean firstLineOnly, int maxChar) {
   String comment = node.getComment();
   if (comment == null) return null;
   boolean trimmed = false;
   if (firstLineOnly) {
     int pos = comment.indexOf("\n");
     if (pos >= 0) {
       comment = comment.substring(0, pos);
       trimmed = true;
     }
   }
   if (comment.length() > maxChar) {
     comment = comment.substring(0, maxChar);
     trimmed = true;
   }
   if (trimmed) {
     if (maxChar > 30) {
       // Try to find a cut-off at a space
       int pos = comment.lastIndexOf(' ');
       if (pos > 20) {
         if (comment.charAt(pos) == '.') --pos;
         comment = comment.substring(0, pos);
       }
     }
     comment = comment + "...";
   }
   return comment;
 }
Exemple #2
0
 /**
  * Check if the comment of the current node contains a pattern.
  *
  * @param node The node to check.
  * @param pattern The pattern.
  * @return <tt>true</tt>, if the current node has a comment and a match for the pattern is found
  *     in the comment.
  */
 public static boolean commentContains(ConstNode node, Pattern pattern) {
   String comment = node.getComment();
   return (comment != null && pattern.matcher(comment).find());
 }