org.eclipse.ocl
Class AbstractTypeChecker<C,O,P,PM>

java.lang.Object
  extended by org.eclipse.ocl.AbstractTypeChecker<C,O,P,PM>
All Implemented Interfaces:
TypeChecker<C,O,P>
Direct Known Subclasses:
BasicTypeChecker

public abstract class AbstractTypeChecker<C,O,P,PM>
extends java.lang.Object
implements TypeChecker<C,O,P>

Implementation of the TypeChecker interface which offers the default implementation for the type checking system. This class encapsulates the behaviour of the 1.2 release's TypeUtil class, in an extensible unit.

This class is not intended to be extended by clients. They should extend AbstractTypeResolver instead, so that TypeChecker can be successfully adapted by AbstractEnvironment. However, if an already implemented TypeResolver wants to exploit the type checking system extensibility, it may extend this class.

See Environment for generic parameters description

Since:
1.3
Author:
Adolfo Sanchez-Barbudo Herrera (adolfosbh)
See Also:
AbstractTypeResolver, TypeUtil

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.eclipse.ocl.TypeChecker
TypeChecker.Cached<C,O,P>
 
Constructor Summary
AbstractTypeChecker(Environment<?,C,O,P,?,PM,?,?,?,?,?,?> env)
          Initializes me with my environment.
 
Method Summary
 boolean checkMutuallyComparable(java.lang.Object problemObject, C type1, C type2, int opcode)
          Checks whether two types are mutually comparable in the determination of the applicability of = and <> operations.
protected  CollectionKind commonSuperType(CollectionKind kind1, CollectionKind kind2)
          Common-supertype helper method for collection kinds
 C commonSuperType(java.lang.Object problemObject, C type1, C type2)
          Get the common supertype of two types.
 boolean compatibleTypeMatch(C type1, C type2)
          Compare two types.
 boolean exactTypeMatch(C type1, C type2)
          Compare two types.
 P findAttribute(C owner, java.lang.String name)
          Finds the most specific (re)definition of an attribute in the specified classifier.
 O findOperationMatching(C owner, java.lang.String name, java.util.List<? extends TypedElement<C>> args)
          Finds an operation by signature in the specified classifier.
 C findSignalMatching(C receiver, java.util.List<C> signals, java.lang.String name, java.util.List<? extends TypedElement<C>> args)
          Find a matching signal in the specified list.
 java.util.List<P> getAttributes(C owner)
          Obtains all of the OCL attributes applicable to the specified owner type, including any that were defined in the OCL environment as additional attributes.
protected  java.util.List<O> getBestMatchingOperations(C owner, java.lang.String name, java.util.List<? extends TypedElement<C>> args)
           
protected  Environment<?,C,O,P,?,PM,?,?,?,?,?,?> getEnvironment()
          Obtains my OCL parsing environment.
protected  OCLFactory getOCLFactory()
          Obtains the OCL factory that I use to instantiate the OCL Abstract Syntax.
 java.util.List<O> getOperations(C owner)
          Obtains all of the OCL operations applicable to the specified owner type, including any that were defined in the OCL environment as additional operations.
 C getPropertyType(C owner, P property)
          Gets the type of a property, accounting for the fact that we may be navigating to it from an association class (in which the member ends of an association always have multiplicity 1) or not.
 int getRelationship(C type1, C type2)
          Queries the relationship, according to generalizations, of two types.
protected  int getRelationship(CollectionKind kind1, CollectionKind kind2)
          Get-relationship helper comparing collection kinds.
 C getResultType(java.lang.Object problemObject, C owner, O operation, java.util.List<? extends TypedElement<C>> args)
          Obtains the effective result type of the specified operation, which may or may not have parameters type by generic type variables.
protected  UMLReflection<?,C,O,P,?,PM,?,?,?,?> getUMLReflection()
          Obtains the UML introspector that I use to access the subject model.
 boolean isStandardLibraryFeature(C owner, java.lang.Object feature)
          Queries whether the specified feature (operation or attribute), as applied to a particular owner classifier, is defined by the standard library or not (in which case it would, presumably, be user-defined).
 boolean matchArgs(C owner, java.util.List<?> paramsOrProperties, java.util.List<? extends TypedElement<C>> args)
          Compares an actual argument list against the signature of an operation or a signal.
protected  int matchArgsWithExactitude(C owner, java.util.List<?> paramsOrProperties, java.util.List<? extends TypedElement<C>> args)
          Return the number of arguments with exact type matches, or -ve if there is no match.
protected abstract  C resolve(C type)
          Resolves the specified template of a demand-created type to one that is already defined in the current environment, or else a new one or even the given type (which would usually then be added to the environment).
protected abstract  CollectionType<C,O> resolveCollectionType(CollectionKind kind, C elementType)
          Resolves the specified collection type to a collection type already available in the current environment, or else a new one.
 O resolveGenericSignature(C owner, O oper)
          Resolves the signature of a generic operation (where it has parameters of type and/or T or T2) against the source type of the operation, as appropriate.
protected  C resolveGenericType(C owner, C paramType, C argType)
          Resolves the generic type of an operation parameter (where it is T or T2) against the source type of the operation or the type of the actual argument, as appropriate.
