|
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.DepthFirstAdapter
tudresden.ocl.codegen.ProceduralCodeGenerator
tudresden.ocl.codegen.JavaCodeGenerator
Field Summary | |
(package private) String |
instanceName
|
(package private) String |
javaResult
|
(package private) static HashSet |
oclAnyOperations
set of all OclAny property names |
private String |
oclLibPackage
The package prefix for all classes of the ocl library in the generated code. |
(package private) NodeNameMap |
operatorCode
maps Nodes for operators (ALogicalOperator, ARelationalOperator...) to the String containing their Java representation |
(package private) StringStringMap |
varMap
|
Fields inherited from class tudresden.ocl.codegen.ProceduralCodeGenerator |
code, constrainedOperation, constrainedType, constraintKind, fragments, fragmentStack, indent, initialIndent, newLine, parameters, preCode, preCodeIsValid, preVariables, preVarTypes, topOfStack, tree, writeToPreCode, writeToStandardCode |
Fields inherited from class tudresden.ocl.parser.analysis.AnalysisAdapter |
|
Constructor Summary | |
JavaCodeGenerator()
|
|
JavaCodeGenerator(String instanceName)
|
|
JavaCodeGenerator(String instanceName,
String resultName)
|
|
JavaCodeGenerator(String instanceName,
String resultName,
String oclLibPackage)
|
Method Summary | |
protected void |
addExpressionToCollection(PExpression e,
String collVar)
|
protected void |
appendActualParameterList(AActualParameterList apl)
append the Java code for an AActualParameterList, excluding the parentheses |
protected void |
appendAndOrLogExpr(PRelationalExpression[] relExprs,
PLogicalOperator[] logOps,
int from,
int to)
Append code for the part of a logical expression between the indexes of relational subexpression given as parameters from and
to , both relational expressions included. |
protected void |
appendPostfixArrowOp(APostfixExpressionTail pet,
Node appliedTo,
Type appliedType)
The APostfixExpressionTail begins with '->' and is therefore a collection operation applied either to a collection or to a single, possible undefined element (as in context Person inv: ... |
protected void |
appendPostfixBasic(APostfixExpressionTail pet,
Node appliedTo,
Type appliedType)
|
protected void |
appendPostfixDotOp(APostfixExpressionTail pet,
Node appliedTo,
Type appliedType)
The APostfixExpressionTail has a '.' begin and is not applied to basic type. |
void |
caseAPostfixExpressionTail(APostfixExpressionTail pet)
Iterating methods parameters must be inserted into an inner class, therefore it is not possible to translate APostfixExpressionTail postfix. |
protected String |
convertToCollection(Node appliedTo)
|
private String |
createDecl(String type,
String variable)
This method generates the declaration prefix of a node. |
protected String[] |
getEvaluatableTypes(String featureName)
|
protected String |
getJavaType(Type t)
|
protected Node |
getPreviousNode(APostfixExpressionTail pet)
|
protected String |
getTransferCode(String var,
String type)
|
void |
inAAndLogicalOperator(AAndLogicalOperator lo)
|
void |
inAConstraintBody(AConstraintBody cb)
the variable for the AConstraintBody node is the variable for "self" |
void |
inADivMultiplyOperator(ADivMultiplyOperator dmo)
|
void |
inAEqualRelationalOperator(AEqualRelationalOperator ero)
|
void |
inAGteqRelationalOperator(AGteqRelationalOperator ro)
|
void |
inAGtRelationalOperator(AGtRelationalOperator ro)
|
void |
inAImpliesLogicalOperator(AImpliesLogicalOperator lo)
|
void |
inALitColPrimaryExpression(ALitColPrimaryExpression lcpe)
This method breaks the usual pattern of generating Java code postfix since the collection must be declared and instanciated prior to setting its contents (in outAExpressionListOrRange ). |
void |
inALteqRelationalOperator(ALteqRelationalOperator ro)
|
void |
inALtRelationalOperator(ALtRelationalOperator ro)
|
void |
inAMinusAddOperator(AMinusAddOperator mao)
|
void |
inAMinusUnaryOperator(AMinusUnaryOperator muo)
|
void |
inAMultMultiplyOperator(AMultMultiplyOperator mmo)
|
void |
inANEqualRelationalOperator(ANEqualRelationalOperator nero)
|
void |
inANotUnaryOperator(ANotUnaryOperator nuo)
|
void |
inAOrLogicalOperator(AOrLogicalOperator lo)
|
void |
inAPlusAddOperator(APlusAddOperator pao)
|
void |
inAXorLogicalOperator(AXorLogicalOperator lo)
|
void |
outAAdditiveExpression(AAdditiveExpression ae)
a + b Ocl? result=Ocl.toOcl?(a).add(Ocl.toOcl?(b)); with Ocl? = OclReal | OclInteger | OclSet |
void |
outABooleanLiteral(ABooleanLiteral bl)
|
void |
outAEnumLiteral(AEnumLiteral el)
|
void |
outAExpression(AExpression e)
|
void |
outAExpressionListOrRange(AExpressionListOrRange elor)
|
void |
outAFeaturePrimaryExpression(AFeaturePrimaryExpression pe)
|
void |
outAIfExpression(AIfExpression ie)
if a then b else c endif Ocl? result=(a.isTrue()) ? (b) : (c); |
void |
outAIfPrimaryExpression(AIfPrimaryExpression ipe)
|
void |
outAIntegerLiteral(AIntegerLiteral il)
|
void |
outALetExpression(ALetExpression le)
|
void |
outALiteralPrimaryExpression(ALiteralPrimaryExpression lpe)
|
void |
outALogicalExpression(ALogicalExpression le)
and , or and xor have precedence
over implies (and binds as strongly as
or )
|
void |
outAMultiplicativeExpression(AMultiplicativeExpression me)
a * b Ocl? result=Ocl.toOcl?(a).multiply(Ocl.toOcl?(b)); with Ocl? = OclReal | OclInteger |
void |
outAParenthesesPrimaryExpression(AParenthesesPrimaryExpression lpe)
|
void |
outAPostfixExpression(APostfixExpression pe)
|
void |
outAPostfixUnaryExpression(APostfixUnaryExpression pue)
|
void |
outARealLiteral(ARealLiteral rl)
|
void |
outARelationalExpression(ARelationalExpression re)
a<b = c>d is not allowed by the OCL grammar, therefore we need not care about precedence |
void |
outAStringLiteral(AStringLiteral sl)
|
void |
outAUnaryUnaryExpression(AUnaryUnaryExpression uue)
not a OclBoolean result=a.not(); |
private String |
qualifyType(String type)
|
protected void |
requireTreeInvariants()
gives subclasses the opportunity to check if the OclTree requires some invariants, using OclTree's requireInvariant() method |
Methods inherited from class tudresden.ocl.codegen.ProceduralCodeGenerator |
addPreVariable, appendCode, assurePreCode, beginNewFragment, caseAConstraintBody, decreaseIndent, endFragment, getCode, getVariable, inAClassifierContext, inAInvStereotype, inAOperationContext, inAPostStereotype, inAPreStereotype, increaseIndent, reachThrough, setInitialIndent, setVariable, writeToBothCodes, writeToPreCodeOnly, writeToStandardCodeOnly |
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 |
String instanceName
String javaResult
private String oclLibPackage
NodeNameMap operatorCode
StringStringMap varMap
static HashSet oclAnyOperations
Constructor Detail |
public JavaCodeGenerator(String instanceName, String resultName)
instanceName
- a Java expression that will be evaluated to the
instance that is checked for constraint conformanceresultName
- a Java expression that will be evaluated to the
result of constrained operation (can be
null
for other constraints than post
conditionspublic JavaCodeGenerator(String instanceName, String resultName, String oclLibPackage)
public JavaCodeGenerator(String instanceName)
instanceName
- a Java expression that will be evaluated to the
instance that is checked for constraint conformancepublic JavaCodeGenerator()
Method Detail |
protected String getTransferCode(String var, String type)
getTransferCode
in class ProceduralCodeGenerator
protected void requireTreeInvariants()
ProceduralCodeGenerator
requireTreeInvariants
in class ProceduralCodeGenerator
private String createDecl(String type, String variable)
final tudresden.ocl.lib.<type> <variable> =The type is ommited, if the variable is one of the transfer variables.
private String qualifyType(String type)
public void inAConstraintBody(AConstraintBody cb)
inAConstraintBody
in class DepthFirstAdapter
public void outAExpression(AExpression e)
outAExpression
in class DepthFirstAdapter
public void outAIfExpression(AIfExpression ie)
For each if expression a new variable is generated.
outAIfExpression
in class DepthFirstAdapter
public void outALogicalExpression(ALogicalExpression le)
and
, or
and xor
have precedence
over implies
(and
binds as strongly as
or
)
a and b or c
OclBoolean result = a.and(b).or(c);
A variable is generated for each ALogicalExpression with tail (not for a ALogicalExpressionTail).
outALogicalExpression
in class DepthFirstAdapter
protected void appendAndOrLogExpr(PRelationalExpression[] relExprs, PLogicalOperator[] logOps, int from, int to)
from
and
to
, both relational expressions included. The part must not
contain an implies
operator. from
may be equal
to to
.
public void outARelationalExpression(ARelationalExpression re)
a = b
OclBoolean result=a.isEqualTo(b);
a > b
OclBoolean result=Ocl.toOclComparable(a).isGreaterThan(Ocl.toOclComparable(b));
A variable is generated for each ARelationalExpression if it has a ARelationalExpressionTail subnode.
outARelationalExpression
in class DepthFirstAdapter
public void outAAdditiveExpression(AAdditiveExpression ae)
A variable is generated for each AAdditiveExpression with tail.
outAAdditiveExpression
in class DepthFirstAdapter
public void outAMultiplicativeExpression(AMultiplicativeExpression me)
A variable is generated for each AMultiplicativeExpression with tail.
outAMultiplicativeExpression
in class DepthFirstAdapter
public void outAUnaryUnaryExpression(AUnaryUnaryExpression uue)
A variable is generated for each AUnaryUnaryExpression.
outAUnaryUnaryExpression
in class DepthFirstAdapter
public void outAPostfixUnaryExpression(APostfixUnaryExpression pue)
outAPostfixUnaryExpression
in class DepthFirstAdapter
public void outAPostfixExpression(APostfixExpression pe)
outAPostfixExpression
in class DepthFirstAdapter
public void outAFeaturePrimaryExpression(AFeaturePrimaryExpression pe)
outAFeaturePrimaryExpression
in class DepthFirstAdapter
public void inALitColPrimaryExpression(ALitColPrimaryExpression lcpe)
outAExpressionListOrRange
).
inALitColPrimaryExpression
in class DepthFirstAdapter
public void outALiteralPrimaryExpression(ALiteralPrimaryExpression lpe)
outALiteralPrimaryExpression
in class DepthFirstAdapter
public void outAParenthesesPrimaryExpression(AParenthesesPrimaryExpression lpe)
outAParenthesesPrimaryExpression
in class DepthFirstAdapter
public void outAIfPrimaryExpression(AIfPrimaryExpression ipe)
outAIfPrimaryExpression
in class DepthFirstAdapter
public void outAExpressionListOrRange(AExpressionListOrRange elor)
outAExpressionListOrRange
in class DepthFirstAdapter
public void caseAPostfixExpressionTail(APostfixExpressionTail pet)
caseAPostfixExpressionTail
in interface Analysis
caseAPostfixExpressionTail
in class DepthFirstAdapter
protected void appendPostfixBasic(APostfixExpressionTail pet, Node appliedTo, Type appliedType)
protected void appendPostfixArrowOp(APostfixExpressionTail pet, Node appliedTo, Type appliedType)
context Person inv: ... husband->isEmpty ...
).
protected String convertToCollection(Node appliedTo)
protected String[] getEvaluatableTypes(String featureName)
featureName
- one of the iterating method names, excluding iterate
evaluate()
methods return type at index 1, and the
return type of the iterating method at index 2.protected void appendPostfixDotOp(APostfixExpressionTail pet, Node appliedTo, Type appliedType)
protected void appendActualParameterList(AActualParameterList apl)
apl
- may be null, then nothing is donepublic void outALetExpression(ALetExpression le)
outALetExpression
in class DepthFirstAdapter
public void outAStringLiteral(AStringLiteral sl)
outAStringLiteral
in class DepthFirstAdapter
public void outARealLiteral(ARealLiteral rl)
outARealLiteral
in class DepthFirstAdapter
public void outAIntegerLiteral(AIntegerLiteral il)
outAIntegerLiteral
in class DepthFirstAdapter
public void outABooleanLiteral(ABooleanLiteral bl)
outABooleanLiteral
in class DepthFirstAdapter
public void outAEnumLiteral(AEnumLiteral el)
outAEnumLiteral
in class DepthFirstAdapter
protected Node getPreviousNode(APostfixExpressionTail pet)
protected void addExpressionToCollection(PExpression e, String collVar)
protected String getJavaType(Type t)
public void inAAndLogicalOperator(AAndLogicalOperator lo)
inAAndLogicalOperator
in class DepthFirstAdapter
public void inAOrLogicalOperator(AOrLogicalOperator lo)
inAOrLogicalOperator
in class DepthFirstAdapter
public void inAXorLogicalOperator(AXorLogicalOperator lo)
inAXorLogicalOperator
in class DepthFirstAdapter
public void inAImpliesLogicalOperator(AImpliesLogicalOperator lo)
inAImpliesLogicalOperator
in class DepthFirstAdapter
public void inAEqualRelationalOperator(AEqualRelationalOperator ero)
inAEqualRelationalOperator
in class DepthFirstAdapter
public void inANEqualRelationalOperator(ANEqualRelationalOperator nero)
inANEqualRelationalOperator
in class DepthFirstAdapter
public void inAGtRelationalOperator(AGtRelationalOperator ro)
inAGtRelationalOperator
in class DepthFirstAdapter
public void inALtRelationalOperator(ALtRelationalOperator ro)
inALtRelationalOperator
in class DepthFirstAdapter
public void inAGteqRelationalOperator(AGteqRelationalOperator ro)
inAGteqRelationalOperator
in class DepthFirstAdapter
public void inALteqRelationalOperator(ALteqRelationalOperator ro)
inALteqRelationalOperator
in class DepthFirstAdapter
public void inAPlusAddOperator(APlusAddOperator pao)
inAPlusAddOperator
in class DepthFirstAdapter
public void inAMinusAddOperator(AMinusAddOperator mao)
inAMinusAddOperator
in class DepthFirstAdapter
public void inAMultMultiplyOperator(AMultMultiplyOperator mmo)
inAMultMultiplyOperator
in class DepthFirstAdapter
public void inADivMultiplyOperator(ADivMultiplyOperator dmo)
inADivMultiplyOperator
in class DepthFirstAdapter
public void inAMinusUnaryOperator(AMinusUnaryOperator muo)
inAMinusUnaryOperator
in class DepthFirstAdapter
public void inANotUnaryOperator(ANotUnaryOperator nuo)
inANotUnaryOperator
in class DepthFirstAdapter
|
Dresden OCL Toolkit | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |