org.eclipse.ocl
Class AbstractEvaluationVisitor<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>

java.lang.Object
  extended by org.eclipse.ocl.utilities.AbstractVisitor<Object,C,O,P,EL,PM,S,COA,SSA,CT>
      extended by org.eclipse.ocl.AbstractEvaluationVisitor<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
All Implemented Interfaces:
EvaluationVisitor<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>, Visitor<Object,C,O,P,EL,PM,S,COA,SSA,CT>

public abstract class AbstractEvaluationVisitor<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
extends AbstractVisitor<Object,C,O,P,EL,PM,S,COA,SSA,CT>
implements EvaluationVisitor<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>

An evaluation visitor implementation for OCL expressions.

Note that this class is not intended to be used or extended by clients. Use the AbstractEvaluationVisitor interface, instead.

See the Environment class for a description of the generic type parameters of this class.


Field Summary
 
Fields inherited from class org.eclipse.ocl.utilities.AbstractVisitor
result
 
Constructor Summary
protected AbstractEvaluationVisitor(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, EvaluationEnvironment<C,O,P,CLS,E> evalEnv, Map<? extends CLS,? extends Set<? extends E>> extentMap)
          Initializes me.
 
Method Summary
protected  Object call(O operation, OCLExpression<C> body, Object target, Object[] args)
          Invokes the specified additional operation on a target object.
protected  Number coerceNumber(Number number)
           Tests whether a given number can be safely coerced to Double or Integer without changing the value of the number.
protected  C getBoolean()
          Obtains my environment's implementation of the OCL Boolean type.
 Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> getEnvironment()
          Obtains the environment that provides the metamodel semantics for the expression to be evaluated.
 EvaluationEnvironment<C,O,P,CLS,E> getEvaluationEnvironment()
          Obtains the evaluation environment that keeps track of variable values and knows how to call operations, navigate properties, etc.
 Map<? extends CLS,? extends Set<? extends E>> getExtentMap()
          Obtains the mapping of model classes to their extends.
protected  C getInteger()
          Obtains my environment's implementation of the OCL Integer type.
protected  String getName(Object namedElement)
          Obtains the name of the specified element, if it has one.
protected  Object getOclInvalid()
          Obtains my environment's implementation of the OclInvalid value.
protected  OCLExpression<C> getOperationBody(O operation)
          Obtains the body of the specified operation's def or body expression, if any.
protected  OCLExpression<C> getPropertyBody(P property)
          Obtains the body of the specified property's def or der expression, if any.
protected  C getReal()
          Obtains my environment's implementation of the OCL Real type.
protected  ExpressionInOCL<C,PM> getSpecification(CT constraint)
          Overridden by subclasses interested in visiting constraints, to get the constraint's specification.
protected  OCLStandardLibrary<C> getStandardLibrary()
          Obtains my environment's OCL Standard Library implementation.
protected  C getString()
          Obtains my environment's implementation of the OCL String type.
protected  UMLReflection<PK,C,O,P,EL,PM,S,COA,SSA,CT> getUMLReflection()
           
protected  C getUnlimitedNatural()
          Obtains my environment's implementation of the OCL UnlimitedNatural type.
protected  EvaluationVisitor<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> getVisitor()
          Obtains the visitor on which I perform nested Visitable.accept(org.eclipse.ocl.utilities.Visitor) calls.
protected  Number higherPrecisionNumber(Number number)
           Coerces the given number to Double or Long precision, if possible.
protected  boolean isUndefined(Object value)
          Convenience method to determine whether the specified value is the null or OclInvalid.
protected  Object navigate(P property, OCLExpression<C> derivation, Object target)
          Obtains an object's value of the specified additional property.
protected  Boolean oclIsKindOf(Object value, Object typeArg)
          Checks whether the supplied value is an instance of the supplied type or one of its super types.
protected  Boolean oclIsTypeOf(Object value, Object typeArg)
          Checks whether the supplied object is an instance of the supplied type.
 String toString()
           
 Object visitConstraint(CT constraint)
          This default implementation asserts that the constraint is boolean-valued if it is an invariant, pre-condition, or post-condition constraint and returns the value of its body expression by delegation to visitExpression(OCLExpression).
 Object visitExpression(OCLExpression<C> expression)
          This default implementation simply asks the expression to accept me.
 
