CommentFormattingOptions options, IFormattingContext formattingContext) {
final ICommentFormatterAdvice advice = options.advice;
final String lineSeparator = formattingContext.getLineSeparatorInformation().getLineSeparator();
final String endToken = out.getEndToken();
List<CharSequence> lines = commentText.lines;
TextFlow flow = new TextFlow(formattingContext);
// StringBuilder builder = new StringBuilder();
int indentSize = out.getLeftPosition();
int leftMarginSize = out.getLeftMargin();
if(Alignment.right == out.getMarkerColumnAlignment())
indentSize += out.getMarkerColumnWidth() - out.getRepeatingToken().length();
CharSequence indent = new CharSequences.Spaces(indentSize);
CharSequence leftMargin = new CharSequences.Spaces(leftMarginSize);
ensureTrailingLines(lines, options);
try {
// always process first line even if it is also the last
int limit = Math.max(1, lines.size() - 1);
boolean singleLine = lines.size() == 1;
for(int i = 0; i < limit; i++) {
// comment container
if(i == 0)
flow.append(CharSequences.spaces(out.getLeftPosition())).append(out.getStartToken());
else
flow.append(indent).append(out.getRepeatingToken());
CharSequence s = lines.get(i);
if(s.length() > 0) {
boolean hasBannerLength = s.length() > 4;
boolean alignSpecialLeft = advice.getAlignSpecialLinesLeft();
// Homogeneous lines should not have a leftMargin e.g. '#---' '********' unless advice says so
// anything starting with letter or digit, or that is not homogeneous has a leftMargin
if(Character.isLetterOrDigit(s.charAt(0)) //
||
!(CharSequences.isHomogeneous(s) && (hasBannerLength || alignSpecialLeft)))
flow.append(leftMargin);
flow.append(s);
// // Homogeneous lines should not have a leftMargin e.g. '#---' '********' unless advice says so
// // anything starting with letter or digit, or that is not homogeneous has a leftMargin
// if(Character.isLetterOrDigit(s.charAt(0)) || !advice.getAlignSpecialLinesLeft() ||
// !(CharSequences.isHomogeneous(s)))
// flow.append(leftMargin);
// flow.append(s);
}
if(!singleLine)
flow.append(lineSeparator);
}
// process last line
if(singleLine) {
// last line is the same as the first
if(endToken.length() > 0)
flow.append(" "); // space before end token (if one will be output)
}
else {
CharSequence s = lines.get(limit);
flow.append(indent);
if(s.length() > 0 || out.isSLStyle()) {
flow.append(out.getRepeatingToken());
if(s.length() > 0) {
if(Character.isLetterOrDigit(s.charAt(0)) || !CharSequences.isHomogeneous(s))
flow.append(leftMargin);
flow.append(s);
if(!out.isSLStyle())
flow.append(" "); // a ML comment may be followed by something
}
}
}
if(endToken.length() > 0)
flow.append(out.getEndToken());
// finally append trailing stuff
if(commentText.trailingContainerText.length() > 0)
flow.append(commentText.trailingContainerText);
}
catch(IOException e) {
// can't happen here, since the TextFlow uses a StringBuilder
// TODO: Actually - this is wrong, the API is open
}