A strategy to break a series of tokens into multiple lines to accomodate a maximum line length.

no subtypes hierarchy

stringSource Codeshared formal String string

A string representation of the line break strategy, suitable for being saved and loaded via saveProfile() and loadProfile(). parseLineBreakStrategy() should be able to parse it.

Refines Object.string
Inherited Attributes
Attributes inherited from: Object
hash, string
lineBreakLocationSource Codeshared formal [Integer?, Boolean] lineBreakLocation(QueueElement[] elements, Integer offset, Integer maxLineLength)

Determine where the next line break should occur, or return a null index if no line break should occur (e. g. because there aren’t enough tokens).

If the first element of the returned value [i, lb] (index, line break) exists, it means that tokens 0..i should be taken from the elements and written out; if lb is true, a LineBreak should be inserted there first.

To clarify, the caller of this method should react to the returned value [i, lb] like this:

  • If i is null, do nothing.

  • If lb is true, take the elements up to (but not including) i and write them out (removing them from the queue), then write out a line break.

    Equivalently, insert a LineBreak (ceylon.formatter::FormattingWriter.LineBreak) into the queue at index i, then write out the elements up to and including i.

    Afterwards, the element that was previously elements[i] is now the first queued element.

  • If lb is false, take the elements up to and including i and write them out (removing them from the queue). (Do not write out an explicit line break.)

    Afterwards, the element that was previously elements[i + 1] is now the first queued element.

Usually, when an element makes the line too long, its index and true is returned. The false case is necessary for a) existing explicit line breaks, and b) multi-line string literals that don’t make the line too long, but still break the line (but not with an explicit extra line break).

  • elements

    The tokens of the line.

  • offset

    The initial line length, negated if caused by indentation.

    The absolute value is the initial line length. If the value is negative or zero, this line length is indentation only; if it’s positive, it comes from a multi-line token.

    The difference between these cases is that after a multi-line token, it’s reasonable to immediately insert a line break (without writing a single token), whereas doing that if the indentation alone exceeds the maximum line length will lead to an infinite loop.

  • maxLineLength

    The maximum line length.

Inherited Methods
Methods inherited from: Object