Hey,
I would like to access the root element of my grammar. For instance:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "h_t_t_p_:_/_/_w_w_w.xtext.org/example/mydsl/MyDsl"
Model:
greetings+=Greeting∗;
Greeting:
'Hello' name=ID '!';
Is there a way I could access all Model instances (spread over several resources file in the workspace)? I need all Model instances in the generation process. Here is what I got so far:
If user saves one file, the generation process is triggered:
class MyDslGenerator implements IGenerator {
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
// HERE I CAN ACCESS THE PRESENT "Model" instance
}
}
I use following code to find the root element:
TreeIterator<EObject> it = resource.getAllContents();
while (it.hasNext()) {
EObject next = it.next();
if(next instanceof Model){
//perform your operations!
break;
}
}
With this solution I'm just able to find the Model instance of the current file (where the user hit save). How do I find all other? Thank you.
Kon