org.eclipse.ocl.examples.impactanalyzer.filterSynthesis
Class FilterSynthesisImpl

java.lang.Object
  extended by org.eclipse.ocl.utilities.AbstractVisitor<org.eclipse.emf.ecore.EPackage,org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EEnumLiteral,org.eclipse.emf.ecore.EParameter,org.eclipse.emf.ecore.EObject,CallOperationAction,SendSignalAction,Constraint>
      extended by org.eclipse.ocl.examples.impactanalyzer.filterSynthesis.FilterSynthesisImpl
All Implemented Interfaces:
OperationBodyToCallMapper, Visitor<org.eclipse.emf.ecore.EPackage,org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EEnumLiteral,org.eclipse.emf.ecore.EParameter,org.eclipse.emf.ecore.EObject,CallOperationAction,SendSignalAction,Constraint>

public class FilterSynthesisImpl
extends AbstractVisitor<org.eclipse.emf.ecore.EPackage,org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EEnumLiteral,org.eclipse.emf.ecore.EParameter,org.eclipse.emf.ecore.EObject,CallOperationAction,SendSignalAction,Constraint>
implements OperationBodyToCallMapper

Collects the relevant events for a single OCLExpression recursively. The analyzer can be parameterized during construction such that it either registers for creation events on the context type or not. Registering for element creation on the context type is useful for invariants / constraints because when a new element is created, validating the constraint may be useful. For other use cases, registering for element creation may not be so useful. For example, when a type inferencer defines its rules using OCL, it only wants to receive update events after the element has been fully initialized from those OCLExpression. In those cases, some framework may be responsible for the initial evaluation of those OCLExpressions on new element, and therefore, context element creation events are not of interest.

Author:
Tobias Hoppe, Axel Uhl

Field Summary
protected  java.util.Map<org.eclipse.emf.ecore.EReference,java.util.Set<NavigationCallExp>> associationEndCallExpressions
           
protected  java.util.Set<EventFilter> filters
          For each OCLExpression analyzed, stores the filters to merge into the resulting filter
 
Fields inherited from class org.eclipse.ocl.utilities.AbstractVisitor
result
 
Constructor Summary
FilterSynthesisImpl(OCLExpression expression, boolean notifyNewContextElements, OCL ocl)
           
 
Method Summary
 java.util.Set<OperationCallExp> getAllInstancesCallsFor(org.eclipse.emf.ecore.EClassifier c)
          Always returns a non-null set.
 java.util.Set<NavigationCallExp> getAssociationEndCallExpressions(org.eclipse.emf.ecore.EReference a)
          Always returns a non-null set
 java.util.Set<PropertyCallExp> getAttributeCallExpressions(org.eclipse.emf.ecore.EAttribute a)
          Always returns a non-null set
 OCLExpression getBodyForCall(OperationCallExp call)
          Looks up if the OCLExpression that is called by the given OperationCallExp has already been visited.
 java.util.Set<OperationCallExp> getCallsOf(OCLExpression operationBodyExpression)
          Returns all the calls to the operation whose body is operationBodyExpression that are reachable from the root expression analyzed by this FilterSynthesisImpl.
 java.util.Map<OCLExpression,java.util.Set<PropertyCallExp>> getDerivedProperties()
           
 OCLExpression getOperationBody(org.eclipse.emf.ecore.EOperation operation)
          Determines the body expression of an operation
 java.util.Set<Variable> getParameterVariablesUsedInBody(OCLExpression body)
          Determines the self variable as used by the operation body body.
 java.util.Set<Variable> getSelfVariablesUsedInBody(OCLExpression body)
          Determines the self variables as used by the operation body or top-level non-operation-body (e.g., invariant) expression body.
 EventFilter getSynthesisedFilter()
          Obtains the event filter for the expression passed to the constructor.
 org.eclipse.emf.ecore.EPackage handleOperationCallExp(OperationCallExp<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation> opCallExp, org.eclipse.emf.ecore.EPackage sourceResult, java.util.List<org.eclipse.emf.ecore.EPackage> qualifierResults)
          Visits the specified operation call with the results of visiting its source and arguments (if any).
 org.eclipse.emf.ecore.EPackage handleOppositePropertyCallExp(OppositePropertyCallExp callExp, org.eclipse.emf.ecore.EPackage sourceResult)
           
 org.eclipse.emf.ecore.EPackage handlePropertyCallExp(PropertyCallExp<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EStructuralFeature> propCallExp, org.eclipse.emf.ecore.EPackage sourceResult, java.util.List<org.eclipse.emf.ecore.EPackage> qualifierResults)
          Visits the specified property call with the results of visiting its source and qualifiers (if any).
 org.eclipse.emf.ecore.EPackage visitOppositePropertyCallExp(OppositePropertyCallExp callExp)
          Visits the property-call source and then its qualifiers (if any).
 org.eclipse.emf.ecore.EPackage visitVariableExp(VariableExp<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EParameter> var)
          Simply returns AbstractVisitor.result.
 
