Class Comment

All Implemented Interfaces:
Formattable, Serializable, Cloneable

public class Comment extends Compound
Arranges all sub-formats decorated as comments. This format is foreseen for longer and multi-line comments: All sub-formats are printed as in a "beneath" format. The space for payload text is smaller than elsewhere, because every printed line is led in by a selectable prefix. Additionally a top and a bottom line can be added, for arrangements as known from the Java api doc format, etc.:
    [[
    // one sub-format
    // the next sub-format
    ]]
  

(Shorter comments embedded in a text line must be constructed otherwise.)

This format is special because the line prefices must be inserted "physically" into the lower level layouts, always at the start of an output line. Therefore they are handled by the FormatPrinter directly. Currently comments cannot be nested. This is detected not before trying to print them.

See Also:
  • Field Details

    • linePrefix

      public final String linePrefix
      String to lead in all inner lines, and the first line if prefix is null.
    • suffix

      @Opt public final @Opt String suffix
      String to lead in one additional closing line.
  • Constructor Details

    • Comment

      protected Comment(@Opt @Opt String prefix, String linePrefix, @Opt @Opt String suffix, List<Format> f)
      A constructor with some field values explicit, some calculated from the subformats. In contrast to the factory methods, denormalized instances may be constructed.
      Parameters:
      prefix - the string to lead in the first line
      linePrefix - the string to lead in all inner lines, and the first line if prefix is null.
      suffix - the string to lead in an additional last line, if not null.
      f - the commented lines, printed as in an implicit beneath format.
    • Comment

      protected Comment(@Opt @Opt String prefix, String linePrefix, @Opt @Opt String suffix, Format... f)
      A constructor with some field values explicit, some calculated from the subformats. In contrast to the factory methods, denormalized instances may be constructed.
      Parameters:
      prefix - the string to lead in the first line
      linePrefix - the string to lead in all inner lines, and the first line if prefix is null.
      suffix - the string to lead in an additional last line, if not null.
      f - the commented lines, printed as in an implicit beneath format.
      See Also:
    • Comment

      protected Comment(int i, int a, boolean m, boolean g, int ind, String prefix, String linePrefix, String suffix, List<Format> f)
      The constructor which sets all field values explicitly. Consistency of the attributes must be realized by the caller. In contrast to the factory methods, denormalized instances may be constructed.
      Parameters:
      i - the minimal width of the format
      a - the maximal width of the format
      m - whether the format will print to multiple lines anyhow
      g - whether the format does not contain any variable
      ind - the indentation value of this format
      prefix - the string to lead in the first line
      linePrefix - the string to lead in all inner lines, and the first line if prefix is null.
      suffix - the string to lead in an additional last line, if not null.
      f - the commented lines
      Throws:
      IllegalArgumentException - if ident value not valid, see Format.checkValidIndent(int)
      See Also:
  • Method Details

    • indent

      public Compound indent(int ind)
      Description copied from class: Format
      Returns a clone of this with the new value of Format.indent.
      Overrides:
      indent in class Compound
      Parameters:
      ind - the new value for indent.
      Returns:
      an new format with identical values but i, or this, if i is its indent value.
    • constructor

      public CompoundConstructor constructor()
      Unsupported Operation. Comment is a Compound, but it is special as it is not freely compositional. It thus has no corresponding CompoundConstructor.
      Specified by:
      constructor in class Compound
      Returns:
      the reification of the constructor of this instance.
    • mutate

      public Comment mutate(Consumer<List<Format>> mapSubs)
      Description copied from class: Compound
      Creates a new instance of the same class as this instance, or an optimized variant. which contains as subformats all formats in a modified list. The list is modified arbitrarily in an "imperative" way, i.e. it can be altered or extended or totally cleared.

      The resulting list is fed into a factory method; therefore optimization applies and the returned type can be the singleton contents or an instance of Empty.

      Overrides:
      mutate in class Compound
      Parameters:
      mapSubs - the code to apply to the list of all subformats
      Returns:
      a new format which contains the all formats in the modified list
    • doprint

      protected void doprint(FormatPrinter v)
      Description copied from class: Format
      Over-ridden by all sub-classes of Format, for performing the print operations.
      Specified by:
      doprint in class Format
      Parameters:
      v - realizes the dynamic context for printing