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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCodeDocumentPart
(long baseAnchorId) Create a new code document part, attached to the given anchor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
Append a chunk of text to the current line.void
append
(String str, ItemClassIdentifiers classId) void
appendAndRecord
(String s, ItemClassIdentifiers classId) Append a chunk of text to the current line.void
appendAndRecord
(String s, ItemClassIdentifiers classId, long itemId) Append a chunk of text to the current line.void
appendAndRecord
(String s, ItemClassIdentifiers classId, long itemId, int flags) Append a chunk of text to the current line.void
appendComment
(String text) void
appendComment
(String text, boolean auto) void
appendCommentAuto
(String text) protected void
appendKeyword
(int id) void
appendKeyword
(String keyword) Convenience method.void
appendKeyword
(String keyword, long itemId) void
void
Append a parameter separator to the current line.void
brace()
void
void
bracket()
void
void
void
void
static boolean
enableTokenFlattening
(boolean enabled) Enable or disable token flattening.void
eol()
End the current line.void
eol
(ICodeCoordinates lineCoord) End the current line.format()
Get the anchors within that part.Get the currently active anchor.Get the last (unfinished) lineint
Same asgetLineCount()
.int
int
int
int
Get the index of the last finished line.getLine
(int index) int
Get 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).void
void
boolean
void
markCurrentPosition
(String name, Object object) boolean
moveLastLine
(int newIndex) boolean
moveLine
(int index, int newIndex) void
paren()
void
void
void
recordCurrentCoordinates
(ICodeCoordinates coordinates) void
recordLineCoordinates
(ICodeCoordinates coordinates) void
recordObjectLocation
(Object object, boolean begin, int depth) boolean
registerAnchor
(long anchorId, String name) Create an anchor with the provided anchor id, and register it at the current last line.boolean
registerAnchor
(String name) Create an anchor using the current (next) anchor id, and register it at the current last line.protected int
registerKeyword
(String keyword) Register a keyword for future fast appending.void
void
setIndentationLevel
(int level) void
setIndentationString
(String indentString) void
setPaddingString
(String paddingString) void
setParameterSeparator
(String parameterSeparator) Set the parameter separator.void
space()
Append a space to the current line.void
space
(int cnt) Append one or more spaces to the current line.toString()
void
void
void
validate()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.pnfsoftware.jeb.core.output.text.ITextDocumentPart
getAnchor
-
Field Details
-
paddingString
-
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
Description copied from interface:ITextDocumentPart
Get the lines within that part. The lines may span over one or more anchors.- Specified by:
getLines
in interfaceITextDocumentPart
- Returns:
- the list of lines
-
getLine
- Specified by:
getLine
in interfaceITextDocumentPart
- Returns:
-
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 interfaceITextDocumentPart
- Returns:
- the list of anchors
-
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 propertyFlattenStringsInCodeDocuments
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
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:
append
in interfaceICodeDocument
-
append
- Specified by:
append
in 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:
paren
in interfaceICodeDocument
-
parenClose
public void parenClose()- Specified by:
parenClose
in interfaceICodeDocument
-
brace
public void brace()- Specified by:
brace
in interfaceICodeDocument
-
braceClose
public void braceClose()- Specified by:
braceClose
in interfaceICodeDocument
-
bracket
public void bracket()- Specified by:
bracket
in interfaceICodeDocument
-
bracketClose
public void bracketClose()- Specified by:
bracketClose
in 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:ICodeDocument
Convenience method.- Specified by:
appendKeyword
in 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: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 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
-