Methods inherited from class org.eclipse.ocl.utilities.AbstractVisitor
getSpecification, handleAssociationClassCallExp, handleCollectionItem, handleCollectionLiteralExp, handleCollectionRange, handleConstraint, handleExpressionInOCL, handleIfExp, handleIterateExp, handleIteratorExp, handleLetExp, handleMessageExp, handleTupleLiteralExp, handleTupleLiteralPart, handleVariable, safeVisit, visitAssociationClassCallExp, visitBooleanLiteralExp, visitCollectionItem, visitCollectionLiteralExp, visitCollectionRange, visitConstraint, visitEnumLiteralExp, visitExpressionInOCL, visitIfExp, visitIntegerLiteralExp, visitInvalidLiteralExp, visitIterateExp, visitIteratorExp, visitLetExp, visitMessageExp, visitNullLiteralExp, visitOperationCallExp, visitPropertyCallExp, visitRealLiteralExp, visitStateExp, visitStringLiteralExp, visitTupleLiteralExp, visitTupleLiteralPart, visitTypeExp, visitUnlimitedNaturalLiteralExp, visitUnspecifiedValueExp, visitVariable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filters

protected final java.util.Set<EventFilter> filters
For each OCLExpression analyzed, stores the filters to merge into the resulting filter


associationEndCallExpressions

protected final java.util.Map<org.eclipse.emf.ecore.EReference,java.util.Set<NavigationCallExp>> associationEndCallExpressions
Constructor Detail

FilterSynthesisImpl

public FilterSynthesisImpl(OCLExpression expression,
                           boolean notifyNewContextElements,
                           OCL ocl)
Parameters:
expression - The OCLExpression the filter should be created for.
notifyNewContextElements - The analyzer can be parameterized during construction such that it either registers for creation events on the context type or not. Registering for element creation on the context type is useful for invariants / constraints because when a new element is created, validating the constraint may be useful. For other use cases, registering for element creation may not be so useful. For example, when a type inferencer defines its rules using OCL, it only wants to receive update events after the element has been fully initialized from those OCL expressions. In those cases, some framework may be responsible for the initial evaluation of those OCL expressions on new element, and therefore, context element creation events are not of interest.
Method Detail

handlePropertyCallExp

public org.eclipse.emf.ecore.EPackage handlePropertyCallExp(PropertyCallExp<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EStructuralFeature> propCallExp,
                                                            org.eclipse.emf.ecore.EPackage sourceResult,
                                                            java.util.List<org.eclipse.emf.ecore.EPackage> qualifierResults)
Description copied from class: AbstractVisitor
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.

Overrides:
handlePropertyCallExp in class AbstractVisitor<org.eclipse.emf.ecore.EPackage,org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EEnumLiteral,org.eclipse.emf.ecore.EParameter,org.eclipse.emf.ecore.EObject,CallOperationAction,SendSignalAction,Constraint>
Parameters:
propCallExp - 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 AbstractVisitor.result, by default
See Also:
AbstractVisitor.visitPropertyCallExp(PropertyCallExp)

handleOperationCallExp

public org.eclipse.emf.ecore.EPackage handleOperationCallExp(OperationCallExp<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation> opCallExp,
                                                             org.eclipse.emf.ecore.EPackage sourceResult,
                                                             java.util.List<org.eclipse.emf.ecore.EPackage> qualifierResults)
Description copied from class: AbstractVisitor
Visits the specified operation call with the results of visiting its source and arguments (if any).

Overrides:
handleOperationCallExp in class AbstractVisitor<org.eclipse.emf.ecore.EPackage,org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EEnumLiteral,org.eclipse.emf.ecore.EParameter,org.eclipse.emf.ecore.EObject,CallOperationAction,SendSignalAction,Constraint>
Parameters:
opCallExp - the operation call expression
sourceResult - the result of visiting the expression's source
qualifierResults - 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.visitOperationCallExp(OperationCallExp)

visitVariableExp

