Skip to content

Instantly share code, notes, and snippets.

Created November 23, 2011 14:16
What would you like to do?
extensions for model elements of the enhanced DomainModel example (Xtext 1.0)
import nl.dslmeinte.xtext.examples.domainmodel.domainModel.Entity
import nl.dslmeinte.xtext.examples.domainmodel.domainModel.Reference
import nl.dslmeinte.xtext.examples.domainmodel.domainModel.Attribute
import nl.dslmeinte.xtext.examples.domainmodel.domainModel.StructuralFeature
* Extensions for model elements of a domain model.
* Usage in Xtend files:
* <pre>
* @Inject extension DomainModelExtensions
* // ...
* entity.structuralFeatures
* reference.structuralFeatures
* reference.entity
* </pre>
class DomainModelExtensions {
def dispatch structuralFeatures(Entity it) {
def dispatch Iterable<StructuralFeature> structuralFeatures(Reference it) {
// (need to specify return type because of recursion)
def dispatch Iterable<StructuralFeature> structuralFeatures(Attribute it) {
// (need to specify return type because common super type of List<T> and Iterable<T> is Object)
* Returns the referenced Entity or null if type references something else (which is an error).
def entity(Reference it) {
if( type.referenced instanceof Entity) type.referenced as Entity else null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment