Class CodeDocumentPart

java.lang.Object
com.pnfsoftware.jeb.core.output.code.CodeDocumentPart
All Implemented Interfaces:
ICodeDocument, ITextDocumentPart
Direct Known Subclasses:
CppLikeDocumentPart

public abstract class CodeDocumentPart extends Object implements ITextDocumentPart, ICodeDocument
A document part specific to code outputs. Use with CodeDocument Remember to call registerAnchor(java.lang.String) before generating content at a given anchor point.

The type of ILine used is CodeLine. The type of IAnchor used is CodeAnchor.

Clients must extend this class.

  • Field Details

    • paddingString

      protected String paddingString
    • indentString

      protected String indentString
  • Constructor Details

    • CodeDocumentPart

      public CodeDocumentPart(long baseAnchorId)
      Create a new code document part, attached to the given anchor. An 8-space padding and a 4-space indentation is selected by default.
      Parameters:
      baseAnchorId - the base anchor identifier
  • Method Details

    • getLines

      public List<CodeLine> getLines()
      Description copied from interface: ITextDocumentPart
      Get the lines within that part. The lines may span over one or more anchors.
      Specified by:
      getLines in interface ITextDocumentPart
      Returns:
      the list of lines
    • getLine

      public CodeLine getLine(int index)
      Specified by:
      getLine in interface ITextDocumentPart
      Returns:
    • getAnchors

      public List<CodeAnchor> getAnchors()
      Description copied from interface: ITextDocumentPart
      Get the anchors within that part. The last anchor object may be used to specify the first anchor id of the next, contiguous part. It is especially useful in cases where a line spans multiple anchor ids.
      Specified by:
      getAnchors in interface ITextDocumentPart
      Returns:
      the list of anchors
    • registerAnchor

      public boolean registerAnchor(String name)
      Create an anchor using the current (next) anchor id, and register it at the current last line.
      Parameters:
      name - the anchor name
      Returns:
      true if the anchor was successfully registered
    • registerAnchor

      public boolean registerAnchor(long anchorId, String name)
      Create an anchor with the provided anchor id, and register it at the current last line.
      Parameters:
      anchorId -
      name -
      Returns:
      true if the anchor was successfully registered
    • getCurrentAnchor

      public CodeAnchor getCurrentAnchor()
      Get the currently active anchor.
      Returns:
    • getLineCount

      public int getLineCount()
      Get the number of finished (EOL-terminated) lines in this part. A line is finished by calling eol().
      Returns:
      the number of lines, excluding the last (unfinished) line
    • getCurrentLineIndex

      public int getCurrentLineIndex()
      Returns:
      the line count
    • getLastLineIndex

      public int getLastLineIndex()
      Get the index of the last finished line.
      Returns:
      the last finished line index
    • getCurrentLine

      public CodeLine getCurrentLine()
      Get the last (unfinished) line
      Returns:
      the last line
    • getCurrentLineLength

      public int getCurrentLineLength()
    • isCurrentLineEmpty

      public boolean isCurrentLineEmpty()
    • setIndentationString

      public void setIndentationString(String indentString)
    • getIndentationString

      public String getIndentationString()
    • setPaddingString

      public void setPaddingString(String paddingString)
    • resetPaddingString

      public void resetPaddingString()
    • enablePadding

      public void enablePadding()
    • disablePadding

      public void disablePadding()
    • indentReset

      public void indentReset()
    • getIndentationLevel

      public int getIndentationLevel()
    • setIndentationLevel

      public void setIndentationLevel(int level)
    • incrementIndentationLevel

      public void incrementIndentationLevel()
    • decrementIndentationLevel

      public void decrementIndentationLevel()
    • getCurrentMarginLength

      public int getCurrentMarginLength()
    • enableTokenFlattening

      public static boolean enableTokenFlattening(boolean enabled)
      Enable or disable token flattening. This method is reserved for internal use. Refer to the Engines property FlattenStringsInCodeDocuments if you wish to modify whether tokens should be flattened when they are appended to a text document.
      Parameters:
      enabled -
      Returns:
      the previous setting
    • append

      public void append(String s, int[] aActualInsertionIndex)
      Append a chunk of text to the current line. The line should not contain CR/LF characters.
      Parameters:
      s - chunk of text, should not contain CR or LF characters. If found, they are replaced by slash ('/') characters
      aActualInsertionIndex - optional: set the index of the inserted string (can be different from current index because of padding) at 0-index
    • append

      public void append(String s)
      Specified by:
      append in interface ICodeDocument
    • append

      public void append(String str, ItemClassIdentifiers classId)
      Specified by:
      append in interface ICodeDocument
    • appendMulti

      public void appendMulti(String s)
    • space

      public void space()
      Append a space to the current line.
    • space

      public void space(int cnt)
      Append one or more spaces to the current line.
      Parameters:
      cnt - the number of spaces to be appended; may be <= 0, in which case, this method will do nothing
    • setParameterSeparator

      public void setParameterSeparator(String parameterSeparator)
      Set the parameter separator. Default is ", ".
      Parameters:
      parameterSeparator - new parameter separator
    • appendParameterSeparator

      public void appendParameterSeparator()
      Append a parameter separator to the current line. Use setParameterSeparator(String) to override default.
    • registerKeyword

      protected int registerKeyword(String keyword)
      Register a keyword for future fast appending. Use for frequent keywords to bypass some internal checks.
      Parameters:
      keyword - a keyword ".", ";" for example...
      Returns:
      the id of the keyword;
    • appendKeyword

      protected void appendKeyword(int id)
    • eol

      public void eol(ICodeCoordinates lineCoord)
      End the current line.
      Parameters:
      lineCoord - optional chunk coordinates
    • eol

      public void eol()
      End the current line.
    • paren

      public void paren()
      Specified by:
      paren in interface ICodeDocument
    • parenClose

      public void parenClose()
      Specified by:
      parenClose in interface ICodeDocument
    • brace

      public void brace()
      Specified by:
      brace in interface ICodeDocument
    • braceClose

      public void braceClose()
      Specified by:
      braceClose in interface ICodeDocument
    • bracket

      public void bracket()
      Specified by:
      bracket in interface ICodeDocument
    • bracketClose

      public void bracketClose()
      Specified by:
      bracketClose in interface ICodeDocument
    • appendAndRecord

      public void appendAndRecord(String s, ItemClassIdentifiers classId)
      Append a chunk of text to the current line.
      Parameters:
      s - a string
      classId - a class identifier
    • appendAndRecord

      public void appendAndRecord(String s, ItemClassIdentifiers classId, long itemId)
      Append a chunk of text to the current line.
      Parameters:
      s - a string
      classId - a class identifier
      itemId - an item identifier
    • appendAndRecord

      public void appendAndRecord(String s, ItemClassIdentifiers classId, long itemId, int flags)
      Append a chunk of text to the current line.
      Parameters:
      s - a string
      classId - a class identifier
      itemId - an item identifier
      flags - flags
    • appendKeyword

      public void appendKeyword(String keyword)
      Description copied from interface: ICodeDocument
      Convenience method.
      Specified by:
      appendKeyword in interface ICodeDocument
    • appendKeyword

      public void appendKeyword(String keyword, long itemId)
    • appendComment

      public void appendComment(String text)
    • appendComment

      public void appendComment(String text, boolean auto)
    • appendCommentAuto

      public void appendCommentAuto(String text)
    • recordLineCoordinates

      public void recordLineCoordinates(ICodeCoordinates coordinates)
    • unrecordLineCoordinates

      public void unrecordLineCoordinates()
    • getCurrentLineCoordinates

      public ICodeCoordinates getCurrentLineCoordinates()
    • getCurrentMostPreciseCodeCoordinates

      public ICodeCoordinates getCurrentMostPreciseCodeCoordinates()
    • recordCurrentCoordinates

      public void recordCurrentCoordinates(ICodeCoordinates coordinates)
    • unrecordCurrentCoordinates

      public void unrecordCurrentCoordinates()
    • getCurrentCoordinates

      public ICodeCoordinates getCurrentCoordinates()
    • validate

      public void validate()
    • prependCodePart

      public void prependCodePart(CodeDocumentPart part)
    • moveLine

      public boolean moveLine(int index, int newIndex)
    • moveLastLine

      public boolean moveLastLine(int newIndex)
    • markCurrentPosition

      public void markCurrentPosition(String name, Object object)
    • format

      public String format()
    • recordObjectLocation

      public void recordObjectLocation(Object object, boolean begin, int depth)
    • getObjectLocations

      public List<ObjectLocation> getObjectLocations()
      Description copied from interface: ITextDocumentPart
      Retrieve the list of objects represented in the part, as well as their locations (line start/end, column start/end). A given coordinates within the part may host multiple objects.

      Implementation of this method is optional; to ensure backward compatibility with existing documents, the default implementation returns an empty collection.

      Specified by:
      getObjectLocations in interface ITextDocumentPart
      Returns:
      a collection of objects; the type of objects is specific to the document (and in the common case, the unit that generated the document)
    • toString

      public String toString()
      Overrides:
      toString in class Object