I have started to work with Eclipse and I'm still a beginner. So I want to get some help from here. I use Xtext to read my DSL. And then I want to show the instance with a diagram, which I have already defined with GMF. But the ecore(MFilesystem) in Xtext and the ecore(Filesystem) in GMF are different. So I use the Xtend to change the model and create an EObject(Filesystem). But i don't know, how the GMF use the resource from Xtent to create a diagram. I show my problem here:
1: I have defined the ecore in xtext(Grammmar):
grammar org.xtext.Filesystem with org.eclipse.xtext.common.Terminals
generate filesystem "http://www.xtext.org/Filesystem"
MFilesystem:
(mfiles+=MFile | mfolder+=MFolder)* ;
MFile:
'myfile' name=ID ';'
;
MFolder:
'myfolder' name = ID ';'
;
2: I have defined the ecore in GMF
3: I try to run the runtime for Xtext
and create the diagramm from my DSL file (test.filesystem).
4: Then I have this problem
5: So I try to use Xtend to change my model in Xtext
package org.xtext.generator
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.xtext.generator.IGenerator
import org.gmf.filesystem.filesystem.Filesystem
import org.gmf.filesystem.filesystem.FilesystemFactory
import org.gmf.filesystem.filesystem.impl.FilesystemFactoryImpl
import org.xtext.filesystem.MFile
import org.xtext.filesystem.MFolder
class FilesystemGenerator implements IGenerator {
Filesystem myfilesystem
FilesystemFactory myfilesystemFactory
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
//TODO implement me
val ast = resource.contents.get(0)
myfilesystemFactory = new FilesystemFactoryImpl()
myfilesystem = myfilesystemFactory.createFilesystem()
val fi = myfilesystemFactory.createFile()
var astFi = (ast.eContents.get(0)) as MFile
fi.name = astFi.name
val fo = myfilesystemFactory.createFolder()
var astFo = (ast.eContents.get(1)) as MFolder
fo.name = astFo.name
}
}
6: But it does not work. I think, I have done something wrong. So I want to know, how I can do so that the GMF uses myfilesystem
to create a diagram.
Thanks.
The Xtext directive
generates a new metamodel instead of importing an existing one. Instead, specify
to refer to the metamodel that your GMF editor is using. See this post for more info.