Serializing Instances based on the Domainmodel (15 minutes tutorial) [message #1806740] |
Tue, 14 May 2019 10:39  |
Eclipse User |
|
|
|
Hi,
I want to programmatically create EMF instances based on the Domainmodel / Entity DSL out of the 15 minutes tutorial (https://www.eclipse.org/Xtext/documentation/102_domainmodelwalkthrough.html#write-the-grammar) and serialize them back into their textual Xtext representation.
E.g., I want to create an EMF instances according to this Xtext representation:
datatype String
entity Blog {
title: String
}
My solution is as follows:
@Inject Serializer serializer
def void serializer() {
val f = DomainmodelFactory.eINSTANCE
val domainModel = f.createDomainmodel
val dataType = f.createDataType
dataType.setName("String")
domainModel.getElements.add(dataType)
val entity = f.createEntity
entity.setName("Blog")
domainModel.getElements.add(entity)
val feature = f.createFeature
feature.setName("title")
feature.setType(dataType)
entity.getFeatures.add(feature)
println(serializer.serialize(domainModel))
}
Unfortunately, I get a NullPointerException. It seems to me as if the cross references in square brackets are the problem, because without them everything works just fine. Does anyone have a solution for this problem / know whats wrong?:
java.lang.NullPointerException
at org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getResourceScope(ImportedNamespaceAwareLocalScopeProvider.java:103)
at org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getScope(ImportedNamespaceAwareLocalScopeProvider.java:97)
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02978 seconds