Class CodeDocumentPart
java.lang.Object
com.pnfsoftware.jeb.core.output.code.CodeDocumentPart
- All Implemented Interfaces:
ICodeDocument,ITextDocumentPart
- Direct Known Subclasses:
CppLikeDocumentPart
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.
-
Constructor Summary
ConstructorsConstructorDescriptionCodeDocumentPart(long baseAnchorId) Create a new code document part, attached to the given anchor. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidAppend a chunk of text to the current line.voidappend(String str, ItemClassIdentifiers classId) voidappendAndRecord(String s, ItemClassIdentifiers classId) Append a chunk of text to the current line.voidappendAndRecord(String s, ItemClassIdentifiers classId, long itemId) Append a chunk of text to the current line.voidappendAndRecord(String s, ItemClassIdentifiers classId, long itemId, int flags) Append a chunk of text to the current line.voidappendComment(String text) voidappendComment(String text, boolean auto) voidappendCommentAuto(String text) protected voidappendKeyword(int id) voidappendKeyword(String keyword) Convenience method.voidappendKeyword(String keyword, long itemId) voidvoidAppend a parameter separator to the current line.voidbrace()voidvoidbracket()voidvoidvoidvoidstatic booleanenableTokenFlattening(boolean enabled) Enable or disable token flattening.voideol()End the current line.voideol(ICodeCoordinates lineCoord) End the current line.format()getAnchor(int index) Get the anchors within that part.intintGet the currently active anchor.Get the last (unfinished) lineintSame asgetLineCount().intintintintGet the index of the last finished line.getLine(int index) intGet the number of finished (EOL-terminated) lines in this part.getLines()Get the lines within that part.Retrieve the list of objects represented in the part, as well as their locations (line start/end, column start/end).voidvoidbooleanvoidmarkCurrentPosition(String name, Object object) booleanmoveLastLine(int newIndex) booleanmoveLine(int index, int newIndex) voidparen()voidvoidvoidrecordCurrentCoordinates(ICodeCoordinates coordinates) voidrecordLineCoordinates(ICodeCoordinates coordinates) voidrecordObjectLocation(Object object, boolean begin, int depth) booleanregisterAnchor(long anchorId, String name) Create an anchor with the provided anchor id, and register it at the current last line.booleanregisterAnchor(String name) Create an anchor using the current (next) anchor id, and register it at the current last line.protected intregisterKeyword(String keyword) Register a keyword for future fast appending.voidvoidsetIndentationLevel(int level) voidsetIndentationString(String indentString) voidsetPaddingString(String paddingString) voidsetParameterSeparator(String parameterSeparator) Set the parameter separator.voidspace()Append a space to the current line.voidspace(int cnt) Append one or more spaces to the current line.toString()voidvoidvoidvalidate()
-
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
Description copied from interface:ITextDocumentPartGet the lines within that part. The lines may span over one or more anchors.- Specified by:
getLinesin interfaceITextDocumentPart- Returns:
- the list of lines
-
getCountOfLines
public int getCountOfLines()- Specified by:
getCountOfLinesin interfaceITextDocumentPart- Returns:
-
getLine
- Specified by:
getLinein interfaceITextDocumentPart- Returns:
-
getAnchors
Description copied from interface:ITextDocumentPartGet 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:
getAnchorsin interfaceITextDocumentPart- Returns:
- the list of anchors
-
getAnchor
- Specified by:
getAnchorin interfaceITextDocumentPart
-
getCountOfAnchors
public int getCountOfAnchors()- Specified by:
getCountOfAnchorsin interfaceITextDocumentPart- Returns:
-
registerAnchor
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
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
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()Same asgetLineCount().- Returns:
- the line count
-
getLastLineIndex
public int getLastLineIndex()Get the index of the last finished line.- Returns:
- the last finished line index
-
getCurrentLine
Get the last (unfinished) line- Returns:
- the last line
-
getCurrentLineLength
public int getCurrentLineLength() -
isCurrentLineEmpty
public boolean isCurrentLineEmpty() -
setIndentationString
-
getIndentationString
-
setPaddingString
-
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 propertyFlattenStringsInCodeDocumentsif you wish to modify whether tokens should be flattened when they are appended to a text document.- Parameters:
enabled-- Returns:
- the previous setting
-
append
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 ('/') charactersaActualInsertionIndex- optional: set the index of the inserted string (can be different from current index because of padding) at 0-index
-
append
- Specified by:
appendin interfaceICodeDocument
-
append
- Specified by:
appendin interfaceICodeDocument
-
appendMulti
-
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
Set the parameter separator. Default is ", ".- Parameters:
parameterSeparator- new parameter separator
-
appendParameterSeparator
public void appendParameterSeparator()Append a parameter separator to the current line. UsesetParameterSeparator(String)to override default. -
registerKeyword
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
End the current line.- Parameters:
lineCoord- optional chunk coordinates
-
eol
public void eol()End the current line. -
paren
public void paren()- Specified by:
parenin interfaceICodeDocument
-
parenClose
public void parenClose()- Specified by:
parenClosein interfaceICodeDocument
-
brace
public void brace()- Specified by:
bracein interfaceICodeDocument
-
braceClose
public void braceClose()- Specified by:
braceClosein interfaceICodeDocument
-
bracket
public void bracket()- Specified by:
bracketin interfaceICodeDocument
-
bracketClose
public void bracketClose()- Specified by:
bracketClosein interfaceICodeDocument
-
appendAndRecord
Append a chunk of text to the current line.- Parameters:
s- a stringclassId- a class identifier
-
appendAndRecord
Append a chunk of text to the current line.- Parameters:
s- a stringclassId- a class identifieritemId- an item identifier
-
appendAndRecord
Append a chunk of text to the current line.- Parameters:
s- a stringclassId- a class identifieritemId- an item identifierflags- flags
-
appendKeyword
Description copied from interface:ICodeDocumentConvenience method.- Specified by:
appendKeywordin interfaceICodeDocument
-
appendKeyword
-
appendComment
-
appendComment
-
appendCommentAuto
-
recordLineCoordinates
-
unrecordLineCoordinates
public void unrecordLineCoordinates() -
getCurrentLineCoordinates
-
getCurrentMostPreciseCodeCoordinates
-
recordCurrentCoordinates
-
unrecordCurrentCoordinates
public void unrecordCurrentCoordinates() -
getCurrentCoordinates
-
validate
public void validate() -
prependCodePart
-
moveLine
public boolean moveLine(int index, int newIndex) -
moveLastLine
public boolean moveLastLine(int newIndex) -
markCurrentPosition
-
format
-
recordObjectLocation
-
getObjectLocations
Description copied from interface:ITextDocumentPartRetrieve 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:
getObjectLocationsin interfaceITextDocumentPart- 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
-