org.eclipse.ocl.util
Class ToStringVisitor<C,O,P,EL,PM,S,COA,SSA,CT>

java.lang.Object
  extended by org.eclipse.ocl.utilities.AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
      extended by org.eclipse.ocl.util.ToStringVisitor<C,O,P,EL,PM,S,COA,SSA,CT>
All Implemented Interfaces:
Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>

public class ToStringVisitor<C,O,P,EL,PM,S,COA,SSA,CT>
extends AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>

Converts an OCL expression to a string for debugging. This is not intended to be used by client applications as an AST-to-text transformation.


Field Summary
protected static String NULL_PLACEHOLDER
          Indicates where a required element in the AST was null, so that it is evident in the debugger that something was missing.
 
Fields inherited from class org.eclipse.ocl.utilities.AbstractVisitor
result
 
Constructor Summary
protected ToStringVisitor(Environment<?,C,O,P,EL,PM,S,COA,SSA,CT,?,?> env)
          Initializes me with my environment.
 
Method Summary
protected  List<EObject> getConstrainedElements(CT constraint)
           
static
<C,O,P,EL,PM,S,COA,SSA,CT>
ToStringVisitor<C,O,P,EL,PM,S,COA,SSA,CT>
getInstance(Environment<?,C,O,P,EL,PM,S,COA,SSA,CT,?,?> env)
          Obtains an instance of the toString() visitor for the specified environment.
static
<C,O,P,EL,PM,S,COA,SSA,CT>
ToStringVisitor<C,O,P,EL,PM,S,COA,SSA,CT>
getInstance(TypedElement<C> element)
          Obtains an instance of the toString() visitor for the specified expression or other typed element.
protected  String getName(Object named)
          Null-safe access to the name of a named element.
protected  O getOperation(COA callOperationAction)
           
protected  List<PM> getParameters(O operation)
           
protected  String getQualifiedName(Object named)
          Null-safe access to the qualified name of a named element.
protected  C getSignal(SSA sendSignalAction)
           
protected  ExpressionInOCL<C,PM> getSpecification(CT constraint)
          Overridden by subclasses interested in visiting constraints, to get the constraint's specification.
protected  String getStereotype(CT constraint)
           
protected  C getType(Object typedElement)
           
protected  String handleAssociationClassCallExp(AssociationClassCallExp<C,P> ac, String sourceResult, List<String> qualifierResults)
          Callback for an AssociationClassCallExp visit.
protected  String handleCollectionItem(CollectionItem<C> item, String itemResult)
          Visits the specified collection item with the result of visiting its item expression.
protected  String handleCollectionLiteralExp(CollectionLiteralExp<C> cl, List<String> partResults)
          Callback for a CollectionLiteralExp visit.
protected  String handleCollectionRange(CollectionRange<C> range, String firstResult, String lastResult)
          Visits the specified collection range with the results of visiting its first and last expressions.
protected  String handleIfExp(IfExp<C> ifExp, String conditionResult, String thenResult, String elseResult)
          Callback for an IfExp visit.
protected  String handleIterateExp(IterateExp<C,PM> callExp, String sourceResult, List<String> variableResults, String resultResult, String bodyResult)
          Callback for an IterateExp visit.
protected  String handleIteratorExp(IteratorExp<C,PM> callExp, String sourceResult, List<String> variableResults, String bodyResult)
          Callback for an IteratorExp visit.
protected  String handleLetExp(LetExp<C,PM> letExp, String variableResult, String inResult)
          Callback for LetExp visit.
protected  String handleMessageExp(MessageExp<C,COA,SSA> messageExp, String targetResult, List<String> argumentResults)
          Visits the specified message expression with the results of visiting its target and arguments (if any).
protected  String handleOperationCallExp(OperationCallExp<C,O> oc, String sourceResult, List<String> argumentResults)
          Callback for an OperationCallExp visit.
protected  String handlePropertyCallExp(PropertyCallExp<C,P> pc, String sourceResult, List<String> qualifierResults)
          Callback for an AssociationEndCallExp visit.
protected  String handleTupleLiteralExp(TupleLiteralExp<C,P> literalExp, List<String> partResults)
          Callback for a TupleLiteralExp visit.
protected  String handleTupleLiteralPart(TupleLiteralPart<C,P> part, String valueResult)
          Visits the specified tuple literal part with the results of visiting its value (if any).
protected  String handleVariable(Variable<C,PM> vd, String initResult)
          Callback for the Variable visit.
protected  String initialLower(String name)
           
protected  boolean isClassifier(Object element)
           
protected  boolean isOperation(Object element)
           
protected  boolean isProperty(Object element)
           
 String visitBooleanLiteralExp(BooleanLiteralExp<C> bl)
          Callback for a BooleanLiteralExp visit.
 String visitConstraint(CT constraint)
          Renders a constraint with its context and expression.
 String visitEnumLiteralExp(EnumLiteralExp<C,EL> el)
          Callback for an EnumLiteralExp visit.
 String visitExpressionInOCL(ExpressionInOCL<C,PM> expression)
          Renders an ExpressionInOcl with its context variables and body.
 String visitIntegerLiteralExp(IntegerLiteralExp<C> il)
          Callback for an IntegerLiteralExp visit.
 String visitInvalidLiteralExp(InvalidLiteralExp<C> il)
          Simply returns AbstractVisitor.result.
 String visitNullLiteralExp(NullLiteralExp<C> il)
          Simply returns AbstractVisitor.result.
 String visitRealLiteralExp(RealLiteralExp<C> rl)
          Callback for a RealLiteralExp visit.
 String visitStateExp(StateExp<C,S> s)
          Simply returns AbstractVisitor.result.
 String visitStringLiteralExp(StringLiteralExp<C> sl)
          Callback for a StringLiteralExp visit.
 String visitTypeExp(TypeExp<C> t)
          Simply returns AbstractVisitor.result.
 String visitUnlimitedNaturalLiteralExp(UnlimitedNaturalLiteralExp<C> unl)
          Callback for an UnlimitedNaturalLiteralExp visit.
 String visitUnspecifiedValueExp(UnspecifiedValueExp<C> uv)
          Callback for an UnspecifiedValueExp visit.
 String visitVariableExp(VariableExp<C,PM> v)
          Callback for a VariableExp visit.
 
Methods inherited from class org.eclipse.ocl.utilities.AbstractVisitor
handleConstraint, handleExpressionInOCL, safeVisit, visitAssociationClassCallExp, visitCollectionItem, visitCollectionLiteralExp, visitCollectionRange, visitIfExp, visitIterateExp, visitIteratorExp, visitLetExp, visitMessageExp, visitOperationCallExp, visitPropertyCallExp, visitTupleLiteralExp, visitTupleLiteralPart, visitVariable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_PLACEHOLDER

protected static String NULL_PLACEHOLDER
Indicates where a required element in the AST was null, so that it is evident in the debugger that something was missing. We don't want just "null" because that would look like the OclVoid literal.

Constructor Detail

ToStringVisitor

protected ToStringVisitor(Environment<?,C,O,P,EL,PM,S,COA,SSA,CT,?,?> env)
Initializes me with my environment.

Parameters:
env - my environment
Method Detail

getInstance

public static <C,O,P,EL,PM,S,COA,SSA,CT> ToStringVisitor<C,O,P,EL,PM,S,COA,SSA,CT> getInstance(Environment<?,C,O,P,EL,PM,S,COA,SSA,CT,?,?> env)
Obtains an instance of the toString() visitor for the specified environment.

Parameters:
env - an OCL environment
Returns:
the corresponding instance

getInstance

public static <C,O,P,EL,PM,S,COA,SSA,CT> ToStringVisitor<C,O,P,EL,PM,S,COA,SSA,CT> getInstance(TypedElement<C> element)
Obtains an instance of the toString() visitor for the specified expression or other typed element.

Parameters:
element - an OCL expression or other typed element such as a variable
Returns:
the corresponding instance

getName

protected String getName(Object named)
Null-safe access to the name of a named element.

Parameters:
named - a named element or null
Returns:
a name, or the null placeholder if the named element or its name be null. i.e., null is never returned

getQualifiedName

protected String getQualifiedName(Object named)
Null-safe access to the qualified name of a named element.

Parameters:
named - a named element or null
Returns:
a qualified name, or the null placeholder if the named element or its name be null. i.e., null is never returned

handleOperationCallExp

protected String handleOperationCallExp(OperationCallExp<C,O> oc,
                                        String sourceResult,
                                        List<String> argumentResults)
Callback for an OperationCallExp visit. Look at the source to determine operator ( -> or . )

Overrides:
handleOperationCallExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
oc - the operation call expression
sourceResult - the result of visiting the expression's source
argumentResults - the results of visiting the expression's arguments, or an empty list if there are no arguments
Returns:
string
See Also:
AbstractVisitor.visitOperationCallExp(OperationCallExp)

visitEnumLiteralExp

public String visitEnumLiteralExp(EnumLiteralExp<C,EL> el)
Callback for an EnumLiteralExp visit.

Specified by:
visitEnumLiteralExp in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitEnumLiteralExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
el - the enumeration literal expresion
Returns:
the enumeration literal toString()

visitVariableExp

public String visitVariableExp(VariableExp<C,PM> v)
Callback for a VariableExp visit.

Specified by:
visitVariableExp in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitVariableExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
v - the variable expression
Returns:
the variable name

handlePropertyCallExp

protected String handlePropertyCallExp(PropertyCallExp<C,P> pc,
                                       String sourceResult,
                                       List<String> qualifierResults)
Callback for an AssociationEndCallExp visit.

Overrides:
handlePropertyCallExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
pc - the property call expression
sourceResult - the result of visiting the expression's source
qualifierResults - the results of visiting the expression's qualifiers, or an empty list if there are no qualifiers
Returns:
string source.ref
See Also:
AbstractVisitor.visitPropertyCallExp(PropertyCallExp)

handleAssociationClassCallExp

protected String handleAssociationClassCallExp(AssociationClassCallExp<C,P> ac,
                                               String sourceResult,
                                               List<String> qualifierResults)
Callback for an AssociationClassCallExp visit.

Overrides:
handleAssociationClassCallExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
ac - the association class expression
sourceResult - the result of visiting the expression's source
qualifierResults - the results of visiting the expression's qualifiers, or an empty list if there are no qualifiers
Returns:
string source.ref
See Also:
AbstractVisitor.visitAssociationClassCallExp(AssociationClassCallExp)

initialLower

protected String initialLower(String name)

handleVariable

protected String handleVariable(Variable<C,PM> vd,
                                String initResult)
Callback for the Variable visit.

Overrides:
handleVariable in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
vd - the variable declaration
initResult - the result of visiting the expression's initializer, or null if it has none
Returns:
string
See Also:
AbstractVisitor.visitVariable(Variable)

handleIfExp

protected String handleIfExp(IfExp<C> ifExp,
                             String conditionResult,
                             String thenResult,
                             String elseResult)
Callback for an IfExp visit.

Overrides:
handleIfExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
ifExp - an IfExp
conditionResult - the result of visiting the expression's condition
thenResult - the result of visiting the expression's then
elseResult - the result of visiting the expression's else
Returns:
the string representation
See Also:
AbstractVisitor.visitIfExp(IfExp)

visitTypeExp

public String visitTypeExp(TypeExp<C> t)
Description copied from class: AbstractVisitor
Simply returns AbstractVisitor.result.

Specified by:
visitTypeExp in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitTypeExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>

visitStateExp

public String visitStateExp(StateExp<C,S> s)
Description copied from class: AbstractVisitor
Simply returns AbstractVisitor.result.

Specified by:
visitStateExp in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitStateExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>

visitUnspecifiedValueExp

public String visitUnspecifiedValueExp(UnspecifiedValueExp<C> uv)
Callback for an UnspecifiedValueExp visit.

Specified by:
visitUnspecifiedValueExp in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitUnspecifiedValueExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
uv - - UnspecifiedValueExp
Returns:
the string representation

visitIntegerLiteralExp

public String visitIntegerLiteralExp(IntegerLiteralExp<C> il)
Callback for an IntegerLiteralExp visit.

Specified by:
visitIntegerLiteralExp in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitIntegerLiteralExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
il - -- integer literal expression
Returns:
String

visitUnlimitedNaturalLiteralExp

public String visitUnlimitedNaturalLiteralExp(UnlimitedNaturalLiteralExp<C> unl)
Callback for an UnlimitedNaturalLiteralExp visit.

Specified by:
visitUnlimitedNaturalLiteralExp in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitUnlimitedNaturalLiteralExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
unl - -- unlimited natural literal expression
Returns:
String

visitRealLiteralExp

public String visitRealLiteralExp(RealLiteralExp<C> rl)
Callback for a RealLiteralExp visit.

Specified by:
visitRealLiteralExp in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitRealLiteralExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
rl - -- real literal expression
Returns:
the value of the real literal as a java.lang.Double.

visitStringLiteralExp

public String visitStringLiteralExp(StringLiteralExp<C> sl)
Callback for a StringLiteralExp visit.

Specified by:
visitStringLiteralExp in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitStringLiteralExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
sl - -- string literal expression
Returns:
the value of the string literal as a java.lang.String.

visitBooleanLiteralExp

public String visitBooleanLiteralExp(BooleanLiteralExp<C> bl)
Callback for a BooleanLiteralExp visit.

Specified by:
visitBooleanLiteralExp in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitBooleanLiteralExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
bl - -- boolean literal expression
Returns:
the value of the boolean literal as a java.lang.Boolean.

handleLetExp

protected String handleLetExp(LetExp<C,PM> letExp,
                              String variableResult,
                              String inResult)
Callback for LetExp visit.

Overrides:
handleLetExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
letExp - a let expression
variableResult - the result of visiting the expression's variable
inResult - the result of visiting the expression's in expression
Returns:
the string representation
See Also:
AbstractVisitor.visitLetExp(LetExp)

handleIterateExp

protected String handleIterateExp(IterateExp<C,PM> callExp,
                                  String sourceResult,
                                  List<String> variableResults,
                                  String resultResult,
                                  String bodyResult)
Callback for an IterateExp visit.

Overrides:
handleIterateExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
callExp - an iterate expression
sourceResult - the result of visiting the expression's source
variableResults - the results of visiting the expression's iterator variables
resultResult - the result of visiting the expressions' result variable
bodyResult - the result of visiting the expression's body
Returns:
the string representation
See Also:
AbstractVisitor.visitIterateExp(IterateExp)

handleIteratorExp

protected String handleIteratorExp(IteratorExp<C,PM> callExp,
                                   String sourceResult,
                                   List<String> variableResults,
                                   String bodyResult)
Callback for an IteratorExp visit.

Overrides:
handleIteratorExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
callExp - an iterator expression
sourceResult - the result of visiting the expression's source
variableResults - the results of visiting the expression's iterator variables
bodyResult - the result of visiting the expression's body
Returns:
the string representation
See Also:
AbstractVisitor.visitIteratorExp(IteratorExp)

handleCollectionLiteralExp

protected String handleCollectionLiteralExp(CollectionLiteralExp<C> cl,
                                            List<String> partResults)
Callback for a CollectionLiteralExp visit.

Overrides:
handleCollectionLiteralExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
cl - collection literal expression
partResults - the results of visiting the expression's parts, or an empty list if there are no parts
Returns:
String
See Also:
AbstractVisitor.visitCollectionLiteralExp(CollectionLiteralExp)

handleCollectionItem

protected String handleCollectionItem(CollectionItem<C> item,
                                      String itemResult)
Description copied from class: AbstractVisitor
Visits the specified collection item with the result of visiting its item expression.

Overrides:
handleCollectionItem in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
item - the collection item
itemResult - the result of visiting the item's item expression
Returns:
the accumulated AbstractVisitor.result, by default
See Also:
AbstractVisitor.visitCollectionItem(CollectionItem)

handleCollectionRange

