org.ocltf.translation
Class TraceTranslator

java.lang.Object
  extended byorg.ocltf.parser.analysis.AnalysisAdapter
      extended byorg.ocltf.parser.analysis.DepthFirstAdapter
          extended byorg.ocltf.translation.BaseTranslator
              extended byorg.ocltf.translation.TraceTranslator
All Implemented Interfaces:
org.ocltf.parser.analysis.Analysis, org.ocltf.parser.node.Switch, Translator

public class TraceTranslator
extends BaseTranslator

This class allows us to trace the parsing of the expression. It is reflectively extended by Javaassist to allow the inclusion of all "inA" and "outA" methods produced by the SableCC parser. This allows us to dynamically include all handling code in each method without having to manual code each one. It used used during development of Translators since it allows you to see the execution of each node.

Author:
Chad Brandon

Nested Class Summary
protected static class TraceTranslator.TranslatorClassPool
          Extends the Javaassist class pool so that we can define our own ClassLoader to use from which to find, load and modify and existing class.
 
Field Summary
 
Fields inherited from interface org.ocltf.translation.Translator
CONTEXT_ELEMENT
 
Constructor Summary
TraceTranslator()
          Constructs an instance of TraceTranslator.
 
Method Summary
protected static void adaptClass()
          This method is called by the main method during the build process, to "adapt" the class to the OCL parser.
protected  java.io.File getAdaptedClassOutputDirectory()
          Retrieves the output directory which the adapted class will be written to.
protected  java.lang.Class getAdaptedTranslationClass()
          Creates and returns the adapted translator class.
protected  java.lang.String getInAMethodBody(javassist.CtMethod method)
          Creates and returns the method body for each "inA" method
static Translator getInstance()
          Creates and returns an new Instance of this ExpressionTranslator as a Translator object.
protected  java.lang.String getMethodPrefix(javassist.CtMethod method)
          Returns the prefix for the method (inA or outA)
protected  java.lang.String getMethodTrace(javassist.CtMethod method)
          Creates the debug statement that will be output for each method
protected  java.lang.String getOclFragmentName(javassist.CtMethod method)
          Returns the OCL fragment name that must have a matching name in the library translation template in order to be placed into the Expression translated expression buffer.
protected  java.lang.String getOutAMethodBody(javassist.CtMethod method)
          Creates and returns the method body for each "inA" method
static void main(java.lang.String[] args)
          This main method is called during the build process, to "adapt" the class to the OCL parser.
protected  boolean needsAdaption()
          Checks to see if this class needs to be adapated If it has the "adapted" field then we know it already has been adapted.
 Expression translate(java.lang.String translationName, java.lang.Object contextElement, java.lang.String expression)
          Translates the OCL into a translated Expression instance.
protected  void writeAdaptedClass()
          Writes the class to the directory found by the class loader (since the class is a currently existing class)
 
Methods inherited from class org.ocltf.translation.BaseTranslator
getContextElement, getExpression, getTranslationFragment, handleException, handleTranslationFragment, inAClassifierContextDeclaration, inADefClassifierExpressionBody, inAInvClassifierExpressionBody, inAOperationContextDeclaration, inAOperationExpressionBody, postProcess, preProcess, process
 
Methods inherited from class org.ocltf.parser.analysis.DepthFirstAdapter
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, caseALetVariableDelaration, 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, inALetVariableDelaration, 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, outALetVariableDelaration, 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, outStart
 
Methods inherited from class org.ocltf.parser.analysis.AnalysisAdapter
caseEOF, caseTAnd, caseTApostrophe, caseTArrow, caseTAt, caseTAttr, caseTBag, caseTBar, caseTBlank, caseTBody, caseTBoolean, caseTCollection, caseTColon, caseTComma, caseTComment, 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, caseTName, caseTNewLine, caseTNot, caseTNotEqual, caseTOper, caseTOr, caseTOrderedset, caseTPackage, caseTPlus, caseTPost, caseTPre, caseTRange, caseTRBrace, caseTRBracket, caseTReal, caseTRParen, caseTScopeOperator, caseTSemicolon, caseTSequence, caseTSet, caseTStringLit, caseTTab, caseTThen, caseTTuple, caseTTupletype, caseTUnknown, caseTXor, defaultCase, getIn, getOut, setIn, setOut
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TraceTranslator

public TraceTranslator()
Constructs an instance of TraceTranslator.

Method Detail

getInstance

public static Translator getInstance()
Creates and returns an new Instance of this ExpressionTranslator as a Translator object. The first time this method is called this class will dynamically be adapted to handle all parser calls.

Returns:
Translator
Throws:
java.lang.IllegalArgumentException - - if the analysisSuperClass doesn't implement Analysis.

translate

public Expression translate(java.lang.String translationName,
                            java.lang.Object contextElement,
                            java.lang.String expression)
Description copied from interface: Translator
Translates the OCL into a translated Expression instance.

Specified by:
translate in interface Translator
Overrides:
translate in class BaseTranslator
See Also:
Translator.translate(java.lang.String, java.lang.Object, java.lang.String)

needsAdaption

protected boolean needsAdaption()
Checks to see if this class needs to be adapated If it has the "adapted" field then we know it already has been adapted.

Returns:
true/false, true if it needs be be adapted.

getAdaptedTranslationClass

protected java.lang.Class getAdaptedTranslationClass()
                                              throws javassist.NotFoundException,
                                                     javassist.CannotCompileException,
                                                     java.io.IOException
Creates and returns the adapted translator class.

Returns:
Class the new Class instance.
Throws:
javassist.NotFoundException
javassist.CannotCompileException
java.io.IOException

writeAdaptedClass

protected void writeAdaptedClass()
Writes the class to the directory found by the class loader (since the class is a currently existing class)


getAdaptedClassOutputDirectory

protected java.io.File getAdaptedClassOutputDirectory()
Retrieves the output directory which the adapted class will be written to.

Returns:

getInAMethodBody

protected java.lang.String getInAMethodBody(javassist.CtMethod method)
                                     throws javassist.NotFoundException
Creates and returns the method body for each "inA" method

Parameters:
method -
Returns:
String
Throws:
javassist.NotFoundException

getOutAMethodBody

protected java.lang.String getOutAMethodBody(javassist.CtMethod method)
                                      throws javassist.NotFoundException
Creates and returns the method body for each "inA" method

Parameters:
method -
Returns:
String
Throws:
javassist.NotFoundException

getOclFragmentName

protected java.lang.String getOclFragmentName(javassist.CtMethod method)
Returns the OCL fragment name that must have a matching name in the library translation template in order to be placed into the Expression translated expression buffer.

Parameters:
method -
Returns:
String

getMethodPrefix

protected java.lang.String getMethodPrefix(javassist.CtMethod method)
Returns the prefix for the method (inA or outA)

Parameters:
method -
Returns:

getMethodTrace

protected java.lang.String getMethodTrace(javassist.CtMethod method)
                                   throws javassist.NotFoundException
Creates the debug statement that will be output for each method

Parameters:
method -
Returns:
Throws:
javassist.NotFoundException

adaptClass

protected static void adaptClass()
This method is called by the main method during the build process, to "adapt" the class to the OCL parser.


main

public static void main(java.lang.String[] args)
This main method is called during the build process, to "adapt" the class to the OCL parser.

Parameters:
args -


Copyright © 2003-2004 Chad Brandon. All Rights Reserved.