org.eclipse.ocl.util
Class TypeUtil

java.lang.Object
  extended by org.eclipse.ocl.util.TypeUtil

public class TypeUtil
extends Object

Static utilities for introspecting OCL types.

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


Method Summary
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
void
checkMutuallyComparable(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C type1, C type2, int opcode)
          Checks whether two types are mutually comparable in the determination of the applicability = and <> operations.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
commonSuperType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C type1, C type2)
          Get the common supertype of two types.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
O
findOperationMatching(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C owner, String name, List<? extends TypedElement<C>> args)
          Finds an operation by signature in the specified classifier.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
findSignalMatching(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C receiver, List<C> signals, String name, List<? extends TypedElement<C>> args)
          Find a matching signal in the specified list.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
List<P>
getAttributes(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, 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.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
List<O>
getOperations(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, 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.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
getPropertyType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, 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.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
int
getRelationship(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C type1, C type2)
          Queries the relationship, according to generalizations, of two types.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
getResultType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C owner, O oper)
          Obtains the result type of the specified operation, which in the case of collection operations sometimes depends on the element type of the source collection.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
boolean
isOclAnyOperation(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, O operation)
          Queries whether an operation is defined by the OclAny type.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
resolveBagType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C elementType)
          Resolves a Bag type against the baf types previously generated and persisted in the environment.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
resolveCollectionType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, CollectionKind kind, C elementType)
          Resolves a collection type against the collection types previously generated and persisted in the environment.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
O
resolveGenericSignature(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, 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.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
resolveOperationMessageType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, O operation)
          Resolves an operation message type against the message types previously generated and persisted in the environment.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
resolveOrderedSetType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C elementType)
          Resolves a OrderedSet type against the types previously generated and persisted in the environment.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
resolveSequenceType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C elementType)
          Resolves a Sequence type against the sequence types previously generated and persisted in the environment.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
resolveSetType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C elementType)
          Resolves a Set type against the set types previously generated and persisted in the environment.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
resolveSignalMessageType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C signal)
          Resolves a signal message type against the message types previously generated and persisted in the environment.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
resolveTupleType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, EList<? extends TypedElement<C>> parts)
          Resolves a tuple type against the tuple types previously generated and persisted in the environment.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
resolveType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C type)
          Resolves the specified type against the model-based types defined by the specified environment's type resolver, for consistency with the environment (especially for persistence).
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
C
resolveTypeType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C type)
          Resolves a tupe-type against the tupe-types previously generated and persisted in the environment.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
boolean
type1AsType2(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C type1, C type2)
          Casts a value of one type as another type, if compatible.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
int
typeCompare(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, C type1, C type2)
          Compare two types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isOclAnyOperation

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> boolean isOclAnyOperation(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                            O operation)
Queries whether an operation is defined by the OclAny type.

Parameters:
env - the OCL environment
operation - an operation
Returns:
true if it is defined by OclAny; false, otherwise

findOperationMatching

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> O findOperationMatching(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                          C owner,
                                                                          String name,
                                                                          List<? extends TypedElement<C>> args)
Finds an operation by signature in the specified classifier.

Parameters:
env - the OCL environment
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

findSignalMatching

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C findSignalMatching(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                       C receiver,
                                                                       List<C> signals,
                                                                       String name,
                                                                       List<? extends TypedElement<C>> args)
Find a matching signal in the specified list.

Parameters:
env - the OCL environment
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

getOperations

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> List<O> getOperations(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                        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.

Parameters:
env - the OCL environment
owner - the operation owner type
Returns:
an unmodifiable list of its operations

getAttributes

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> List<P> getAttributes(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                        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.

Parameters:
env - the OCL environment
owner - the attribute owner type
Returns:
an unmodifiable list of its attributes

resolveGenericSignature

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> O resolveGenericSignature(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                            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.

Parameters:
env - the OCL environment
owner - the operation source type
oper - the generic operation
Returns:
the resolved parameter type

getPropertyType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C getPropertyType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                    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.

Parameters:
env - the OCL environment
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

getResultType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C getResultType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                  C owner,
                                                                  O oper)
Obtains the result type of the specified operation, which in the case of collection operations sometimes depends on the element type of the source collection.

Parameters:
env - the OCL environment
owner - the type of the operation call source
oper - the operation
Returns:
the operation's effect result type

type1AsType2

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> boolean type1AsType2(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                       C type1,
                                                                       C type2)
                            throws SemanticException
Casts a value of one type as another type, if compatible.

Parameters:
env - the OCL environment
type1 - a type
type2 - another type
Returns:
true if the cast is successful
Throws:
SemanticException - if the cast fails (because the types are not conformant)

typeCompare

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> int typeCompare(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                  C type1,
                                                                  C type2)
Compare two types. Returns 0 if types are exactly equal, -1 if type1 conforms to type2 (type1 is a subtype of type2) 1 if type2 conforms to type1 (type2 is a subtype of type1). Fails if there is no type conformance.

Parameters:
type1 - a type
type2 - another type
Returns:
the ordering key
Throws:
IllegalArgumentException - if the types are not conformant one way or the other

checkMutuallyComparable

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> void checkMutuallyComparable(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                               C type1,
                                                                               C type2,
                                                                               int opcode)
                                    throws SemanticException
Checks whether two types are mutually comparable in the determination of the applicability = and <> operations.

Parameters:
env - the OCL environment
type1 - a type
type2 - another type
opcode - the operation code
Throws:
SemanticException - if the types are not comparable

getRelationship

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> int getRelationship(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                      C type1,
                                                                      C type2)
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.

Parameters:
env - the OCL environment
type1 - a type
type2 - another type
Returns:
the nature of their hierarchical relationship, as enumerated in the UMLReflection interface
See Also:
UMLReflection.getRelationship(Object, Object)

commonSuperType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C commonSuperType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                    C type1,
                                                                    C type2)
                         throws SemanticException
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.

Parameters:
type1 - a type
type2 - another type
Returns:
their common supertype, if any
Throws:
SemanticException - if the two types have no common supertype
See Also:
UMLReflection.getCommonSuperType(Object, Object)

resolveType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C resolveType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                C type)
Resolves the specified type against the model-based types defined by the specified environment's type resolver, for consistency with the environment (especially for persistence).

Parameters:
env - the OCL environment
type - the type to resolve
Returns:
the environment's corresponding type

resolveSetType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C resolveSetType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                   C elementType)
Resolves a Set type against the set types previously generated and persisted in the environment.

Parameters:
env - the OCL environment
elementType - the element type of the set type to resolve
Returns:
the environment's corresponding type

resolveOrderedSetType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C resolveOrderedSetType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                          C elementType)
Resolves a OrderedSet type against the types previously generated and persisted in the environment.

Parameters:
env - the OCL environment
elementType - the element type of the ordered set type to resolve
Returns:
the environment's corresponding type

resolveBagType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C resolveBagType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                   C elementType)
Resolves a Bag type against the baf types previously generated and persisted in the environment.

Parameters:
env - the OCL environment
elementType - the element type of the baf type to resolve
Returns:
the environment's corresponding type

resolveSequenceType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C resolveSequenceType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                        C elementType)
Resolves a Sequence type against the sequence types previously generated and persisted in the environment.

Parameters:
env - the OCL environment
elementType - the element type of the sequence type to resolve
Returns:
the environment's corresponding type

resolveCollectionType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C resolveCollectionType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                          CollectionKind kind,
                                                                          C elementType)
Resolves a collection type against the collection types previously generated and persisted in the environment.

Parameters:
env - the OCL environment
kind - the collection kind to resolve
elementType - the element type of the collection type to resolve
Returns:
the environment's corresponding type

resolveTupleType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C resolveTupleType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                     EList<? extends TypedElement<C>> parts)
Resolves a tuple type against the tuple types previously generated and persisted in the environment.

Parameters:
env - the OCL environment
parts - the expressions or variables describing the parts of the tuple type to resolve
Returns:
the environment's corresponding type

resolveTypeType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C resolveTypeType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                    C type)
Resolves a tupe-type against the tupe-types previously generated and persisted in the environment.

Parameters:
env - the OCL environment
type - the referred type of the type-type to resolve
Returns:
the environment's corresponding type

resolveOperationMessageType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C resolveOperationMessageType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                                O operation)
Resolves an operation message type against the message types previously generated and persisted in the environment.

Parameters:
env - the OCL environment
operation - the operation referenced by the message type to resolve
Returns:
the environment's corresponding type

resolveSignalMessageType

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> C resolveSignalMessageType(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                             C signal)
Resolves a signal message type against the message types previously generated and persisted in the environment.

Parameters:
env - the OCL environment
signal - the signal referenced by the message type to resolve
Returns:
the environment's corresponding type

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