I have a XText project within Eclipse, with my own grammar file implemented. Using the doGenerate function I generate several .java files. So far everything works like a charm.
My problem is that every time I generate my files I need to do the following:
I would like to be able to make any or all of these steps automatic every time the doGenerate function is called, so is there a way to do just that with xtend/java code? I should mention that my grammar requires the user to specify the project directory + name, so that info is available at runtime from within the doGenerate function.
The code should preferably be able to detect if there is already a project with the same name, and update it's contents within the open Eclipse instance at runtime if such a thing is possible.
Alternatively, if this cannot be done with xtend/java, can this be done with a plugin?
Creating new projects has to be done through the resources API of eclipse. If you are ok, with having that dependency in your code generator, you can simply add a dependency to org.eclipse.core.resources and do something like
ResourcesPlugin.getWorkspace().getRoot().getProject("myProject").create(null)
If you don't want that dependency, because you run your code generator from other environments (e.g. Maven), you need to abstract the project creation into its own class, inject it and have individual implementations for Eclipse and non-Eclipse.
The code generator API of Xtext (IFileSystemAccess) will use the Eclipse resources API under the hood, to make sure all notifications etc. work as expected and you don't need to manually refresh. So no need for different implementations here, as Xtext takes care of that.