code: public static String addLineNumbers(final String aMessage) {
          final StringBuilder buffer = new StringBuilder();
          final String[] lines = aMessage.split(EOL);
  
          int lineCount = 1; // Error messages start with line 1
  
          for (final String line : lines) {
              buffer.append(lineCount++).append(' ').append(line);
              buffer.append(EOL);
          }
  
          final int length = buffer.length();
  
          buffer.delete(length - EOL.length(), length);
  
          return buffer.toString();
      }
docs: Adds line numbers to any string. This is useful when I need to debug an XQuery outside the context of an IDE
  (i.e., in debugging output).
  
  @param aMessage Text to which line numbers should be added
  @return The supplied text with line numbers at the first of each line