Methods inherited from class org.eclipse.ocl.utilities.AbstractVisitor
handleAssociationClassCallExp, handleCollectionItem, handleCollectionLiteralExp, handleCollectionRange, handleConstraint, handleExpressionInOCL, handleIfExp, handleIterateExp, handleIteratorExp, handleLetExp, handleMessageExp, handleOperationCallExp, handlePropertyCallExp, handleTupleLiteralExp, handleTupleLiteralPart, handleVariable, safeVisit, visitAssociationClassCallExp, visitBooleanLiteralExp, visitCollectionItem, visitCollectionLiteralExp, visitCollectionRange, visitEnumLiteralExp, visitExpressionInOCL, visitIfExp, visitIntegerLiteralExp, visitInvalidLiteralExp, visitIterateExp, visitIteratorExp, visitLetExp, visitMessageExp, visitNullLiteralExp, visitOperationCallExp, visitPropertyCallExp, visitRealLiteralExp, visitStateExp, visitStringLiteralExp, visitTupleLiteralExp, visitTupleLiteralPart, visitTypeExp, visitUnlimitedNaturalLiteralExp, visitUnspecifiedValueExp, visitVariable, visitVariableExp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.ocl.utilities.Visitor
visitAssociationClassCallExp, visitBooleanLiteralExp, visitCollectionItem, visitCollectionLiteralExp, visitCollectionRange, visitEnumLiteralExp, visitExpressionInOCL, visitIfExp, visitIntegerLiteralExp, visitInvalidLiteralExp, visitIterateExp, visitIteratorExp, visitLetExp, visitMessageExp, visitNullLiteralExp, visitOperationCallExp, visitPropertyCallExp, visitRealLiteralExp, visitStateExp, visitStringLiteralExp, visitTupleLiteralExp, visitTupleLiteralPart, visitTypeExp, visitUnlimitedNaturalLiteralExp, visitUnspecifiedValueExp, visitVariable, visitVariableExp
 

Constructor Detail

AbstractEvaluationVisitor

protected AbstractEvaluationVisitor(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                    EvaluationEnvironment<C,O,P,CLS,E> evalEnv,
                                    Map<? extends CLS,? extends Set<? extends E>> extentMap)
Initializes me.

Parameters:
env - the current environment
evalEnv - an evaluation environment (map of variable names to values)
extentMap - a map of classes to their instance sets
Method Detail

getVisitor

protected final EvaluationVisitor<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> getVisitor()
Obtains the visitor on which I perform nested Visitable.accept(org.eclipse.ocl.utilities.Visitor) calls. This handles the case in which I am decorated by another visitor that must intercept every visitXxx() method. If I internally just recursively visit myself, then this decorator is cut out of the picture.

Returns:
my delegate visitor, which may be my own self or some other

getEvaluationEnvironment

public EvaluationEnvironment<C,O,P,CLS,E> getEvaluationEnvironment()
Description copied from interface: EvaluationVisitor
Obtains the evaluation environment that keeps track of variable values and knows how to call operations, navigate properties, etc.

Specified by:
getEvaluationEnvironment in interface EvaluationVisitor<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
Returns:
the evaluation environment

getEnvironment

public Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> getEnvironment()
Description copied from interface: EvaluationVisitor
Obtains the environment that provides the metamodel semantics for the expression to be evaluated.

Specified by:
getEnvironment in interface EvaluationVisitor<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
Returns:
the environment

getUMLReflection

protected UMLReflection<PK,C,O,P,EL,PM,S,COA,SSA,CT> getUMLReflection()

getExtentMap

public Map<? extends CLS,? extends Set<? extends E>> getExtentMap()
Description copied from interface: EvaluationVisitor
Obtains the mapping of model classes to their extends.

Specified by:
getExtentMap in interface EvaluationVisitor<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
Returns:
the extent map

getStandardLibrary

protected OCLStandardLibrary<C> getStandardLibrary()
Obtains my environment's OCL Standard Library implementation.

Returns:
the OCL standard library

getOclInvalid

protected final Object getOclInvalid()
Obtains my environment's implementation of the OclInvalid value.

Returns:
the invalid result

getBoolean

protected final C getBoolean()
Obtains my environment's implementation of the OCL Boolean type.

Returns:
the boolean type

getString

protected final C getString()
Obtains my environment's implementation of the OCL String type.

Returns:
the string type

getInteger

protected final C getInteger()
Obtains my environment's implementation of the OCL Integer type.

Returns:
the integer type

getUnlimitedNatural

protected final C getUnlimitedNatural()
Obtains my environment's implementation of the OCL UnlimitedNatural type.

Returns:
the unlimited natural type

getReal

protected final C getReal()
Obtains my environment's implementation of the OCL Real type.

Returns:
the real type

getName

protected String getName(Object namedElement)
Obtains the name of the specified element, if it has one.

Parameters:
namedElement - a named element
Returns:
its name, or null if it has none

visitExpression

public Object visitExpression(OCLExpression<C> expression)
This default implementation simply asks the expression to accept me.

Specified by:
visitExpression in interface EvaluationVisitor<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
Parameters:
expression - an OCL expression to evaluate
Returns:
the result of the evaluation

visitConstraint

public Object visitConstraint(CT constraint)
This default implementation asserts that the constraint is boolean-valued if it is an invariant, pre-condition, or post-condition constraint and returns the value of its body expression by delegation to visitExpression(OCLExpression).

Specified by:
visitConstraint in interface EvaluationVisitor<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
Specified by:
visitConstraint in interface Visitor<Object,C,O,P,EL,PM,S,COA,SSA,CT>
Overrides:
visitConstraint in class AbstractVisitor<Object,C,O,P,EL,PM,S,COA,SSA,CT>
Returns:
for boolean-valued constraints (invariant, precondition, postcondition) Boolean.TRUE if the constraint holds and Boolean.FALSE if it is violated (including evaluations that result in OclInvalid). For operation body conditions, the value of the operation result
See Also:
AbstractVisitor.getSpecification(Object)

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<Object,C,O,P,EL,PM,S,COA,SSA,CT>
Parameters:
constraint - a constraint
Returns:
its specification
See Also:
AbstractVisitor.visitConstraint(Object)

toString

public String toString()
Overrides:
toString in class Object

isUndefined

protected boolean isUndefined(Object value)
Convenience method to determine whether the specified value is the null or OclInvalid.

Parameters:
value - a value
Returns:
whether it is undefined

call

protected Object call(O operation,
                      OCLExpression<C> body,
                      Object target,
                      Object[] args)
Invokes the specified additional operation on a target object. The invocation is performed in a nested evaluation environment.

Parameters:
operation - the operation to invoke
body - the operation's body expression
target - the object on which to evaluate the operation body
args - the arguments to the operation call

getOperationBody

protected OCLExpression<C> getOperationBody(O operation)
Obtains the body of the specified operation's def or body expression, if any.

Parameters:
operation - an operation
Returns:
its value expression, if any

getPropertyBody

protected OCLExpression<C> getPropertyBody(P property)
Obtains the body of the specified property's def or der expression, if any.

Parameters:
property - a property
Returns:
its value expression, if any

navigate

protected Object navigate(P property,
                          OCLExpression<C> derivation,
                          Object target)
Obtains an object's value of the specified additional property.

Parameters:
property - the property to navigate
derivation - the expression that computes its value
target - the object in which context to evaluate the derivation
Returns:
the property's value

oclIsTypeOf

protected Boolean oclIsTypeOf(Object value,
                              Object typeArg)
Checks whether the supplied object is an instance of the supplied type.

Parameters:
value - the value to check
typeArg - the type to check
Returns:
true if the object is an instance of the type, false otherwise.

oclIsKindOf

protected Boolean oclIsKindOf(Object value,
                              Object typeArg)
Checks whether the supplied value is an instance of the supplied type or one of its super types.

Parameters:
value - the value to check
typeArg - the type to check
Returns:
true iff the value is of the type or one of its super types.

coerceNumber

protected Number coerceNumber(Number number)

Tests whether a given number can be safely coerced to Double or Integer without changing the value of the number. Safe means that coercing a number to Double or Integer and then coercing it back to the original type will result in the same value (no loss of precision). This is trivial for types, which have a smaller domain then Integer or Double, but for example a Long number may not be safely coerced to Integer.

If the coercion is safe, the number will be returned as either Double or Integer, as appropriate to the original precision. Otherwise the original number is returned.

Parameters:
number - a number to coerce to Integer or Double
Returns:
the coerced number, or the original number, if coercion was not safe
Since:
1.2

higherPrecisionNumber

protected Number higherPrecisionNumber(Number number)

Coerces the given number to Double or Long precision, if possible. Note that this is only impossible for BigDecimal or BigInteger values, respectively, that are out of range of their primitive counterparts.

Parameters:
number - a number to coerce to Long or Double
Returns:
the coerced number, or the original number, in case of overflow
Since:
1.2

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