public abstract class AbstractTypeResolver<PK,C,O,P,PM> extends java.lang.Object implements TypeResolver<C,O,P>
TypeResolver
interface, useful for
providers of environment implementations to build their type resolvers.
It is recommended that clients extend this class to customize resolution of types based on their models, rather than implementing the interface. Simply override a few protected methods for creating metamodel-specific constructs.
See the Environment
class for a description of the
generic type parameters of this class.
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
ADDITIONS_PACKAGE |
protected static java.lang.String |
COLLECTIONS_PACKAGE |
protected static java.lang.String |
MESSAGES_PACKAGE |
protected static java.lang.String |
TUPLES_PACKAGE |
protected static java.lang.String |
TYPES_PACKAGE |
Constructor and Description |
---|
AbstractTypeResolver(Environment<PK,C,O,P,?,PM,?,?,?,?,?,?> env)
Initializes me with an environment.
|
AbstractTypeResolver(Environment<PK,C,O,P,?,PM,?,?,?,?,?,?> env,
org.eclipse.emf.ecore.resource.Resource resource)
Initializes me with a resource in which I will persist the model-based
types that I generate in my associated
Environment . |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
addClassifier(PK pkg,
C classifier)
Adds a classifier to the specified package, which is one that I use to
store OCL-generated types.
|
protected abstract void |
addOperation(C owner,
O operation)
Adds the specified operation to a classifier.
|
protected abstract void |
addProperty(C owner,
P property)
Adds the specified property to a classifier.
|
protected PK |
createAdditionalFeaturesPackage()
Creates the package containing the additional operations and properties
parsed in my environment.
|
protected PK |
createCollectionPackage()
Creates the package containing the collection types that I generate.
|
protected CollectionType<C,O> |
createCollectionType(CollectionKind kind,
C elementType)
Creates a new collection type of the specified
kind and element
type, assuming that it does not already exist. |
protected PK |
createMessagePackage()
Creates the package containing the message types that I generate.
|
protected MessageType<C,O,P> |
createOperationMessageType(O operation)
Creates a new message type for the specified
element ,
assuming that it does not already exist. |
protected abstract PK |
createPackage(java.lang.String name)
Creates a package with the specified name.
|
protected org.eclipse.emf.ecore.resource.Resource |
createResource()
Creates the resource that persists my generated types.
|
protected abstract C |
createShadowClass(C type)
Creates the shadow class to contain additional features defined for the
specified OCL
type . |
protected MessageType<C,O,P> |
createSignalMessageType(C signal)
Creates a new message type for the specified
element ,
assuming that it does not already exist. |
protected PK |
createTuplePackage()
Creates the package containing the tuple types that I generate.
|
protected TupleType<O,P> |
createTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
Creates a new tuple type from the specified
parts , assuming that
it does not already exist. |
protected PK |
createTypePackage()
Creates the package containing the type types that I generate.
|
protected TypeType<C,O> |
createTypeType(C type)
Creates a new type type for the specified
type ,
assuming that it does not already exist. |
void |
dispose()
Disposes me by unloading my resource, if and only if I created it in
the first place.
|
protected PK |
findAdditionalFeaturesPackage()
Finds the package storing additional features, if our resource already
contains it.
|
protected PK |
findCollectionPackage()
Finds the package storing collection types, if our resource already
contains it.
|
protected CollectionType<C,O> |
findCollectionType(CollectionKind kind,
C elementType)
Finds an existing collection type matching the specified
kind and
element type, if any has already been created. |
protected O |
findMatchingOperation(C shadow,
O operation)
Finds an operation already existing in the specified
shadow
class that matches the specified operation signature. |
protected P |
findMatchingProperty(C shadow,
P property)
Finds a property already existing in the specified
shadow
class that matches the specified property signature. |
protected PK |
findMessagePackage()
Finds the package storing message types, if our resource already
contains it.
|
protected MessageType<C,O,P> |
findMessageType(java.lang.Object element)
Finds an existing message type matching the specified
element ,
if any has already been created. |
protected abstract PK |
findPackage(java.lang.String name)
Finds the existing package with the specified name in my resource.
|
protected C |
findShadowClass(C type)
Finds the shadow class to contain additional features defined for the
specified OCL
type , if it already exists. |
protected PK |
findTuplePackage()
Finds the package storing tuple types, if our resource already
contains it.
|
protected TupleType<O,P> |
findTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
Finds an existing tuple type matching the specified
parts , if any
has already been created. |
protected PK |
findTypePackage()
Finds the package storing type types, if our resource already
contains it.
|
protected TypeType<C,O> |
findTypeType(C type)
Finds an existing type type matching the specified
type ,
if any has already been created. |
java.util.List<P> |
getAdditionalAttributes(C owner)
Obtains the additional attributes defined (via OCL) in the specified
classifier context.
|
PK |
getAdditionalFeaturesPackage()
Obtains the package containing the additional operations and properties
parsed in my environment.
|
java.util.List<O> |
getAdditionalOperations(C owner)
Obtains the additional operations defined (via OCL) in the specified
classifier context.
|
PK |
getCollectionPackage()
Obtains the package containing the collection types that I generate.
|
protected Environment<PK,C,O,P,?,PM,?,?,?,?,?,?> |
getEnvironment()
Obtains the environment that I persist.
|
PK |
getMessagePackage()
Obtains the package containing the message types that I generate.
|
org.eclipse.emf.ecore.resource.Resource |
getResource()
Obtains the resource in which the types that I generate are stored for
persistence.
|
protected C |
getShadowClass(C type)
Obtains the shadow class for the specified model classifier, creating
it if necessary.
|
protected abstract C |
getShadowedClassifier(C shadow)
Obtains the classifier for which the specified shadow stores additional
features.
|
PK |
getTuplePackage()
Obtains the package containing the tuple types that I generate.
|
PK |
getTypePackage()
Obtains the package containing the type types that I generate.
|
protected boolean |
hasAdditionalFeatures()
Queries whether the current environment has any additional features
defined at all.
|
C |
resolve(C type)
Resolves the specified
type , returning my own persistent
type instance representing the same OCL type. |
P |
resolveAdditionalAttribute(C owner,
P property)
Resolves the specified "additional attribute" defined by the OCL client
on the specified
owner type. |
O |
resolveAdditionalOperation(C owner,
O operation)
Resolves the specified "additional operation" defined by the OCL client
on the specified
owner type. |
CollectionType<C,O> |
resolveCollectionType(CollectionKind kind,
C elementType)
Resolves the collection type of the specified
kind and
element type, either created anew or previously created. |
MessageType<C,O,P> |
resolveOperationMessageType(O operation)
Resolves the type for a message expression referencing the specified
operation . |
MessageType<C,O,P> |
resolveSignalMessageType(C signal)
Resolves the type for a message expression referencing the specified
signal . |
TupleType<O,P> |
resolveTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
Resolves the tuple type consisting of the specified
parts ,
in no particular order, either created anew or previously created. |
TypeType<C,O> |
resolveTypeType(C type)
Resolves the type for a type expression referencing the specified
type . |
protected static final java.lang.String COLLECTIONS_PACKAGE
protected static final java.lang.String MESSAGES_PACKAGE
protected static final java.lang.String TUPLES_PACKAGE
protected static final java.lang.String TYPES_PACKAGE
protected static final java.lang.String ADDITIONS_PACKAGE
public AbstractTypeResolver(Environment<PK,C,O,P,?,PM,?,?,?,?,?,?> env)
env
- the environment that I persistpublic AbstractTypeResolver(Environment<PK,C,O,P,?,PM,?,?,?,?,?,?> env, org.eclipse.emf.ecore.resource.Resource resource)
Environment
.env
- my environmentresource
- my resourcepublic C resolve(C type)
TypeResolver
type
, returning my own persistent
type instance representing the same OCL type.
The type
may have been newly created by the parser and be
a duplicate of a type previously resolved, or it may actually be a
type that was previously resolved. In the latter case, the
type
is returned as is. The null
type is
considered to be resolved (i.e., the result is also null
).
Usually, this method will delegate to one of the
resolveXyzType()
methods defined by this interface.
resolve
in interface TypeResolver<C,O,P>
type
- a type to resolvetype
if it is already resolvedprotected final Environment<PK,C,O,P,?,PM,?,?,?,?,?,?> getEnvironment()
public org.eclipse.emf.ecore.resource.Resource getResource()
TypeResolver
getResource
in interface TypeResolver<C,O,P>
protected org.eclipse.emf.ecore.resource.Resource createResource()
public PK getCollectionPackage()
protected PK createCollectionPackage()
protected PK findCollectionPackage()
null
if it does not yet existpublic CollectionType<C,O> resolveCollectionType(CollectionKind kind, C elementType)
TypeResolver
kind
and
element type, either created anew or previously created.resolveCollectionType
in interface TypeResolver<C,O,P>
kind
- the kind of collection type to createelementType
- the element typeprotected CollectionType<C,O> createCollectionType(CollectionKind kind, C elementType)
kind
and element
type, assuming that it does not already exist.kind
- the kind of collection to createelementType
- the collection's element typeprotected CollectionType<C,O> findCollectionType(CollectionKind kind, C elementType)
kind
and
element type, if any has already been created.kind
- the element kind to search forelementType
- the element type to search fornull
if none foundpublic PK getTuplePackage()
protected PK createTuplePackage()
protected PK findTuplePackage()
null
if it does not yet existpublic TupleType<O,P> resolveTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
TypeResolver
parts
,
in no particular order, either created anew or previously created. The
resulting type is uniquely defined by the names and types of its parts, and
twp tuple types are considered equal if they have the same number of parts
and their parts correspond one-for-one in name and type (order is not
significant).resolveTupleType
in interface TypeResolver<C,O,P>
parts
- a list of TypedElement
s defining the name and type of
each tuple part. The part names are uniqueprotected TupleType<O,P> createTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
parts
, assuming that
it does not already exist.parts
- the TypedElement
s describing the tuple partsprotected TupleType<O,P> findTupleType(org.eclipse.emf.common.util.EList<? extends TypedElement<C>> parts)
parts
, if any
has already been created.parts
- the TypedElement
s describing the tuple partsnull
if none foundpublic PK getTypePackage()
protected PK createTypePackage()
protected PK findTypePackage()
null
if it does not yet existpublic TypeType<C,O> resolveTypeType(C type)
TypeResolver
type
. This is, effectively, the OCL metatype counterpart
for the specified model type.resolveTypeType
in interface TypeResolver<C,O,P>
type
- a model typeprotected TypeType<C,O> createTypeType(C type)
type
,
assuming that it does not already exist.type
- the referenced model typeprotected TypeType<C,O> findTypeType(C type)
type
,
if any has already been created.type
- the referenced model typenull
if none foundpublic PK getMessagePackage()
protected PK createMessagePackage()
protected PK findMessagePackage()
null
if it does not yet existpublic MessageType<C,O,P> resolveOperationMessageType(O operation)
TypeResolver
operation
.resolveOperationMessageType
in interface TypeResolver<C,O,P>
operation
- the operation call that the message representspublic MessageType<C,O,P> resolveSignalMessageType(C signal)
TypeResolver
signal
.resolveSignalMessageType
in interface TypeResolver<C,O,P>
signal
- the signal send that the message representsprotected MessageType<C,O,P> createOperationMessageType(O operation)
element
,
assuming that it does not already exist.operation
- the operation referenced by the message typeprotected MessageType<C,O,P> createSignalMessageType(C signal)
element
,
assuming that it does not already exist.signal
- the signal referenced by the message typeprotected MessageType<C,O,P> findMessageType(java.lang.Object element)
element
,
if any has already been created.element
- the referenced model elementnull
if none foundpublic PK getAdditionalFeaturesPackage()
protected PK createAdditionalFeaturesPackage()
protected PK findAdditionalFeaturesPackage()
null
if it does not yet existpublic O resolveAdditionalOperation(C owner, O operation)
TypeResolver
owner
type.resolveAdditionalOperation
in interface TypeResolver<C,O,P>
owner
- the type on which the additional operation is definedoperation
- the additional operationpublic java.util.List<O> getAdditionalOperations(C owner)
TypeResolver
getAdditionalOperations
in interface TypeResolver<C,O,P>
owner
- the context classifierprotected O findMatchingOperation(C shadow, O operation)
shadow
class that matches the specified operation
signature.shadow
- the shadow class to searchoperation
- the operation to matchnull
if not foundprotected P findMatchingProperty(C shadow, P property)
shadow
class that matches the specified property
signature.shadow
- the shadow class to searchproperty
- the property to matchnull
if not foundpublic P resolveAdditionalAttribute(C owner, P property)
TypeResolver
owner
type.resolveAdditionalAttribute
in interface TypeResolver<C,O,P>
owner
- the type on which the additional attribute is definedproperty
- the additional attributeprotected boolean hasAdditionalFeatures()
public java.util.List<P> getAdditionalAttributes(C owner)
TypeResolver
getAdditionalAttributes
in interface TypeResolver<C,O,P>
owner
- the context classifierprotected abstract C createShadowClass(C type)
type
.type
- an OCL typeprotected abstract void addProperty(C owner, P property)
owner
- the classifier to own the propertyproperty
- the property to add to the classifierprotected abstract void addOperation(C owner, O operation)
owner
- the classifier to own the operationoperation
- the operation to add to the classifierprotected C findShadowClass(C type)
type
, if it already exists.type
- an OCL typenull
if not foundprotected abstract C getShadowedClassifier(C shadow)
shadow
- a class originally created to shadow a model classifiercreateShadowClass(Object)
,
getShadowClass(Object)
protected C getShadowClass(C type)
type
- a classifier in the modelprotected abstract PK createPackage(java.lang.String name)
name
- the package nameprotected abstract PK findPackage(java.lang.String name)
name
- the package to seeknull
if noneprotected abstract void addClassifier(PK pkg, C classifier)
pkg
- one of my packagesclassifier
- a classifier to add to itpublic void dispose()