Package org.tomlj

Class TomlComment

java.lang.Object
org.tomlj.TomlComment
All Implemented Interfaces:
TomlElement

public final class TomlComment extends Object implements TomlElement
A comment in a TOML document, either attached to an entry or unattached.

A comment attached to an entry is either the run of comment lines directly above it (TomlComment.Placement.ABOVE) or the comment on its line (TomlComment.Placement.AFTER); every other comment is unattached, and belongs to the table or array it was written in. An entry has at most one comment of each placement.

  • Method Details

    • lines

      public List<String> lines()
      The text of each line, one entry per line of the run, in document order.

      Each entry is the text after the #, with one leading space removed if there is one, so # foo and #foo both give foo, while a line written with two spaces keeps its second. A bare # gives an empty string. No entry contains a newline.

      An attached TomlComment.Placement.AFTER comment has exactly one line.

      Returns:
      The text of each line, in document order. Unmodifiable.
    • text

      public String text()
      The lines of this comment, joined with \n.
      Returns:
      The lines of this comment, joined with \n.
    • position

      public @Nullable TomlPosition position()
      The position of the # opening the first line of this comment.

      The lines of a run are contiguous, so line i of the run is on line position().line() + i.

      Specified by:
      position in interface TomlElement
      Returns:
      The position of the # opening the first line, or null if this comment was not read from a document.
    • placement

      public TomlComment.Placement placement()
      Where this comment sits relative to the entry it is attached to.
      Returns:
      TomlComment.Placement.ABOVE or TomlComment.Placement.AFTER for an attached comment, or TomlComment.Placement.UNATTACHED for an unattached one.
    • toString

      public String toString()
      Overrides:
      toString in class Object