|
Dresden OCL Toolkit | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttudresden.ocl.parser.analysis.AnalysisAdapter
tudresden.ocl.parser.analysis.ReversedDepthFirstAdapter
tudresden.ocl.codegen.decl.DeclarativeCodeGenerator
This class provides functionality to generate declarative code such as SQL by traversing the abstract syntax tree in reversed depth first order. The basic concept is simple substring replacing in a StringBuffer. Therefore placeholders are going to be created and inserted at the proper positions within the buffer. The task of replacing these placeholders with target code is up to the nodes of the abstract syntax tree. To associate nodes of the syntax tree with such tasks, a Hashtable is used provided by AnalysisAdapter. It contains the nodes as keys and the tasks (placeholders) as elements. It can be accessed by using the setIn and getIn methodes of Analysis Adapter. To implement a code generator using the explained strategy, it is necessary to derive a subclass from DeclarativeCodeGenerator and implement all inA... methodes of the nodes that are destined to produce code. If a node is not able to produce complete target code, new unique placeholders should be inserted at the critical positions. The task to replace these placeholders should be forwarded to subnodes using the proper methodes of this class. DeclarativeCodeGenerator does not produce any code or codefragments. It only creates the first task at the start node and delegates it to the leaf nodes. Code generation and CodeFragment handling is up to the derived subclasses.
Field Summary | |
protected CodeAgent |
ca
the code agent that provides code templates |
protected StringBuffer |
code
the temporary code buffer, later inserted into code fragments |
protected Vector |
fragments
the container for the produced code fragments |
private int |
taskCounter
the counter for the creation of unique tasks |
protected OclTree |
theTree
the abstract syntax tree |
Fields inherited from class tudresden.ocl.parser.analysis.AnalysisAdapter |
|
Constructor Summary | |
DeclarativeCodeGenerator(String rules)
|
Method Summary | |
void |
defaultIn(Node node)
Automated task delegation for all nodes. |
CodeFragment[] |
getCode(OclTree tree)
|
(package private) String |
getUniqueTask()
|
void |
inAConstraint(AConstraint node)
Creates the first task, initializes the code buffer with it and delegates it to all subnodes. |
(package private) String |
replaceInString(String source,
String oldStr,
String newStr)
A replacement methode for Strings. |
(package private) void |
replaceTask(String task,
String template)
Replaces all occurences of the task with the given template in the code buffer. |
(package private) void |
setRules(String rules)
|
(package private) void |
transferTask(Node from,
LinkedList to)
Delegates a task to an list of subnodes. |
(package private) void |
transferTask(Node from,
Node to)
Delegates a task to an subnode. |
Methods inherited from class tudresden.ocl.parser.analysis.AnalysisAdapter |
caseEOF, caseTAnd, caseTApostroph, caseTArrow, caseTAt, caseTBar, caseTBlank, caseTBool, caseTChannel, caseTColon, caseTComma, caseTComment, caseTContext, caseTDcolon, caseTDdot, caseTDiv, caseTDot, caseTEndif, caseTEnum, caseTEqual, caseTGt, caseTGteq, caseTImplies, caseTInt, caseTLBrace, caseTLBracket, caseTLPar, caseTLt, caseTLteq, caseTMinus, caseTMult, caseTName, caseTNEqual, caseTNewLine, caseTNot, caseTOr, caseTPlus, caseTRBrace, caseTRBracket, caseTReal, caseTRPar, caseTSemicolon, caseTSimpleTypeName, caseTStringLit, caseTTab, caseTTBag, caseTTCollection, caseTTElse, caseTTIf, caseTTIn, caseTTInv, caseTTLet, caseTTPost, caseTTPre, caseTTSequence, caseTTSet, caseTTThen, caseTXor, defaultCase, getIn, getOut, setIn, setOut |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected OclTree theTree
protected Vector fragments
protected StringBuffer code
protected CodeAgent ca
private int taskCounter
Constructor Detail |
public DeclarativeCodeGenerator(String rules)
Method Detail |
void setRules(String rules)
String getUniqueTask()
void replaceTask(String task, String template)
task
- the placeholdertemplate
- the code templateString replaceInString(String source, String oldStr, String newStr)
source
- the string containing substrings that equal to oldStroldStr
- the substring to be replacednewStr
- the replacement
void transferTask(Node from, LinkedList to)
from
- the owner of the taskto
- the list of recieversvoid transferTask(Node from, Node to)
from
- the owner of the taskto
- the recieverpublic void inAConstraint(AConstraint node)
inAConstraint
in class ReversedDepthFirstAdapter
public void defaultIn(Node node)
defaultIn
in class ReversedDepthFirstAdapter
public CodeFragment[] getCode(OclTree tree)
getCode
in interface CodeGenerator
|
Dresden OCL Toolkit | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |