org.eclipse.ocl.utilities
Class AbstractVisitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

java.lang.Object
  extended by org.eclipse.ocl.utilities.AbstractVisitor<T,C,O,P,EL,PM,S,COA,SSA,CT>
All Implemented Interfaces:
Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>
Direct Known Subclasses:
AbstractEvaluationVisitor, AbstractVisitor, FilterSynthesisImpl, FindAlwaysUsedVariablesVisitor, ToStringVisitor

public abstract class AbstractVisitor<T,C,O,P,EL,PM,S,COA,SSA,CT>
extends java.lang.Object
implements Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

An abstract implementation of the Visitor API, in which subclasses need only selectively override handleXxx(...) methods for internal AST nodes and visitXxx(...) methods for leaf nodes.

The result value is convenient for accumulating the result of the visitation. In the subclass, simply assign/modify the result value as necessary in the overridden visitation methods, and this framework will ensure that it is returned as the overall value of the Visitable.accept(Visitor) call.

Author:
Christian W. Damus (cdamus)

Field Summary
protected  T result
          Accumulator for the result of the AST visitation.
 
Constructor Summary
protected AbstractVisitor()
          Initializes me.
protected AbstractVisitor(T initialValue)
          Initializes me with an initial value for my result.
 
Method Summary
protected  ExpressionInOCL<C,PM> getSpecification(CT constraint)
          Overridden by subclasses interested in visiting constraints, to get the constraint's specification.
protected  T handleAssociationClassCallExp(AssociationClassCallExp<C,P> callExp, T sourceResult, java.util.List<T> qualifierResults)
          Visits the specified association-class call with the results of visiting its source and qualifiers (if any).
protected  T handleCollectionItem(CollectionItem<C> item, T itemResult)
          Visits the specified collection item with the result of visiting its item expression.
protected  T handleCollectionLiteralExp(CollectionLiteralExp<C> literalExp, java.util.List<T> partResults)
          Visits the specified collection literal expression with the results of visiting its parts (if any).
protected  T handleCollectionRange(CollectionRange<C> range, T firstResult, T lastResult)
          Visits the specified collection range with the results of visiting its first and last expressions.
protected  T handleConstraint(CT constraint, T specificationResult)
          Visits the specified constraint with the results of visiting its specification.
protected  T handleExpressionInOCL(ExpressionInOCL<C,PM> expression, T contextResult, T resultResult, java.util.List<T> parameterResults, T bodyResult)
          Visits the specified expression-in-OCL with the results of visiting its context variable, its result variable (if any), its parameter variables (if any), and its body expression.
protected  T handleIfExp(IfExp<C> ifExp, T conditionResult, T thenResult, T elseResult)
          Visits the specified if expression with the results of visiting its condition, then, and else expressions.
protected  T handleIterateExp(IterateExp<C,PM> callExp, T sourceResult, java.util.List<T> variableResults, T resultResult, T bodyResult)
          Visits the specified iterate expression with the results of visiting its source, its iterator variables, its result variable, and its body expression.
protected  T handleIteratorExp(IteratorExp<C,PM> callExp, T sourceResult, java.util.List<T> variableResults, T bodyResult)
          Visits the specified iterator expression with the results of visiting its source, its iterator variables, and its body expression.
protected  T handleLetExp(LetExp<C,PM> letExp, T variableResult, T inResult)
          Visits the specified let expression with the results of visiting its variable and in expression.
protected  T handleMessageExp(MessageExp<C,COA,SSA> messageExp, T targetResult, java.util.List<T> argumentResults)
          Visits the specified message expression with the results of visiting its target and arguments (if any).
protected  T handleOperationCallExp(OperationCallExp<C,O> callExp, T sourceResult, java.util.List<T> argumentResults)
          Visits the specified operation call with the results of visiting its source and arguments (if any).
protected  T handlePropertyCallExp(PropertyCallExp<C,P> callExp, T sourceResult, java.util.List<T> qualifierResults)
          Visits the specified property call with the results of visiting its source and qualifiers (if any).
protected  T handleTupleLiteralExp(TupleLiteralExp<C,P> literalExp, java.util.List<T> partResults)
          Visits the specified tuple literal expression with the results of visiting its parts (if any).
protected  T handleTupleLiteralPart(TupleLiteralPart<C,P> part, T valueResult)
          Visits the specified tuple literal part with the results of visiting its value (if any).
protected  T handleVariable(Variable<C,PM> variable, T initResult)
          Visits the specified variable with the results of visiting its initializer (if any).
protected  T safeVisit(Visitable v)
          A null-safe visitation of the specified visitable.
 T visitAssociationClassCallExp(AssociationClassCallExp<C,P> callExp)
          Visits the association-class-call source and then its qualifiers (if any).
 T visitBooleanLiteralExp(BooleanLiteralExp<C> literalExp)
          Simply returns result.
 T visitCollectionItem(CollectionItem<C> item)
          Visits the item's item expression.
 T visitCollectionLiteralExp(CollectionLiteralExp<C> literalExp)
          Visits the collection literal's parts.
 T visitCollectionRange(CollectionRange<C> range)
          Visits the range's first and last expressions.
 T visitConstraint(CT constraint)
          Visits the constraint's specification, if any (and if the getSpecification(Object) method is overridden).
 T visitEnumLiteralExp(EnumLiteralExp<C,EL> literalExp)
          Simply returns result.
 T visitExpressionInOCL(ExpressionInOCL<C,PM> expression)
          Visits the expressions context variable, its parameter variables (if any), its result variable (if any), and finally its body expression.
 T visitIfExp(IfExp<C> ifExp)
          Visits the if expression's condition, then, and else expressions.
 T visitIntegerLiteralExp(IntegerLiteralExp<C> literalExp)
          Simply returns result.
 T visitInvalidLiteralExp(InvalidLiteralExp<C> literalExp)
          Simply returns result.
 T visitIterateExp(IterateExp<C,PM> callExp)
          Visits the iterate's source, then its iterator variables, result variable, and body expression.
 T visitIteratorExp(IteratorExp<C,PM> callExp)
          Visits the iterator's source, then its variables, followed by its body expression.
 T visitLetExp(LetExp<C,PM> letExp)
          Visits the let's variable declaration then its 'in' expression.
 T visitMessageExp(MessageExp<C,COA,SSA> messageExp)
          Visits the message expression's target and then its arguments.
 T visitNullLiteralExp(NullLiteralExp<C> literalExp)
          Simply returns result.
 T visitOperationCallExp(OperationCallExp<C,O> callExp)
          Visits the operation-call source and then its arguments.
 T visitPropertyCallExp(PropertyCallExp<C,P> callExp)
          Visits the property-call source and then its qualifiers (if any).
 T visitRealLiteralExp(RealLiteralExp<C> literalExp)
          Simply returns result.
 T visitStateExp(StateExp<C,S> stateExp)
          Simply returns result.
 T visitStringLiteralExp(StringLiteralExp<C> literalExp)
          Simply returns result.
 T visitTupleLiteralExp(TupleLiteralExp<C,P> literalExp)
          Visits the tuple literal's parts.
 T visitTupleLiteralPart(TupleLiteralPart<C,P> part)
          Visits the tuple literal part's value, if any.
 T visitTypeExp(TypeExp<C> t)
          Simply returns result.
 T visitUnlimitedNaturalLiteralExp(UnlimitedNaturalLiteralExp<C> literalExp)
          Simply returns result.
 T visitUnspecifiedValueExp(UnspecifiedValueExp<C> unspecExp)
          Simply returns result.
 T visitVariable(Variable<C,PM> variable)
          Visits the variable's initialization expression (if any).
 T visitVariableExp(VariableExp<C,PM> v)
          Simply returns result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

result

protected T result
Accumulator for the result of the AST visitation.

Constructor Detail

AbstractVisitor

protected AbstractVisitor()
Initializes me.


AbstractVisitor

protected AbstractVisitor(T initialValue)
Initializes me with an initial value for my result.

Parameters:
initialValue - my initial result value
Method Detail

safeVisit

protected T safeVisit(Visitable v)
A null-safe visitation of the specified visitable.

Parameters:
v - a visitable, or null
Returns:
null if the visitable is null; otherwise, the result of visiting it
Since:
1.2

visitOperationCallExp

public T visitOperationCallExp(OperationCallExp<C,O> callExp)
Visits the operation-call source and then its arguments. Returns the result of handleOperationCallExp(OperationCallExp, Object, List).

Specified by:
visitOperationCallExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleOperationCallExp

protected T handleOperationCallExp(OperationCallExp<C,O> callExp,
                                   T sourceResult,
                                   java.util.List<T> argumentResults)
Visits the specified operation call with the results of visiting its source and arguments (if any).

Parameters:
callExp - 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:
the accumulated result, by default
See Also:
visitOperationCallExp(OperationCallExp)

visitVariableExp

public T visitVariableExp(VariableExp<C,PM> v)
Simply returns result.

Specified by:
visitVariableExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

visitPropertyCallExp

public T visitPropertyCallExp(PropertyCallExp<C,P> callExp)
Visits the property-call source and then its qualifiers (if any). Returns the result of handlePropertyCallExp(PropertyCallExp, Object, List).

Specified by:
visitPropertyCallExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handlePropertyCallExp

protected T handlePropertyCallExp(PropertyCallExp<C,P> callExp,
                                  T sourceResult,
                                  java.util.List<T> qualifierResults)
Visits the specified property call with the results of visiting its source and qualifiers (if any). Note that in the case of a property call expression as a qualifier of an association class call, the property call does not have a source and, therefore, the sourceResult will be null in that case.

Parameters:
callExp - the property call expression, if there is a source
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:
the accumulated result, by default
See Also:
visitPropertyCallExp(PropertyCallExp)

visitAssociationClassCallExp

public T visitAssociationClassCallExp(AssociationClassCallExp<C,P> callExp)
Visits the association-class-call source and then its qualifiers (if any). Returns the result of handleAssociationClassCallExp(AssociationClassCallExp, Object, List).

Specified by:
visitAssociationClassCallExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleAssociationClassCallExp

protected T handleAssociationClassCallExp(AssociationClassCallExp<C,P> callExp,
                                          T sourceResult,
                                          java.util.List<T> qualifierResults)
Visits the specified association-class call with the results of visiting its source and qualifiers (if any).

Parameters:
callExp - the association-class 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:
the accumulated result, by default
See Also:
visitAssociationClassCallExp(AssociationClassCallExp)

visitVariable

public T visitVariable(Variable<C,PM> variable)
Visits the variable's initialization expression (if any). Returns the result of handleVariable(Variable, Object).

Specified by:
visitVariable in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleVariable

protected T handleVariable(Variable<C,PM> variable,
                           T initResult)
Visits the specified variable with the results of visiting its initializer (if any).

Parameters:
variable - the variable
initResult - the result of visiting the expression's initializer, or null if it has none
Returns:
the accumulated result, by default
See Also:
visitVariable(Variable)

visitIfExp

public T visitIfExp(IfExp<C> ifExp)
Visits the if expression's condition, then, and else expressions. Returns the result of handleIfExp(IfExp, Object, Object, Object).

Specified by:
visitIfExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleIfExp

protected T handleIfExp(IfExp<C> ifExp,
                        T conditionResult,
                        T thenResult,
                        T elseResult)
Visits the specified if expression with the results of visiting its condition, then, and else expressions.

Parameters:
ifExp - the if expression
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 accumulated result, by default
See Also:
visitIfExp(IfExp)

visitTypeExp

public T visitTypeExp(TypeExp<C> t)
Simply returns result.

Specified by:
visitTypeExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

visitMessageExp

public T visitMessageExp(MessageExp<C,COA,SSA> messageExp)
Visits the message expression's target and then its arguments. Returns the result of handleMessageExp(MessageExp, Object, List).

Specified by:
visitMessageExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleMessageExp

protected T handleMessageExp(MessageExp<C,COA,SSA> messageExp,
                             T targetResult,
                             java.util.List<T> argumentResults)
Visits the specified message expression with the results of visiting its target and arguments (if any).

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 result, by default
See Also:
visitMessageExp(MessageExp)

visitUnspecifiedValueExp

public T visitUnspecifiedValueExp(UnspecifiedValueExp<C> unspecExp)
Simply returns result.

Specified by:
visitUnspecifiedValueExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

visitStateExp

public T visitStateExp(StateExp<C,S> stateExp)
Simply returns result.

Specified by:
visitStateExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

visitIntegerLiteralExp

public T visitIntegerLiteralExp(IntegerLiteralExp<C> literalExp)
Simply returns result.

Specified by:
visitIntegerLiteralExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

visitUnlimitedNaturalLiteralExp

public T visitUnlimitedNaturalLiteralExp(UnlimitedNaturalLiteralExp<C> literalExp)
Simply returns result.

Specified by:
visitUnlimitedNaturalLiteralExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

visitRealLiteralExp

public T visitRealLiteralExp(RealLiteralExp<C> literalExp)
Simply returns result.

Specified by:
visitRealLiteralExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

visitStringLiteralExp

public T visitStringLiteralExp(StringLiteralExp<C> literalExp)
Simply returns result.

Specified by:
visitStringLiteralExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

visitBooleanLiteralExp

public T visitBooleanLiteralExp(BooleanLiteralExp<C> literalExp)
Simply returns result.

Specified by:
visitBooleanLiteralExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

visitNullLiteralExp

public T visitNullLiteralExp(NullLiteralExp<C> literalExp)
Simply returns result.

Specified by:
visitNullLiteralExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

visitInvalidLiteralExp

public T visitInvalidLiteralExp(InvalidLiteralExp<C> literalExp)
Simply returns result.

Specified by:
visitInvalidLiteralExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

visitTupleLiteralExp

public T visitTupleLiteralExp(TupleLiteralExp<C,P> literalExp)
Visits the tuple literal's parts. Returns the result of handleTupleLiteralExp(TupleLiteralExp, List).

Specified by:
visitTupleLiteralExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleTupleLiteralExp

protected T handleTupleLiteralExp(TupleLiteralExp<C,P> literalExp,
                                  java.util.List<T> partResults)
Visits the specified tuple literal expression with the results of visiting its parts (if any).

Parameters:
literalExp - the tuple literal expression
partResults - the results of visiting the expression's parts, or an empty list if there are no parts
Returns:
the accumulated result, by default
See Also:
visitTupleLiteralExp(TupleLiteralExp)

visitTupleLiteralPart

public T visitTupleLiteralPart(TupleLiteralPart<C,P> part)
Visits the tuple literal part's value, if any. Returns the result of handleTupleLiteralPart(TupleLiteralPart, Object).

Specified by:
visitTupleLiteralPart in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleTupleLiteralPart

protected T handleTupleLiteralPart(TupleLiteralPart<C,P> part,
                                   T valueResult)
Visits the specified tuple literal part with the results of visiting its value (if any).

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 result, by default
See Also:
visitTupleLiteralPart(TupleLiteralPart)

visitLetExp

public T visitLetExp(LetExp<C,PM> letExp)
Visits the let's variable declaration then its 'in' expression. Returns the result of handleLetExp(LetExp, Object, Object).

Specified by:
visitLetExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleLetExp

protected T handleLetExp(LetExp<C,PM> letExp,
                         T variableResult,
                         T inResult)
Visits the specified let expression with the results of visiting its variable and in expression.

Parameters:
letExp - the let expression
variableResult - the result of visiting the expression's variable
inResult - the result of visiting the expression's in expression
Returns:
the accumulated result, by default
See Also:
visitLetExp(LetExp)

visitEnumLiteralExp

public T visitEnumLiteralExp(EnumLiteralExp<C,EL> literalExp)
Simply returns result.

Specified by:
visitEnumLiteralExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

visitCollectionLiteralExp

public T visitCollectionLiteralExp(CollectionLiteralExp<C> literalExp)
Visits the collection literal's parts. Returns the result of handleCollectionLiteralExp(CollectionLiteralExp, List).

Specified by:
visitCollectionLiteralExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleCollectionLiteralExp

protected T handleCollectionLiteralExp(CollectionLiteralExp<C> literalExp,
                                       java.util.List<T> partResults)
Visits the specified collection literal expression with the results of visiting its parts (if any).

Parameters:
literalExp - the collection literal expression
partResults - the results of visiting the expression's parts, or an empty list if there are no parts
Returns:
the accumulated result, by default
See Also:
visitCollectionLiteralExp(CollectionLiteralExp)

visitCollectionItem

public T visitCollectionItem(CollectionItem<C> item)
Visits the item's item expression. Returns the result of handleCollectionItem(CollectionItem, Object)

Specified by:
visitCollectionItem in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleCollectionItem

protected T handleCollectionItem(CollectionItem<C> item,
                                 T itemResult)
Visits the specified collection item with the result of visiting its item expression.

Parameters:
item - the collection item
itemResult - the result of visiting the item's item expression
Returns:
the accumulated result, by default
See Also:
visitCollectionItem(CollectionItem)

visitCollectionRange

public T visitCollectionRange(CollectionRange<C> range)
Visits the range's first and last expressions. Returns the result of handleCollectionRange(CollectionRange, Object, Object).

Specified by:
visitCollectionRange in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleCollectionRange

protected T handleCollectionRange(CollectionRange<C> range,
                                  T firstResult,
                                  T lastResult)
Visits the specified collection range with the results of visiting its first and last expressions.

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 result, by default
See Also:
visitCollectionRange(CollectionRange)

visitIteratorExp

public T visitIteratorExp(IteratorExp<C,PM> callExp)
Visits the iterator's source, then its variables, followed by its body expression. Returns the result of handleIteratorExp(IteratorExp, Object, List, Object).

Specified by:
visitIteratorExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleIteratorExp

protected T handleIteratorExp(IteratorExp<C,PM> callExp,
                              T sourceResult,
                              java.util.List<T> variableResults,
                              T bodyResult)
Visits the specified iterator expression with the results of visiting its source, its iterator variables, and its body expression.

Parameters:
callExp - the 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 accumulated result, by default
See Also:
visitIteratorExp(IteratorExp)

visitIterateExp

public T visitIterateExp(IterateExp<C,PM> callExp)
Visits the iterate's source, then its iterator variables, result variable, and body expression. Returns the result of handleIterateExp(IterateExp, Object, List, Object, Object).

Specified by:
visitIterateExp in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleIterateExp

protected T handleIterateExp(IterateExp<C,PM> callExp,
                             T sourceResult,
                             java.util.List<T> variableResults,
                             T resultResult,
                             T bodyResult)
Visits the specified iterate expression with the results of visiting its source, its iterator variables, its result variable, and its body expression.

Parameters:
callExp - the 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 accumulated result, by default
See Also:
visitIterateExp(IterateExp)

visitExpressionInOCL

public T visitExpressionInOCL(ExpressionInOCL<C,PM> expression)
Visits the expressions context variable, its parameter variables (if any), its result variable (if any), and finally its body expression. Returns the result of handleExpressionInOCL(ExpressionInOCL, Object, Object, List, Object).

Specified by:
visitExpressionInOCL in interface Visitor<T,C,O,P,EL,PM,S,COA,SSA,CT>

handleExpressionInOCL

protected T handleExpressionInOCL(ExpressionInOCL<C,PM> expression,
                                  T contextResult,
                                  T resultResult,
                                  java.util.List<T> parameterResults,
                                  T bodyResult)
Visits the specified expression-in-OCL with the results of visiting its context variable, its result variable (if any), its parameter variables (if any), and its body expression.

Parameters:
expression - the expression-in-OCL
contextResult - the result of visiting the expression's context variable
resultResult - the result of visiting the expressions' result variable, or null if there is no result variable
parameterResults - the results of visiting the expression's parameter variables, or an empty list if there are none
bodyResult - the result of visiting the expression's body
Returns:
the accumulated result, by default
See Also:
visitExpressionInOCL(ExpressionInOCL)

visitConstraint

public T visitConstraint(CT constraint)
Visits the constraint's specification, if any (and if the getSpecification(Object) method is overridden). Returns the result of handleConstraint(Object, Object).

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

handleConstraint

protected T handleConstraint(CT constraint,
                             T specificationResult)
Visits the specified constraint with the results of visiting its specification.

Parameters:
constraint - the constraint
specificationResult - the result of visiting the constraint's specification, or null if either it has none or the getSpecification(Object) method is not overridden
Returns:
the accumulated result, by default #see getSpecification(Object)
See Also:
visitConstraint(Object)

getSpecification

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

Parameters:
constraint - a constraint
Returns:
its specification
See Also:
visitConstraint(Object)