Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Access root instance of grammar of all resource files in the workspace
Access root instance of grammar of all resource files in the workspace [message #896120] Tue, 17 July 2012 10:28 Go to next message
kon f is currently offline kon fFriend
Messages: 152
Registered: March 2012
Senior Member
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
Re: Access root instance of grammar of all resource files in the workspace [message #896122 is a reply to message #896120] Tue, 17 July 2012 10:49 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Hi Kon!

Please read Xtend Generating from multiple input models for an approach.

Regards,
~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Access root instance of grammar of all resource files in the workspace [message #896157 is a reply to message #896122] Tue, 17 July 2012 12:41 Go to previous message
kon f is currently offline kon fFriend
Messages: 152
Registered: March 2012
Senior Member
Thank you Karsten Smile
Previous Topic:Integrate existed interpreter with Xtext
Next Topic:Chain generation from language1 -> language2 -> java
Goto Forum:
  


Current Time: Fri Apr 26 18:20:19 GMT 2024

Powered by FUDForum. Page generated in 0.03208 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top