public org.eclipse.emf.ecore.EPackage visitVariableExp(VariableExp<org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EParameter> var)
Description copied from class: AbstractVisitor
Simply returns AbstractVisitor.result.

Specified by:
visitVariableExp in interface Visitor<org.eclipse.emf.ecore.EPackage,org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EEnumLiteral,org.eclipse.emf.ecore.EParameter,org.eclipse.emf.ecore.EObject,CallOperationAction,SendSignalAction,Constraint>
Overrides:
visitVariableExp in class AbstractVisitor<org.eclipse.emf.ecore.EPackage,org.eclipse.emf.ecore.EClassifier,org.eclipse.emf.ecore.EOperation,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EEnumLiteral,org.eclipse.emf.ecore.EParameter,org.eclipse.emf.ecore.EObject,CallOperationAction,SendSignalAction,Constraint>

getCallsOf

public java.util.Set<OperationCallExp> getCallsOf(OCLExpression operationBodyExpression)
Returns all the calls to the operation whose body is operationBodyExpression that are reachable from the root expression analyzed by this FilterSynthesisImpl. If no such calls exist, an empty set is returned.

Specified by:
getCallsOf in interface OperationBodyToCallMapper

getSynthesisedFilter

public EventFilter getSynthesisedFilter()
Obtains the event filter for the expression passed to the constructor. When an event matches the filter, the value of the expression may have changed for one or more evaluation contexts. To determine a superset of those context elements for which the value may have changed, feed the event into ImpactAnalyzer.getContextObjects(Notification).

Returns:
the filter matching all relevant events

getBodyForCall

public OCLExpression getBodyForCall(OperationCallExp call)
Looks up if the OCLExpression that is called by the given OperationCallExp has already been visited.

Parameters:
call - The OperationCallExp to look for
Returns:
the OCLExpression that defines the body of the called operation

getAttributeCallExpressions

public java.util.Set<PropertyCallExp> getAttributeCallExpressions(org.eclipse.emf.ecore.EAttribute a)
Always returns a non-null set


getAssociationEndCallExpressions

public java.util.Set<NavigationCallExp> getAssociationEndCallExpressions(org.eclipse.emf.ecore.EReference a)
Always returns a non-null set


getAllInstancesCallsFor

public java.util.Set<OperationCallExp> getAllInstancesCallsFor(org.eclipse.emf.ecore.EClassifier c)
Always returns a non-null set. Finds all occurrences of an allInstances call on a type expression for the classifier c (but not for its generalizations) in the expression analyzed by this visitor.


getSelfVariablesUsedInBody

public java.util.Set<Variable> getSelfVariablesUsedInBody(OCLExpression body)
Description copied from interface: OperationBodyToCallMapper
Determines the self variables as used by the operation body or top-level non-operation-body (e.g., invariant) expression body. While it might seem a little strange to have multiple self variables within the same operation body, that's however what may happen in Ecore OCL. It would otherwise be tricky to identify the self variable when given the body or the EOperation element. If self is not used by the body, then null will be returned. Never returns null but may return an empty set.

Specified by:
getSelfVariablesUsedInBody in interface OperationBodyToCallMapper

getParameterVariablesUsedInBody

public java.util.Set<Variable> getParameterVariablesUsedInBody(OCLExpression body)
Description copied from interface: OperationBodyToCallMapper
Determines the self variable as used by the operation body body. It would otherwise be tricky to identify the self variable when given the body or the EOperation element. If self is not used by the body, then null will be returned. Never returns null but may return an empty set.

Specified by:
getParameterVariablesUsedInBody in interface OperationBodyToCallMapper

getOperationBody

public OCLExpression getOperationBody(org.eclipse.emf.ecore.EOperation operation)
Description copied from interface: OperationBodyToCallMapper
Determines the body expression of an operation

Specified by:
getOperationBody in interface OperationBodyToCallMapper

handleOppositePropertyCallExp

public org.eclipse.emf.ecore.EPackage handleOppositePropertyCallExp(OppositePropertyCallExp callExp,
                                                                    org.eclipse.emf.ecore.EPackage sourceResult)

visitOppositePropertyCallExp

public org.eclipse.emf.ecore.EPackage visitOppositePropertyCallExp(OppositePropertyCallExp callExp)
Visits the property-call source and then its qualifiers (if any). Returns the result of AbstractVisitor.handlePropertyCallExp(PropertyCallExp, Object, List).


getDerivedProperties

public java.util.Map<OCLExpression,java.util.Set<PropertyCallExp>> getDerivedProperties()