* @return the postprocessed code snippet
*/
private String postprocessCodeSnippet(String snippet, String indentation) {
// patch content prefix
StringBuffer buffer= new StringBuffer();
ILineTracker tracker= new DefaultLineTracker();
String patch= indentation + MultiCommentLine.MULTI_COMMENT_CONTENT_PREFIX;
// remove trailing spaces
int i= snippet.length();
while (i > 0 && ' ' == snippet.charAt(i-1))
i--;
snippet= snippet.substring(0, i);
buffer.setLength(0);
String lineDelimiter= getDelimiter();
if (lineDelimiter != null && snippet.indexOf(lineDelimiter) != 0)
buffer.append(lineDelimiter);
buffer.append(convertJava2Html(snippet));
if (lineDelimiter != null && snippet.lastIndexOf(lineDelimiter) != snippet.length() - lineDelimiter.length())
buffer.append(lineDelimiter);
tracker.set(buffer.toString());
for (int line= tracker.getNumberOfLines() - 1; line > 0; line--)
try {
buffer.insert(tracker.getLineOffset(line), patch);
} catch (BadLocationException e) {
// Can not happen
CommentFormatterUtil.log(e);
return snippet;
}