Type System TypeData type TypeParameterized type

Type System

The abstraction layer on API basis is called a type system. It provides access to built-in types and different registered metamodel implementations. These registered metamodel implementations offer access to the types they provide. The first part of this documentation describes the type system. The expression sub-language is described afterwards in the second part of this documentation. This differentiation is necessary because the type system and the expression language are two different things. The type system is a kind of reflection layer, that can be extended with metamodel implementations. The expression language defines a concrete syntax for executable expressions, using the type system.

The Java API described here is located in the org.eclipse.xpand.type package and is a part of the subproject core.expressions.

Every object (e.g. model elements, values, etc.) has a type. A type contains properties and operations. In addition it might inherit from other types (multiple inheritance).

As mentioned before, the expressions framework has several built-in types that define operations and properties. In the following, we will give a rough overview of the types and their features. We will not document all of the operations here, because the built-in types will evolve over time and we want to derive the documentation from the implementation (model-driven, of course). For a complete reference, consult the generated API documentation (http://www.openarchitectureware.org/api/built-ins/).

By default, the type system only knows the built-in types. In order to register your own metatypes (e.g. Entity or State), you need to register a respective metamodel implementation with the type system. Within a metamodel implementation the Xpand type system elements (Type, Property, Operation) are mapped to an arbitrary other type system (Java reflections, Ecore or XML Schema).

With Xpad you can work on different kinds of Model representations at the same time in a transparent manner. One can work with EMF models, XML DOM models, and simple JavaBeans in the same Xpand template. You just need to configure the respective MetaModel implementations.

If you want to do so you need to know how the type lookup works. Let us assume that we have an EMF metamodel and a model based on some Java classes. Then the following would be a possible configuration:

<component class="org.eclipse.xpand2.Generator">
   <metaModel class="org.eclipse.internal.xtend.type.impl.java.JavaMetaModel"/>
   <metaModel class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
      <metaModelFile value="my/java/package/metamodel.ecore"/>
   </metaModel>

   ...
</component>

When the runtime needs to access a property of a given object, it asks the metamodels in the configured order. Let us assume that our model element is an instance of the Java type org.eclipse.emf.ecore.EObject and it is a dynamic instance of an EMF EClass MyType.

We have three Metamodels:

The first one will return the type Object (not java.lang.Object but Object of Xpand ). At this point the type Object best fits the request, so it will act as the desired type.

The second metamodel returns a type called org::eclipse::emf::ecore::EObject The type system will check if the returned type is a specialization of the current 'best-fit' type (Object). It is, because it extends Object (Every metatype has to extend Object). At this time the type system assumes org::eclipse::emf::ecore::EObject to be the desired type.

The third metamodel will return metamodel::MyType which is the desired type. But unfortunately it doesn't extend org::eclipse::emf::ecore::EObject as it has nothing to do with those Java types. Instead it extends emf::EObject which extends Object.

We need to swap the configuration of the two metamodels to get the desired type.

<component class="org.eclipse.xpand2.Generator">
   <metaModel class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
      <metaModelFile value="my/java/package/metamodel.ecore"/>
   </metaModel>
   <metaModel class="org.eclipse.internal.xtend.type.impl.java.JavaMetaModel"/>

   ...
</component>