Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Retrieving Xtext resources in project
Retrieving Xtext resources in project [message #689810] Tue, 28 June 2011 12:10 Go to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
When a Xtext resource is saved, I need to generate a single file gathering information about all Xtext files in my project. To give an example: all my xtext resources contain an "Entity" object with an ID. When one of these Entities is modified, I need to generate a single file listing the IDs of all Entities in the project.

I tried to retrieve those entities using the resource.getResourceSet() but not all resources are present in the resourceSet (apparently, they are only added to the resourceSet when they are modified and saved).

What would be the best approach to generate this file with the Entity IDs ?
Re: Retrieving Xtext resources in project [message #690929 is a reply to message #689810] Thu, 30 June 2011 12:32 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Hi Cedric,

assuming your are using Xtext 2.0: You can use an injected
org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider and obtain
the IResourceDescriptions for the resource set. They can provide the
necessary information for your use case.

Hope that helps,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 28.06.11 14:10, Cedric Moonen wrote:
> When a Xtext resource is saved, I need to generate a single file
> gathering information about all Xtext files in my project. To give an
> example: all my xtext resources contain an "Entity" object with an ID.
> When one of these Entities is modified, I need to generate a single file
> listing the IDs of all Entities in the project.
>
> I tried to retrieve those entities using the resource.getResourceSet()
> but not all resources are present in the resourceSet (apparently, they
> are only added to the resourceSet when they are modified and saved).
>
> What would be the best approach to generate this file with the Entity IDs ?
Re: Retrieving Xtext resources in project [message #692951 is a reply to message #690929] Tue, 05 July 2011 14:27 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hi Sebastian,

This is indeed what I'm looking for. Here is my code, this seems to be working but I'm not sure it is really correct:

@Inject ResourceDescriptionsProvider provider
	
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
   var descriptions = provider.getResourceDescriptions(resource)
   var resourceSet = resource.resourceSet
   for (resourceDescription : descriptions.allResourceDescriptions) {
      var uri = resourceDescription.getURI
      var newResource = resourceSet.getResource(uri, true)
      //Do something with newResource
   }
}
Re: Retrieving Xtext resources in project [message #693143 is a reply to message #692951] Tue, 05 July 2011 21:45 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Looks good to me.
If you have really many resources, you should think about clustering the
loop body and you could inspect the resource description itself prior to
loading the resource. I assume you are only interested in resources with
a specific file extension?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 05.07.11 16:27, Cedric Moonen wrote:
> Hi Sebastian,
>
> This is indeed what I'm looking for. Here is my code, this seems to be
> working but I'm not sure it is really correct:
>
> @Inject ResourceDescriptionsProvider provider
>
> override void doGenerate(Resource resource, IFileSystemAccess fsa) {
> var descriptions = provider.getResourceDescriptions(resource)
> var resourceSet = resource.resourceSet
> for (resourceDescription : descriptions.allResourceDescriptions) {
> var uri = resourceDescription.getURI
> var newResource = resourceSet.getResource(uri, true)
> //Do something with newResource
> }
> }
Re: Retrieving Xtext resources in project [message #693283 is a reply to message #693143] Wed, 06 July 2011 07:45 Go to previous message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Yes indeed, this could improve performances.
Thanks for the tip.
Previous Topic:code too long
Next Topic:Xtext/Xpand 1.02 License Question
Goto Forum:
  


Current Time: Mon Sep 28 07:09:45 GMT 2020

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

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

Back to the top