public abstract class BaseTranslator extends DepthFirstAdapter implements Translator
| Modifier and Type | Field and Description |
|---|---|
protected Logger |
logger
The logger instance that can be used by all decendant classes.
|
| Constructor and Description |
|---|
BaseTranslator() |
| Modifier and Type | Method and Description |
|---|---|
Object |
getContextElement()
Returns the context element for the expression being translated.
|
Expression |
getExpression()
Returns the current value of the Expression.
|
protected OperationDeclaration |
getOperation()
Gets the operation declaration of the constraint (if the context is an operation), otherwise returns null.
|
protected String |
getTranslationFragment(String fragmentName)
Finds the "fragment" with the specified
fragmentName from the library translation file. |
protected void |
handleTranslationFragment(Object node)
Calls the handlerMethod defined on the <fragment/> element if
fragmentName matches one the
fragments defined within the current translation file. |
void |
inAClassifierContextDeclaration(AClassifierContextDeclaration declaration)
Sets the element type which represents the context of the expression for expressions having classifiers as their
context.
|
void |
inADefClassifierExpressionBody(ADefClassifierExpressionBody expressionBody)
Sets the kind and name of the expression for
def expressions. |
void |
inAInvClassifierExpressionBody(AInvClassifierExpressionBody expressionBody)
Sets the kind and name of the expression for
inv expressions. |
void |
inAOperationContextDeclaration(AOperationContextDeclaration declaration)
Sets the element type which represents the context of the expression for expressions having operations as their
context.
|
void |
inAOperationExpressionBody(AOperationExpressionBody operationExpressionBody)
Sets the kind and name of the expression for operation contexts.
|
protected boolean |
isOperationArgument(String argument)
Indicates if the given
argument is an operation argument (if the context declaration is an
operation) |
abstract void |
postProcess()
Performs any post processing.
|
void |
preProcess()
Performs any initialization.
|
protected void |
process(String expression)
Parses the expression and applies this Translator to it.
|
Expression |
translate(String translationName,
String expression,
Object contextElement)
NOTE: null is allowed for contextElement (even though it isn't within
ExpressionTranslator.translate() since the TraceTranslator doesn't need a
contextElement and we
don't want to slow down the trace by having to read and load a model each time. |
caseAActualParameterList, caseAAdditiveExpression, caseAAdditiveExpressionTail, caseAAndLogicalOperator, caseAArrowPropertyCallExpressionTail, caseAAttributeOrAssociationContextDeclaration, caseAAttributeOrAssociationExpressionBody, caseABagCollectionKind, caseABagCollectionType, caseABarFeatureCallParameterOption, caseABodyOperationStereotype, caseABooleanPrimitiveLit, caseAClassifierContextDeclaration, caseACollectionCollectionKind, caseACollectionCollectionType, caseACollectionLit, caseACollectionLiteral, caseACollectionType, caseAColonFeatureCallParameterOption, caseACommaExpression, caseACommaFeatureCallParameterOption, caseAConcreteFeatureCallParameters, caseAContextDeclaration, caseADeclaratorTail, caseADefClassifierExpressionBody, caseADeriveInitialOrDerivedValue, caseADivMultiplyOperator, caseADotPropertyCallExpressionTail, caseAEqualExpression, caseAEqualRelationalOperator, caseAExpMessageArgument, caseAExpressionListOrRange, caseAFeatureCall, caseAFeatureCallParameters, caseAFeaturePrimaryExpression, caseAGteqRelationalOperator, caseAGtRelationalOperator, caseAIfExpression, caseAIfPrimaryExpression, caseAImpliesLogicalOperator, caseAInitInitialOrDerivedValue, caseAInLetExpSub, caseAIntegerPrimitiveLit, caseAInvClassifierExpressionBody, caseAIsMarkedPre, caseAIsSentMessageExp, caseAIterateDeclarator, caseAIterateFeatureCallParameterOption, caseALetExp, caseALetExpression, caseALetVariableDeclaration, caseAListExpressionListOrRangeTail, caseALiteralPrimaryExpression, caseALogicalExp, caseALogicalExpression, caseALogicalExpressionTail, caseALteqRelationalOperator, caseALtRelationalOperator, caseAMessageArguments, caseAMessageArgumentsTail, caseAMessageExpression, caseAMessageMessageExp, caseAMinusAddOperator, caseAMinusUnaryOperator, caseAMultiplicativeExpression, caseAMultiplicativeExpressionTail, caseAMultMultiplyOperator, caseANotEqualRelationalOperator, caseANotUnaryOperator, caseAOperation, caseAOperationContextDeclaration, caseAOperationDefinitionExpression, caseAOperationExpressionBody, caseAOrderedsetCollectionType, caseAOrLogicalOperator, caseAPackageDeclaration, caseAParenthesesPrimaryExpression, caseAPathName, caseAPathNameTail, caseAPlusAddOperator, caseAPostOperationStereotype, caseAPreOperationStereotype, caseAPrimitiveLiteral, caseAPropertyCallExpression, caseAQualifiers, caseARangeExpressionListOrRangeTail, caseARealPrimitiveLit, caseARelationalExpression, caseARelationalExpressionTail, caseAScopeOperatorName, caseASequenceCollectionKind, caseASequenceCollectionType, caseASetCollectionKind, caseASetCollectionType, caseASimpleType, caseAStandardDeclarator, caseAStringPrimitiveLit, caseATupleLit, caseATupleLiteral, caseATupleType, caseATupletypeType, caseATypeDeclaration, caseATypeMessageArgument, caseAUnaryExpression, caseAVariableDeclaration, caseAVariableDeclarationLetExpSub, caseAVariableDeclarationList, caseAVariableDeclarationListTail, caseAVariableDefinitionExpression, caseAXorLogicalOperator, caseStart, defaultIn, defaultOut, inAActualParameterList, inAAdditiveExpression, inAAdditiveExpressionTail, inAAndLogicalOperator, inAArrowPropertyCallExpressionTail, inAAttributeOrAssociationContextDeclaration, inAAttributeOrAssociationExpressionBody, inABagCollectionKind, inABagCollectionType, inABarFeatureCallParameterOption, inABodyOperationStereotype, inABooleanPrimitiveLit, inACollectionCollectionKind, inACollectionCollectionType, inACollectionLit, inACollectionLiteral, inACollectionType, inAColonFeatureCallParameterOption, inACommaExpression, inACommaFeatureCallParameterOption, inAConcreteFeatureCallParameters, inAContextDeclaration, inADeclaratorTail, inADeriveInitialOrDerivedValue, inADivMultiplyOperator, inADotPropertyCallExpressionTail, inAEqualExpression, inAEqualRelationalOperator, inAExpMessageArgument, inAExpressionListOrRange, inAFeatureCall, inAFeatureCallParameters, inAFeaturePrimaryExpression, inAGteqRelationalOperator, inAGtRelationalOperator, inAIfExpression, inAIfPrimaryExpression, inAImpliesLogicalOperator, inAInitInitialOrDerivedValue, inAInLetExpSub, inAIntegerPrimitiveLit, inAIsMarkedPre, inAIsSentMessageExp, inAIterateDeclarator, inAIterateFeatureCallParameterOption, inALetExp, inALetExpression, inALetVariableDeclaration, inAListExpressionListOrRangeTail, inALiteralPrimaryExpression, inALogicalExp, inALogicalExpression, inALogicalExpressionTail, inALteqRelationalOperator, inALtRelationalOperator, inAMessageArguments, inAMessageArgumentsTail, inAMessageExpression, inAMessageMessageExp, inAMinusAddOperator, inAMinusUnaryOperator, inAMultiplicativeExpression, inAMultiplicativeExpressionTail, inAMultMultiplyOperator, inANotEqualRelationalOperator, inANotUnaryOperator, inAOperation, inAOperationDefinitionExpression, inAOrderedsetCollectionType, inAOrLogicalOperator, inAPackageDeclaration, inAParenthesesPrimaryExpression, inAPathName, inAPathNameTail, inAPlusAddOperator, inAPostOperationStereotype, inAPreOperationStereotype, inAPrimitiveLiteral, inAPropertyCallExpression, inAQualifiers, inARangeExpressionListOrRangeTail, inARealPrimitiveLit, inARelationalExpression, inARelationalExpressionTail, inAScopeOperatorName, inASequenceCollectionKind, inASequenceCollectionType, inASetCollectionKind, inASetCollectionType, inASimpleType, inAStandardDeclarator, inAStringPrimitiveLit, inATupleLit, inATupleLiteral, inATupleType, inATupletypeType, inATypeDeclaration, inATypeMessageArgument, inAUnaryExpression, inAVariableDeclaration, inAVariableDeclarationLetExpSub, inAVariableDeclarationList, inAVariableDeclarationListTail, inAVariableDefinitionExpression, inAXorLogicalOperator, inStart, outAActualParameterList, outAAdditiveExpression, outAAdditiveExpressionTail, outAAndLogicalOperator, outAArrowPropertyCallExpressionTail, outAAttributeOrAssociationContextDeclaration, outAAttributeOrAssociationExpressionBody, outABagCollectionKind, outABagCollectionType, outABarFeatureCallParameterOption, outABodyOperationStereotype, outABooleanPrimitiveLit, outAClassifierContextDeclaration, outACollectionCollectionKind, outACollectionCollectionType, outACollectionLit, outACollectionLiteral, outACollectionType, outAColonFeatureCallParameterOption, outACommaExpression, outACommaFeatureCallParameterOption, outAConcreteFeatureCallParameters, outAContextDeclaration, outADeclaratorTail, outADefClassifierExpressionBody, outADeriveInitialOrDerivedValue, outADivMultiplyOperator, outADotPropertyCallExpressionTail, outAEqualExpression, outAEqualRelationalOperator, outAExpMessageArgument, outAExpressionListOrRange, outAFeatureCall, outAFeatureCallParameters, outAFeaturePrimaryExpression, outAGteqRelationalOperator, outAGtRelationalOperator, outAIfExpression, outAIfPrimaryExpression, outAImpliesLogicalOperator, outAInitInitialOrDerivedValue, outAInLetExpSub, outAIntegerPrimitiveLit, outAInvClassifierExpressionBody, outAIsMarkedPre, outAIsSentMessageExp, outAIterateDeclarator, outAIterateFeatureCallParameterOption, outALetExp, outALetExpression, outALetVariableDeclaration, outAListExpressionListOrRangeTail, outALiteralPrimaryExpression, outALogicalExp, outALogicalExpression, outALogicalExpressionTail, outALteqRelationalOperator, outALtRelationalOperator, outAMessageArguments, outAMessageArgumentsTail, outAMessageExpression, outAMessageMessageExp, outAMinusAddOperator, outAMinusUnaryOperator, outAMultiplicativeExpression, outAMultiplicativeExpressionTail, outAMultMultiplyOperator, outANotEqualRelationalOperator, outANotUnaryOperator, outAOperation, outAOperationContextDeclaration, outAOperationDefinitionExpression, outAOperationExpressionBody, outAOrderedsetCollectionType, outAOrLogicalOperator, outAPackageDeclaration, outAParenthesesPrimaryExpression, outAPathName, outAPathNameTail, outAPlusAddOperator, outAPostOperationStereotype, outAPreOperationStereotype, outAPrimitiveLiteral, outAPropertyCallExpression, outAQualifiers, outARangeExpressionListOrRangeTail, outARealPrimitiveLit, outARelationalExpression, outARelationalExpressionTail, outAScopeOperatorName, outASequenceCollectionKind, outASequenceCollectionType, outASetCollectionKind, outASetCollectionType, outASimpleType, outAStandardDeclarator, outAStringPrimitiveLit, outATupleLit, outATupleLiteral, outATupleType, outATupletypeType, outATypeDeclaration, outATypeMessageArgument, outAUnaryExpression, outAVariableDeclaration, outAVariableDeclarationLetExpSub, outAVariableDeclarationList, outAVariableDeclarationListTail, outAVariableDefinitionExpression, outAXorLogicalOperator, outStartcaseEOF, caseTAnd, caseTApostrophe, caseTArrow, caseTAttr, caseTBag, caseTBar, caseTBlank, caseTBody, caseTBoolean, caseTCollection, caseTColon, caseTComma, caseTCommercialAt, caseTContext, caseTDef, caseTDerive, caseTDiv, caseTDot, caseTElse, caseTEndif, caseTEndpackage, caseTEnum, caseTEqual, caseTGt, caseTGteq, caseTIf, caseTImplies, caseTIn, caseTInit, caseTInt, caseTInv, caseTIsSentOperator, caseTLBrace, caseTLBracket, caseTLet, caseTLParen, caseTLt, caseTLteq, caseTMessageOperator, caseTMinus, caseTMult, caseTMultiLineComment, caseTName, caseTNewLine, caseTNot, caseTNotEqual, caseTOper, caseTOr, caseTOrderedset, caseTPackage, caseTPlus, caseTPost, caseTPre, caseTRange, caseTRBrace, caseTRBracket, caseTReal, caseTRParen, caseTScopeOperator, caseTSemicolon, caseTSequence, caseTSet, caseTSingleLineComment, caseTStringLit, caseTTab, caseTThen, caseTTuple, caseTTupletype, caseTUnknown, caseTXor, defaultCase, getIn, getOut, setIn, setOutpublic BaseTranslator()
public Expression getExpression()
public Object getContextElement()
protected void handleTranslationFragment(Object node)
fragmentName matches one the
fragments defined within the current translation file.
A handlerMethod must have two arguments: String which will be the body of the corresponding kind element for the
matching fragment. (i.e. if 'context LegalAgreement inv: allInstances -> isUnique(documentTitle')'
is being translated, then the body of the element <kind name="inv"/> would be returned)Object and is the node that is currently being parsed at the time the
matching of the fragmentName occurred.
<fragment name="(\s*${elementName}\s*\.)?\s*allInstances.*"
handlerMethod="handleAllInstances">
<kind name="body">
from $completeElementName as $lowerCaseElementName
</kind>
</fragment>
And the implementation of the handleAllInstances method would be:
public void handleAllInstances(String translation, Object node)
{
//some handling code
}
node - the node being parsed, the toString value of this node is what is matched against the translation
fragment. We also need to pass the node to our handlerMethod so that it
can be used it for additional processing (if we need it).getTranslationFragment(String)protected String getTranslationFragment(String fragmentName)
fragmentName from the library translation file.
IMPORTANT: as a best practice, it is recommended that you use handleTranslationFragment(Node
node) if at all possible (instead of this method), it will help your code be cleaner and the methods smaller
and more maintainable.
Will retrieve the contents of the fragment kind that corresponds to the kind of expression currently
being translated. (i.e. if 'context LegalAgreement inv: allInstances -> isUnique(documentTitle')' is
being translated, then the body of the element <kind name="inv"> would be returned).
NOTE: You would use this method instead of handleTranslationFragment(Object
node) if you just want to retrieve the value of the fragment and don't want to have a handlerMethod which actually handles the processing of the output. For example you may
want to add a fragment called 'constraintTail' which would always be added to your translation at the end of the
constraint, the 'tail'. There isn't any part of the expression that matches this, but you still want to store it
in a translation template since it could be different between translations within your Translation-Library. fragmentName - the name of the fragment to retrieve from the translationhandleTranslationFragment(Object)public void preProcess()
public Expression translate(String translationName, String expression, Object contextElement)
contextElement and we
don't want to slow down the trace by having to read and load a model each time. translate in interface TranslatortranslationName - expression - contextElement - ExpressionTranslator.translate(String, String, Object)protected void process(String expression) throws IOException
expression - the expression to process.IOException - if an IO error occurs during processing.public abstract void postProcess()
public void inAInvClassifierExpressionBody(AInvClassifierExpressionBody expressionBody)
inv expressions. If subclasses override this method,
they MUST call this method before their own implementation.inAInvClassifierExpressionBody in class DepthFirstAdapterexpressionBody - public void inADefClassifierExpressionBody(ADefClassifierExpressionBody expressionBody)
def expressions. If subclasses override this method,
they MUST call this method before their own implementation.inADefClassifierExpressionBody in class DepthFirstAdapterexpressionBody - public void inAOperationExpressionBody(AOperationExpressionBody operationExpressionBody)
inAOperationExpressionBody in class DepthFirstAdapteroperationExpressionBody - public void inAOperationContextDeclaration(AOperationContextDeclaration declaration)
inAOperationContextDeclaration in class DepthFirstAdapterdeclaration - the AOperationContextDeclaration instance from which we retrieve the element type.protected OperationDeclaration getOperation()
protected boolean isOperationArgument(String argument)
argument is an operation argument (if the context declaration is an
operation)argument - the argument to check.public void inAClassifierContextDeclaration(AClassifierContextDeclaration declaration)
inAClassifierContextDeclaration in class DepthFirstAdapterdeclaration - the AClassifierContextDeclaration instance from which we retrieve the element type.Copyright © 2003–2014 AndroMDA.org. All rights reserved.