protected abstract  TupleType<O,P> resolveTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
          Resolves the specified signature of tuple parts to a tuple type already available in the current environment, or else a new one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTypeChecker

public AbstractTypeChecker(Environment<?,C,O,P,?,PM,?,?,?,?,?,?> env)
Initializes me with my environment.

Parameters:
env - my environment
Method Detail

getEnvironment

protected Environment<?,C,O,P,?,PM,?,?,?,?,?,?> getEnvironment()
Obtains my OCL parsing environment.

Returns:
my environment

getUMLReflection

protected UMLReflection<?,C,O,P,?,PM,?,?,?,?> getUMLReflection()
Obtains the UML introspector that I use to access the subject model.

Returns:
my UML introspector

getOCLFactory

protected OCLFactory getOCLFactory()
Obtains the OCL factory that I use to instantiate the OCL Abstract Syntax.

Returns:
my OCL factory

getRelationship

public int getRelationship(C type1,
                           C type2)
Description copied from interface: TypeChecker
Queries the relationship, according to generalizations, of two types. This operation accounts for the OCL Standard Library types, which the otherwise similar UMLReflection.getRelationship(Object, Object) method does not.

Specified by:
getRelationship in interface TypeChecker<C,O,P>
Parameters:
type1 - a type
type2 - another type
Returns:
the nature of their hierarchical relationship of type1 to type2, as enumerated in the UMLReflection interface
See Also:
UMLReflection.getRelationship(Object, Object)

getRelationship

protected int getRelationship(CollectionKind kind1,
                              CollectionKind kind2)
Get-relationship helper comparing collection kinds.


getResultType

public C getResultType(java.lang.Object problemObject,
                       C owner,
                       O operation,
                       java.util.List<? extends TypedElement<C>> args)
Description copied from interface: TypeChecker
Obtains the effective result type of the specified operation, which may or may not have parameters type by generic type variables. Many of the OCL Standard Library operations are either generic themselves or defined by generic types, so the return results depend on the argument and source types.

Specified by:
getResultType in interface TypeChecker<C,O,P>
Parameters:
problemObject - the context object on which to report any problem that we may find in computing the result type. Usually this is some abstract or concrete syntax tree node
owner - the owner of the operation (type on which the operation is called)
operation - the operation signature
args - the arguments of the operation call, which are expressions or variables
Returns:
the effective result type of the corresponding operation, or null after reporting a problem if any of the argument types do not correspond to the source type and/or expected parameter types of the operation

getPropertyType

public C getPropertyType(C owner,
                         P property)
Description copied from interface: TypeChecker
Gets the type of a property, accounting for the fact that we may be navigating to it from an association class (in which the member ends of an association always have multiplicity 1) or not.

Specified by:
getPropertyType in interface TypeChecker<C,O,P>
Parameters:
owner - the source of the navigation of the property, which may be an association class (the interesting scenario)
property - the property to navigate
Returns:
the effective type of the property, which may not be a collection type despite its declared multiplicity in the association class case

commonSuperType

public C commonSuperType(java.lang.Object problemObject,
                         C type1,
                         C type2)
Get the common supertype of two types. This operation accounts for the OCL Standard Library types, which the otherwise similar UMLReflection.getCommonSuperType(Object, Object) method does not.

Specified by:
commonSuperType in interface TypeChecker<C,O,P>
Parameters:
type1 - a type
type2 - another type
problemObject - the object which could have problems.
Returns:
their common supertype, if any, null if the two types have no common supertype
See Also:
UMLReflection.getCommonSuperType(Object, Object)

commonSuperType

protected CollectionKind commonSuperType(CollectionKind kind1,
                                         CollectionKind kind2)
Common-supertype helper method for collection kinds


checkMutuallyComparable

public boolean checkMutuallyComparable(java.lang.Object problemObject,
                                       C type1,
                                       C type2,
                                       int opcode)
Description copied from interface: TypeChecker
Checks whether two types are mutually comparable in the determination of the applicability of = and <> operations.

Specified by:
checkMutuallyComparable in interface TypeChecker<C,O,P>
Parameters:
problemObject - the object which could have problems.
type1 - a type
type2 - another type
opcode - the operation code
Returns:
false if the types are not comparable

exactTypeMatch

public boolean exactTypeMatch(C type1,
                              C type2)
Description copied from interface: TypeChecker
Compare two types. Returns true if types are exactly equal, false otherwise.

Specified by:
exactTypeMatch in interface TypeChecker<C,O,P>
Parameters:
type1 - a type
type2 - another type
Returns:
true if the same type

compatibleTypeMatch

public boolean compatibleTypeMatch(C type1,
                                   C type2)
Description copied from interface: TypeChecker
Compare two types. Returns true if types are compatible, false otherwise.

Specified by:
compatibleTypeMatch in interface TypeChecker<C,O,P>
Parameters:
type1 - a type
type2 - another type
Returns:
true if the same type or type1 is a strict subtype of type2.

getOperations

public java.util.List<O> getOperations(C owner)
Description copied from interface: TypeChecker
Obtains all of the OCL operations applicable to the specified owner type, including any that were defined in the OCL environment as additional operations.

Specified by:
getOperations in interface TypeChecker<C,O,P>
Parameters:
owner - the operation owner type
Returns:
an unmodifiable list of its operations

findAttribute

public P findAttribute(C owner,
                       java.lang.String name)
Finds the most specific (re)definition of an attribute in the specified classifier.

Specified by:
findAttribute in interface TypeChecker<C,O,P>
Parameters:
owner - the classifier to search
name - the name of the operation
Returns:
the matching operation, or null if not found

getAttributes

public java.util.List<P> getAttributes(C owner)
Description copied from interface: TypeChecker
Obtains all of the OCL attributes applicable to the specified owner type, including any that were defined in the OCL environment as additional attributes.

Specified by:
getAttributes in interface TypeChecker<C,O,P>
Parameters:
owner - the attribute owner type
Returns:
an unmodifiable list of its attributes

resolveGenericSignature

public O resolveGenericSignature(C owner,
                                 O oper)
Description copied from interface: TypeChecker
Resolves the signature of a generic operation (where it has parameters of type and/or T or T2) against the source type of the operation, as appropriate.

Specified by:
resolveGenericSignature in interface TypeChecker<C,O,P>
Parameters:
owner - the operation source type
oper - the generic operation
Returns:
the resolved parameter type

resolveGenericType

protected C resolveGenericType(C owner,
                               C paramType,
                               C argType)
Resolves the generic type of an operation parameter (where it is T or T2) against the source type of the operation or the type of the actual argument, as appropriate.

Parameters:
env - the OCL environment
owner - the operation source type
paramType - the operation parameter type
argType - the actual operation argument type
Returns:
the resolved parameter type

matchArgs

public boolean matchArgs(C owner,
                         java.util.List<?> paramsOrProperties,
                         java.util.List<? extends TypedElement<C>> args)
Description copied from interface: TypeChecker
Compares an actual argument list against the signature of an operation or a signal.

Specified by:
matchArgs in interface TypeChecker<C,O,P>
Parameters:
owner - the type that owns the operation
paramsOrProperties - the operation parameters or signal attributes to match against the arguments
args - a list of OCLExpressions or Variables
Returns:
true or false

matchArgsWithExactitude

protected int matchArgsWithExactitude(C owner,
                                      java.util.List<?> paramsOrProperties,
                                      java.util.List<? extends TypedElement<C>> args)
Return the number of arguments with exact type matches, or -ve if there is no match.

Since:
3.2

findSignalMatching

public C findSignalMatching(C receiver,
                            java.util.List<C> signals,
                            java.lang.String name,
                            java.util.List<? extends TypedElement<C>> args)
Description copied from interface: TypeChecker
Find a matching signal in the specified list.

Specified by:
findSignalMatching in interface TypeChecker<C,O,P>
Parameters:
receiver - the type that receives the signal
signals - the signals to search
name - name of signal to find
args - list of arguments to match against the signal signature
Returns:
the matching signal, or null if not found

findOperationMatching

public O findOperationMatching(C owner,
                               java.lang.String name,
                               java.util.List<? extends TypedElement<C>> args)
Description copied from interface: TypeChecker
Finds an operation by signature in the specified classifier.

Specified by:
findOperationMatching in interface TypeChecker<C,O,P>
Parameters:
owner - the classifier to search
name - the name of the operation
args - a list of arguments to match against the operation signature, as either expressions or variables
Returns:
the matching operation, or null if not found

getBestMatchingOperations

protected java.util.List<O> getBestMatchingOperations(C owner,
                                                      java.lang.String name,
                                                      java.util.List<? extends TypedElement<C>> args)
Since:
3.2

isStandardLibraryFeature

public boolean isStandardLibraryFeature(C owner,
                                        java.lang.Object feature)
Description copied from interface: TypeChecker
Queries whether the specified feature (operation or attribute), as applied to a particular owner classifier, is defined by the standard library or not (in which case it would, presumably, be user-defined).

Specified by:
isStandardLibraryFeature in interface TypeChecker<C,O,P>
Parameters:
owner - a classifier on which a feature is to be accessed
feature - the feature to be accessed
Returns:
whether the feature is defined by the standard library

resolveTupleType

protected abstract TupleType<O,P> resolveTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
Resolves the specified signature of tuple parts to a tuple type already available in the current environment, or else a new one.

Parameters:
parts - specification of the tuple type signature
Returns:
the resolved or new tuple type

resolveCollectionType

protected abstract CollectionType<C,O> resolveCollectionType(CollectionKind kind,
                                                             C elementType)
Resolves the specified collection type to a collection type already available in the current environment, or else a new one.

Parameters:
kind - the kind of collection type to obtain
elementType - the element type of the requisite collection type
Returns:
the resolved or new collection type

resolve

protected abstract C resolve(C type)
Resolves the specified template of a demand-created type to one that is already defined in the current environment, or else a new one or even the given type (which would usually then be added to the environment).

Parameters:
type - the template/prototype/example of a type to resolve in the current environment
Returns:
the resolved type