protected String handleCollectionRange(CollectionRange<C> range,
                                       String firstResult,
                                       String lastResult)
Description copied from class: AbstractVisitor
Visits the specified collection range with the results of visiting its first and last expressions.

Overrides:
handleCollectionRange in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
range - the collection range
firstResult - the result of visiting the range's first expression
lastResult - the result of visiting the range's last expression
Returns:
the accumulated AbstractVisitor.result, by default
See Also:
AbstractVisitor.visitCollectionRange(CollectionRange)

handleTupleLiteralExp

protected String handleTupleLiteralExp(TupleLiteralExp<C,P> literalExp,
                                       List<String> partResults)
Callback for a TupleLiteralExp visit.

Overrides:
handleTupleLiteralExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
literalExp - tuple literal expression
partResults - the results of visiting the expression's parts, or an empty list if there are no parts
Returns:
the string representation
See Also:
AbstractVisitor.visitTupleLiteralExp(TupleLiteralExp)

handleTupleLiteralPart

protected String handleTupleLiteralPart(TupleLiteralPart<C,P> part,
                                        String valueResult)
Description copied from class: AbstractVisitor
Visits the specified tuple literal part with the results of visiting its value (if any).

Overrides:
handleTupleLiteralPart in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
part - the tuple literal part
valueResult - the result of visiting the expression's value, or null if it has no value
Returns:
the accumulated AbstractVisitor.result, by default
See Also:
AbstractVisitor.visitTupleLiteralPart(TupleLiteralPart)

handleMessageExp

protected String handleMessageExp(MessageExp<C,COA,SSA> messageExp,
                                  String targetResult,
                                  List<String> argumentResults)
Description copied from class: AbstractVisitor
Visits the specified message expression with the results of visiting its target and arguments (if any).

Overrides:
handleMessageExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
messageExp - the message expression
targetResult - the result of visiting the expression's target
argumentResults - the results of visiting the expression's arguments, or an empty list if there are no arguments
Returns:
the accumulated AbstractVisitor.result, by default
See Also:
AbstractVisitor.visitMessageExp(MessageExp)

getOperation

protected O getOperation(COA callOperationAction)

getSignal

protected C getSignal(SSA sendSignalAction)

visitExpressionInOCL

public String visitExpressionInOCL(ExpressionInOCL<C,PM> expression)
Renders an ExpressionInOcl with its context variables and body.

Specified by:
visitExpressionInOCL in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitExpressionInOCL in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>

visitConstraint

public String visitConstraint(CT constraint)
Renders a constraint with its context and expression.

Specified by:
visitConstraint in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitConstraint in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
See Also:
AbstractVisitor.getSpecification(Object)

isClassifier

protected boolean isClassifier(Object element)

isOperation

protected boolean isOperation(Object element)

isProperty

protected boolean isProperty(Object element)

getConstrainedElements

protected List<EObject> getConstrainedElements(CT constraint)

getStereotype

protected String getStereotype(CT constraint)

getSpecification

protected ExpressionInOCL<C,PM> getSpecification(CT constraint)
Description copied from class: AbstractVisitor
Overridden by subclasses interested in visiting constraints, to get the constraint's specification.

Overrides:
getSpecification in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
constraint - a constraint
Returns:
its specification
See Also:
AbstractVisitor.visitConstraint(Object)

getType

protected C getType(Object typedElement)

getParameters

protected List<PM> getParameters(O operation)

visitInvalidLiteralExp

public String visitInvalidLiteralExp(InvalidLiteralExp<C> il)
Description copied from class: AbstractVisitor
Simply returns AbstractVisitor.result.

Specified by:
visitInvalidLiteralExp in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitInvalidLiteralExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>

visitNullLiteralExp

public String visitNullLiteralExp(NullLiteralExp<C> il)
Description copied from class: AbstractVisitor
Simply returns AbstractVisitor.result.

Specified by:
visitNullLiteralExp in interface Visitor<String,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitNullLiteralExp in class AbstractVisitor<String,C,O,P,EL,PM,S,COA,SSA,CT>

Copyright 2002, 2007 IBM Corporation and others.
All Rights Reserved.