org.eclipse.ocl.examples.impactanalyzer.instanceScope
Class AbstractTracer<T extends org.eclipse.emf.ecore.EObject>

java.lang.Object
  extended by org.eclipse.ocl.examples.impactanalyzer.instanceScope.AbstractTracer<T>
All Implemented Interfaces:
Tracer
Direct Known Subclasses:
BooleanLiteralExpTracer, CollectionLiteralExpTracer, EnumLiteralExpTracer, IfExpTracer, IntegerLiteralExpTracer, InvalidlLiteralExpTracer, IterateExpTracer, IteratorExpTracer, LetExpTracer, NullLiteralExpTracer, OperationCallExpTracer, OppositePropertyCallExpTracer, PropertyCallExpTracer, RealLiteralExpTracer, StringLiteralExpTracer, TupleLiteralExpTracer, TypeExpTracer, VariableExpTracer

public abstract class AbstractTracer<T extends org.eclipse.emf.ecore.EObject>
extends java.lang.Object
implements Tracer


Field Summary
protected  OCLFactory oclFactory
           
 
Constructor Summary
protected AbstractTracer(T expression, AbstractTracer<?> caller, java.lang.String additionalTuplePartNameToLookFor, OCLFactory oclFactory)
          Creates a tracer for OCL expression expression and adding another tuple part name to the list of tuple parts to look for as already defined for the caller tracer.
protected AbstractTracer(T expression, OCLFactory oclFactory)
          Creates a tracer with a null tuplePartNames array, meaninig that this tracer is not looking for TupleLiteralPart expressions on which to unroll a part access.
protected AbstractTracer(T expression, java.util.Stack<java.lang.String> tuplePartNames, OCLFactory oclFactory)
          Specifies an explicit list of tuple part names to look for.
 
Method Summary
protected  void applyScopesOnNavigationStep(NavigationStep step, OperationBodyToCallMapper operationBodyToCallMapper)
           
protected  java.util.Set<Variable> calculateEnteringScope(OperationBodyToCallMapper operationBodyToCallMapper)
          Calculates the scopes the NavigationStep this Tracer creates will enter when navigated.
protected  java.util.Set<Variable> calculateLeavingScopes(OperationBodyToCallMapper operationBodyToCallMapper)
          Calculates which scopes the NavigationStep this Tracer creates will leave when navigated.
protected  OCLExpression commonCompositionParent(OCLExpression second)
          This method is a shortcut for commonCompositionParent(OCLExpression, OCLExpression) that uses getExpression() as the origin.
protected static OCLExpression commonCompositionParent(OCLExpression first, OCLExpression second)
          This method finds the common composition parent of the two given OCLExpressions.
static boolean doesTypeMatch(org.eclipse.emf.ecore.EClass sourceType, AnnotatedEObject fromObject)
           
protected  boolean doesTypeMatch(org.eclipse.emf.ecore.EObject s)
          Checks if s conforms to the type of the expression managed by this tracer.
protected static java.util.Set<Variable> getAllVariablesInScope(OCLExpression e, OperationBodyToCallMapper operationBodyToCallMapper)
           
protected  T getExpression()
           
 java.util.Stack<java.lang.String> getExtendedListOfTuplePartNames(java.lang.String toAdd)
           
protected  org.eclipse.emf.ecore.EClass getInnermostElementType(org.eclipse.emf.ecore.EClassifier type)
          We assume a collection, possibly nested, that eventually has elements of a class-like type inside.
protected  java.util.Stack<java.lang.String> getListOfTuplePartNamesWithFoundRemoved()
          Returns tuplePartNames with the first element at index 0 removed.
protected  OCLExpression getRootExpression()
          There are a few known idiosyncrasies in the OCL "composition" hierarchy.
 java.util.Stack<java.lang.String> getTupleLiteralPartNamesToLookFor()
           
protected  java.lang.String getTuplePartNameLookedFor()
           
protected  java.util.Set<Variable> getVariablesIntroducedBetweenHereAnd(OCLExpression parent, OperationBodyToCallMapper operationBodyToCallMapper)
          This method is a shortcut for variablesIntroducedBetween(OCLExpression, OCLExpression, OperationBodyToCallMapper) that uses getExpression() as the origin.
protected static java.util.Set<Variable> getVariablesScopedByExpression(OCLExpression e, OperationBodyToCallMapper operationBodyToCallMapper)
           
protected  boolean isLookingForTuplePart()
           
 NavigationStep traceback(org.eclipse.emf.ecore.EClass context, PathCache pathCache, OperationBodyToCallMapper operationBodyToCallMapper)
          By default, many expression types which, e.g., result in a primitive result, return an EmptyResultNavigationStep which is what this default implementation does.
protected  java.util.Set<Variable> variablesIntroducedBetween(OCLExpression origin, OCLExpression parent, OperationBodyToCallMapper operationBodyToCallMapper)
          This method returns all variables introduced by parent or any contained expression along the containment hierarchy, down to origin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

oclFactory

protected final OCLFactory oclFactory
Constructor Detail

AbstractTracer

protected AbstractTracer(T expression,
                         OCLFactory oclFactory)
Creates a tracer with a null tuplePartNames array, meaninig that this tracer is not looking for TupleLiteralPart expressions on which to unroll a part access.

Parameters:
expression - the OCL expression for which this tracer shall determine a navigation step

AbstractTracer

protected AbstractTracer(T expression,
                         java.util.Stack<java.lang.String> tuplePartNames,
                         OCLFactory oclFactory)
Specifies an explicit list of tuple part names to look for. Useful in combination with getListOfTuplePartNamesWithFoundRemoved().


AbstractTracer

protected AbstractTracer(T expression,
                         AbstractTracer<?> caller,
                         java.lang.String additionalTuplePartNameToLookFor,
                         OCLFactory oclFactory)
Creates a tracer for OCL expression expression and adding another tuple part name to the list of tuple parts to look for as already defined for the caller tracer. See also getExtendedListOfTuplePartNames(String).

Parameters:
additionalTuplePartNameToLookFor - if along the chain of sub-expressions traversed there was an attribute access on a source expression of a tuple type that needs to be unwound when at some point a TupleLiteralPart is found. Must not be null.
Method Detail

getExpression

protected T getExpression()

isLookingForTuplePart

protected boolean isLookingForTuplePart()

getTuplePartNameLookedFor

protected java.lang.String getTuplePartNameLookedFor()

getExtendedListOfTuplePartNames

public java.util.Stack<java.lang.String> getExtendedListOfTuplePartNames(java.lang.String toAdd)

getListOfTuplePartNamesWithFoundRemoved

protected java.util.Stack<java.lang.String> getListOfTuplePartNamesWithFoundRemoved()
Returns tuplePartNames with the first element at index 0 removed. If tuplePartNames is null or contains one or no element, null is returned.


getTupleLiteralPartNamesToLookFor

public java.util.Stack<java.lang.String> getTupleLiteralPartNamesToLookFor()

getRootExpression

protected OCLExpression getRootExpression()
There are a few known idiosyncrasies in the OCL "composition" hierarchy. A TupleLiteralExp does not contain its tuple parts which are variable declarations, a CollectionLiteralExp does not contain its parts, and of those parts, none of CollectionRange nor CollectionItem contains the expressions that it uses to describe itself.

We still need to be able to determine the scope of, e.g., self or operation parameters and therefore need to ascend what may be called the "logical composition hierarchy" of an OCL expression. Therefore, this operation ascends the real composition hierarchy until it finds a null parent or a parent of type constraint or EAnnotation. In this case, it tries the aforementioned "logical compositions" one after the other. If for one such association another element is found, ascending continues there.


doesTypeMatch

protected boolean doesTypeMatch(org.eclipse.emf.ecore.EObject s)
Checks if s conforms to the type of the expression managed by this tracer. A mismatch may occur because of "reverse polymorphic traversal." In other words, if an expression with a source traces back to its source in order to find out the possible values for self that may have produced a specific value, the actual source object may be of a more general type than the static type of the source expression of the specific expression analyzed. This can happen because there may be multiple occurrences of attribute or association end call expressions for the same attribute/association that occur in different expressions, where navigation back to self is not always possible because of the actual type constraints.

