/** * Wraps the comment ranges in this comment region into comment lines. * * @param width the maximal width of text in this comment region measured in average character * widths */ protected void wrapRegion(final int width) { fLines.clear(); int index = 0; boolean adapted = false; CommentLine successor = null; CommentLine predecessor = null; CommentRange previous = null; CommentRange next = null; while (!fRanges.isEmpty()) { index = 0; adapted = false; predecessor = successor; successor = createLine(); fLines.add(successor); while (!fRanges.isEmpty()) { next = (CommentRange) fRanges.getFirst(); if (canAppend(successor, previous, next, index, width)) { if (!adapted && predecessor != null) { successor.adapt(predecessor); adapted = true; } fRanges.removeFirst(); successor.append(next); index += (next.getLength() + 1); previous = next; } else break; } } }