public class CodeSplicer
extends java.lang.Object
CodeSplicer
splices code segments from an existing
user file into a new automatically generated file. The intended use of
the code splicer is to preserve user edits to generated code. The new
file replaces the original one; however, the code splicer preserves areas
delineated with the pair of strings:
DO-NOT-DELETE splicer.begin(symbol)
DO-NOT-DELETE splicer.end(symbol)
embedded in comments in both the edited and generated files. The
code splicer also tracks which symbols were not used in the newly
generated file, and these symbols may be output at the end of the
new file to preserve code for the user.
IMPORTANT:
After introduction of splicer blocks into the AST and Symbol Table,
the rules for processing changed. The precedence, from highest to
least, is now as follows:
1) Legacy file splicer contents (if _any_ are populated);
2) AST contents (which are assumed to have been transferred to the symbol
table; then
3) Default contents.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
S_HEADER |
static java.lang.String |
S_SOURCE |
Constructor and Description |
---|
CodeSplicer(SymbolID id,
boolean isSource,
boolean prependFullName,
Context context)
Create a CodeSplicer that does not contain contents obtained from a
file.
|
CodeSplicer(SymbolID id,
java.io.BufferedReader reader,
java.lang.String vpath,
java.lang.String path,
boolean isSource,
boolean prependFullName,
Context context)
Create a new instance of the code splicer class.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getBeginString(java.lang.String symbol)
Return the code splicer start string for the beginning of a code
splice region.
|
java.lang.String |
getEditString(java.lang.String symbol)
Retrieve the edit string associated with the specified symbol.
|
static java.lang.String |
getEndString(java.lang.String symbol)
Return the code splicer end string for the closing of a code splice
region.
|
java.util.Set |
getSymbols()
Retrieve a
Set of the symbols in the symbol edit
database. |
java.lang.String |
getVPath()
query the current vpath setting
"." indicates no vpath
|
boolean |
hasSymbol(java.lang.String symbol)
Query whether the specified symbol exists in the symbol database.
|
boolean |
hasUnusedSymbolEdits()
Returns TRUE if there is at least one unused edit in the symbol
edit database.
|
void |
outputSymbolEdits(java.lang.String symbol,
LanguageWriter writer)
Output symbol information to the specified output print writer.
|
void |
outputUnusedSymbolEdits(LanguageWriter writer)
Output the unused edits in the symbol edit database.
|
void |
outputUnusedSymbolEdits(java.io.PrintWriter writer)
Output the unused edits in the symbol edit database.
|
void |
renameSymbol(java.lang.String oldName,
java.lang.String newName)
If a symbol by the name oldName exists, rename it to newName.
|
void |
setLineRedirector(LineRedirector lr) |
void |
setVPath(java.lang.String vpath)
explicitly set the vpath.
|
void |
splice(java.lang.String symbol,
LanguageWriter writer,
java.lang.String alt_msg)
The easiest method to envoke to create a spliced region
during code generation.
|
void |
splice(java.lang.String symbol,
LanguageWriter writer,
java.lang.String alt_msg,
java.lang.String alt_code)
The easiest method to envoke to create a spliced region
during code generation.
|
void |
splice(java.lang.String symbol,
LanguageWriter writer,
java.lang.String alt_msg,
java.lang.String[] comment_code)
The initial code is an array of lines.
|
void |
splice(java.lang.String symbol,
LanguageWriter writer,
java.lang.String alt_msg,
java.lang.String[] comment_code,
java.lang.String[] live_code)
The initial code is an array of lines.
|
public static final java.lang.String S_HEADER
public static final java.lang.String S_SOURCE
public CodeSplicer(SymbolID id, java.io.BufferedReader reader, java.lang.String vpath, java.lang.String path, boolean isSource, boolean prependFullName, Context context) throws java.io.IOException
java.io.IOException
public CodeSplicer(SymbolID id, boolean isSource, boolean prependFullName, Context context) throws java.io.IOException
java.io.IOException
public static java.lang.String getBeginString(java.lang.String symbol)
public static java.lang.String getEndString(java.lang.String symbol)
public void setLineRedirector(LineRedirector lr)
public java.lang.String getVPath()
public void setVPath(java.lang.String vpath)
public boolean hasSymbol(java.lang.String symbol)
public void outputSymbolEdits(java.lang.String symbol, LanguageWriter writer)
public java.lang.String getEditString(java.lang.String symbol)
public boolean hasUnusedSymbolEdits()
public void outputUnusedSymbolEdits(java.io.PrintWriter writer)
public void outputUnusedSymbolEdits(LanguageWriter writer)
public java.util.Set getSymbols()
Set
of the symbols in the symbol edit
database. Each entry in the set is a string representing a symbol.public void splice(java.lang.String symbol, LanguageWriter writer, java.lang.String alt_msg)
symbol
- The string symbol to match. Should be unique in a filewriter
- The LanguageWriter to embed the symbols in appropriate
commentsalt_msg
- An alternate message to embed in comments only if no
information was found by the splicer.public void splice(java.lang.String symbol, LanguageWriter writer, java.lang.String alt_msg, java.lang.String alt_code)
symbol
- The string symbol to match. Should be unique in a filewriter
- The LanguageWriter to embed the symbols in appropriate
commentsalt_msg
- An alternate message to embed in comments only if noalt_code
- A default code chunk (used for languages that REQUIRE a
return value (or some such)
information was found by the splicer.public void splice(java.lang.String symbol, LanguageWriter writer, java.lang.String alt_msg, java.lang.String[] comment_code)
symbol
- The string symbol to match. Should be unique in a filewriter
- The LanguageWriter to embed the symbols in appropriate
commentsalt_msg
- An alternate message to embed in comments only if nocomment_code
- A default code chunk that will be included
in a block comment.
information was found by the splicer.public void splice(java.lang.String symbol, LanguageWriter writer, java.lang.String alt_msg, java.lang.String[] comment_code, java.lang.String[] live_code)
symbol
- The string symbol to match. Should be unique in a filewriter
- The LanguageWriter to embed the symbols in appropriate
commentsalt_msg
- An alternate message to embed in comments only if no
information was found by the splicer.comment_code
- A default code chunk that will be included in a
comment block only if no information was found by the splicer.live_code
- A default code chunk that will be included only if no
information was found by the splicer.public void renameSymbol(java.lang.String oldName, java.lang.String newName)
oldName
- the name of symbol to renamenewName
- this is the new name if the old one exists.