All implementations of Tracer.traceback(EClass, PathCache, OperationBodyToCallMapper) must call this operation to ensure they don't try to continue on a trace that type-wise is impossible.


doesTypeMatch

public static boolean doesTypeMatch(org.eclipse.emf.ecore.EClass sourceType,
                                    AnnotatedEObject fromObject)

traceback

public NavigationStep traceback(org.eclipse.emf.ecore.EClass context,
                                PathCache pathCache,
                                OperationBodyToCallMapper operationBodyToCallMapper)
By default, many expression types which, e.g., result in a primitive result, return an EmptyResultNavigationStep which is what this default implementation does.

Specified by:
traceback in interface Tracer
Parameters:
context - the context type that defines the type of any self occurrence outside of operation bodies
pathCache - a global cache that remembers the navigation steps already computed for some OCL expressions
operationBodyToCallMapper - the filter synthesizer that analyzed an overall expression that contains the expression to be handled by this tracer

getInnermostElementType

protected org.eclipse.emf.ecore.EClass getInnermostElementType(org.eclipse.emf.ecore.EClassifier type)
We assume a collection, possibly nested, that eventually has elements of a class-like type inside.


calculateLeavingScopes

protected java.util.Set<Variable> calculateLeavingScopes(OperationBodyToCallMapper operationBodyToCallMapper)
Calculates which scopes the NavigationStep this Tracer creates will leave when navigated.

Returns:
the set of OCLExpressions representing the scopes the created NavigationStep will leave when navigated.

calculateEnteringScope

protected java.util.Set<Variable> calculateEnteringScope(OperationBodyToCallMapper operationBodyToCallMapper)
Calculates the scopes the NavigationStep this Tracer creates will enter when navigated.

Returns:
the OCLExpressions representing the scope the created NavigationStep will enter when navigated. Always non-null, but possibly empty

applyScopesOnNavigationStep

protected void applyScopesOnNavigationStep(NavigationStep step,
                                           OperationBodyToCallMapper operationBodyToCallMapper)

variablesIntroducedBetween

protected java.util.Set<Variable> variablesIntroducedBetween(OCLExpression origin,
                                                             OCLExpression parent,
                                                             OperationBodyToCallMapper operationBodyToCallMapper)
This method returns all variables introduced by parent or any contained expression along the containment hierarchy, down to origin.

Parameters:
origin - The OCLExpression used as the origin of the search.
parent - The OCLExpression that is a immediate or transitive containment parent of the origin (see EObject.eContainer())
Returns:
A Set of OCLExpressions containing all scope creating expressions in the containment hierarchy between origin and parent.

getVariablesScopedByExpression

protected static java.util.Set<Variable> getVariablesScopedByExpression(OCLExpression e,
                                                                        OperationBodyToCallMapper operationBodyToCallMapper)

getAllVariablesInScope

protected static java.util.Set<Variable> getAllVariablesInScope(OCLExpression e,
                                                                OperationBodyToCallMapper operationBodyToCallMapper)

getVariablesIntroducedBetweenHereAnd

protected java.util.Set<Variable> getVariablesIntroducedBetweenHereAnd(OCLExpression parent,
                                                                       OperationBodyToCallMapper operationBodyToCallMapper)
This method is a shortcut for variablesIntroducedBetween(OCLExpression, OCLExpression, OperationBodyToCallMapper) that uses getExpression() as the origin. See variablesIntroducedBetween(OCLExpression, OCLExpression, OperationBodyToCallMapper) for description.

Parameters:
parent -
Returns:
a non-null set, possibly empty

commonCompositionParent

protected static OCLExpression commonCompositionParent(OCLExpression first,
                                                       OCLExpression second)
This method finds the common composition parent of the two given OCLExpressions. If the two expressions don't have a common container, null is returned.

Parameters:
first - The first OCLExpression.
second - The second OCLExpression.
Returns:
The common composition parent or null, in case there is none.

commonCompositionParent

protected OCLExpression commonCompositionParent(OCLExpression second)
This method is a shortcut for commonCompositionParent(OCLExpression, OCLExpression) that uses getExpression() as the origin. See commonCompositionParent(OCLExpression, OCLExpression) for description.

Parameters:
second -
Returns: