Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » When to use createLiveScopeResourceDescriptions?(Questions about correctly using ResourceDescriptionsProvider)
When to use createLiveScopeResourceDescriptions? [message #804653] Wed, 22 February 2012 21:28 Go to next message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

Hello,

I recently stumbled upon an itemis blog post, where I learned that I should not be injecting IResourceDescriptions into my classes, but instead to inject ResourceDescriptionsProvider:

Quote:
...So if you want to access the index yourself, be it for modifying scoping, validation or something else, it is important NOT!! simply to inject IResourceDescriptions (this is an extremely common mistake causing linking problems). In Xtext 2 you should use (read: inject) the ResourceDescriptionsProvider...

(from http://blogs.itemis.de/stundzig/archives/809)

After reading this, I changed my classes and found I could obtain the same functionality if I injected ResourceDescriptionsProvider and then called ResourceDescriptionsProvider.createResourceDescriptions().

But I couldn't help but notice the other, similarly-named methods:


  1. ResourceDescriptionsProvider.createLiveScopeResourceDescriptions()
  2. ResourceDescriptionsProvider.createBuilderScopeResourceDescriptions()


When would it be appropriate to use each of these? I thought I had a good idea what they meant, but when I called createLiveScopeResourceDescriptions(), I found an empty list returned...

Re: When to use createLiveScopeResourceDescriptions? [message #804673 is a reply to message #804653] Wed, 22 February 2012 21:56 Go to previous messageGo to next message
Alex Tugarev is currently offline Alex TugarevFriend
Messages: 14
Registered: July 2011
Junior Member
Joey Mink wrote on Wed, 22 February 2012 16:28
...
When would it be appropriate to use each of these? I thought I had a good idea what they meant, but when I called createLiveScopeResourceDescriptions(), I found an empty list returned...


Have a look at this message: eclipse.org/forums/index.php/mv/msg/228269/707018/#msg_707018
Re: When to use createLiveScopeResourceDescriptions? [message #804684 is a reply to message #804673] Wed, 22 February 2012 22:15 Go to previous messageGo to next message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

Alex,

Thanks for the reply. I had seen that post before - the relevant portion of it seems to be this:

Quote:
the LIVE_SCOPE is necessary for refactorings in the UI. It is save to
use the ResourceSetBasedResourceDescriptions there.


I'm still left wondering, however, when I might call ResourceDescriptionsProvider.createLiveScopeResourceDescriptions(). I currently call createResourceDescriptions(), which appears to give me an IResourceDescriptions instance (Xtext index) containing all IResourceDescription instances in my workspace. Could createLiveScopeResourceDescriptions() potentially give me access to exported objects in an unsaved file or something?
Re: When to use createLiveScopeResourceDescriptions? [message #805053 is a reply to message #804684] Thu, 23 February 2012 09:27 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Clients should only call
ResourceDescriptionsProvider.getResourceDescriptions(ResourceSet) which
decides on the given resource set which implementation to return.

Not sure why the other methods are public. Maybe for testing.

There are three types of these:
NAMED_BUILDER_SCOPE: used by the builder. Contains information on
persisted resources only

dirty state scope (default): Information on resources in unsaved editors
shadow the information on the persisted resources

LIVE_SCOPE: For refactoring only: ResourceSet contents shadow the dirty
state information. We must simulate the model changes of the refactoring
in a temporary resource set to calculate the text changes.

Am 22.02.12 23:15, schrieb Joey Mink:
> Alex,
>
> Thanks for the reply. I had seen that post before - the relevant portion
> of it seems to be this:
>
> Quote:
>> the LIVE_SCOPE is necessary for refactorings in the UI. It is save to
>> use the ResourceSetBasedResourceDescriptions there.
>
>
> I'm still left wondering, however, when I might call
> ResourceDescriptionsProvider.createLiveScopeResourceDescriptions(). I
> currently call createResourceDescriptions(), which appears to give me an
> IResourceDescriptions instance (Xtext index) containing all
> IResourceDescription instances in my workspace. Could
> createLiveScopeResourceDescriptions() potentially give me access to
> exported objects in an unsaved file or something?


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


---
Get professional support from the Xtext committers at www.typefox.io
Re: When to use createLiveScopeResourceDescriptions? [message #805235 is a reply to message #805053] Thu, 23 February 2012 14:29 Go to previous messageGo to next message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

Jan,

Thanks for the clarification. It seems I've been using ResourceDescriptionsProvider incorrectly, as I used it the following way to obtain all IResourceDescription instances for a given Eclipse project:

public class TplFile {
	@Inject
	private ResourceDescriptionsProvider resourceDescriptionsProvider;

	public List<IResourceDescription> getResourceDescriptionsFor(IProject project)
	{		
		List<IResourceDescription> descriptions = new ArrayList<IResourceDescription>();
		
		IResourceDescriptions xtextIndex = resourceDescriptionsProvider.createResourceDescriptions();
		for (IResourceDescription desc : xtextIndex.getAllResourceDescriptions())
		{
			org.eclipse.emf.common.util.URI descUri = desc.getURI();
			List<String> uriSegments = descUri.segmentsList();
			String projectSegment = uriSegments.get(1);
			if (project.getName().equals(projectSegment))
			{
				// We found an IResourceDescription for a file in the current project:
				descriptions.add(desc);
			}
		}
		return descriptions;
	}
}


If I change the code above to use ResourceDescriptionsProvider.getResourceDescriptions(Resource) instead, how should I choose the Resource parameter to either:


  1. Obtain all IResourceDescriptions in the workspace and filter them as I do now or
  2. Obtain only the IResourceDescriptions for the given project so I do not have to filter the results?



Re: When to use createLiveScopeResourceDescriptions? [message #805320 is a reply to message #805235] Thu, 23 February 2012 16:26 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
You're mixing up two things here:
1) Obtaining the IResourceDescriptions for a given scope (builder,
dirty, live)
2) Getting the all IResourceDescription entries for a given project

Let's start with 1):
What is the purpose of the code? I ask because you usually are in the
context of a model, which allows you to access its resource set and us
it in the ResourceDescriptionsProvider to obtain the ResourceDescriptions.

If you're interested in the dirty state, it's okay to have the
IResourceDescriptions directly injected. If you want the persisted
information only, get an ResourceSet configured for your project using
the IResourceSetProvider, ste the load option NAMED_BUILDER_SCOPE and
use this resource set in the ResourceDescriptionsProvider to get the
IResourceDescriptions.

Not to step 2)
An IResourceDescriptions object contains IResourceDescription (without
's') entries for all indexed resources. You can filter the ones in a
given project by their URI. If you want to have descriptions from
dependent projects, too, you'll likely want to dig into the
documentation on IContainers in the section on scoping in the Xtext docs.


Am 23.02.12 15:29, schrieb Joey Mink:
> Jan,
>
> Thanks for the clarification. It seems I've been using
> ResourceDescriptionsProvider incorrectly, as I used it the following way
> to obtain all IResourceDescription instances for a given Eclipse project:
>
>
> public class TplFile {
> @Inject
> private ResourceDescriptionsProvider resourceDescriptionsProvider;
>
> public List<IResourceDescription> getResourceDescriptionsFor(IProject
> project)
> {
> List<IResourceDescription> descriptions = new
> ArrayList<IResourceDescription>();
>
> IResourceDescriptions xtextIndex =
> resourceDescriptionsProvider.createResourceDescriptions();
> for (IResourceDescription desc : xtextIndex.getAllResourceDescriptions())
> {
> org.eclipse.emf.common.util.URI descUri = desc.getURI();
> List<String> uriSegments = descUri.segmentsList();
> String projectSegment = uriSegments.get(1);
> if (project.getName().equals(projectSegment))
> {
> // We found an IResourceDescription for a file in the current project:
> descriptions.add(desc);
> }
> }
> return descriptions;
> }
> }
>
>
> If I change the code above to use
> ResourceDescriptionsProvider.getResourceDescriptions(Resource) instead,
> how should I choose the Resource parameter to either:
>
>
> Obtain all IResourceDescriptions in the workspace and filter them as I
> do now or
> Obtain only the IResourceDescriptions for the given project so I do not
> have to filter the results?
>
>
>
>


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


---
Get professional support from the Xtext committers at www.typefox.io
Re: When to use createLiveScopeResourceDescriptions? [message #805416 is a reply to message #805320] Thu, 23 February 2012 18:44 Go to previous message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

Quote:
What is the purpose of the code? I ask because you usually are in the
context of a model, which allows you to access its resource set and us
it in the ResourceDescriptionsProvider to obtain the ResourceDescriptions.


The purpose of the code in question is to give us programmatic access to an instance of our DSL. We used to have a custom-built parser and DOM in our Eclipse IDE. We used that DOM to create views (Common Navigators, etc.) based on the the user's DSL code. But now we've migrated to Xtext (gaining lots of functionality in the process), and are basically trying to restore the old views by backing them with the Xtext index instead of our custom parser and DOM. Our context is usually the active editor, from which we derive the current project.

Thanks for the rest of your reply - I just need to spend some time digesting it and trying things out Smile

Previous Topic:How to retrieve all instances of given grammar class?
Next Topic:Collapse All/Expand All for Outline View
Goto Forum:
  


Current Time: Fri Apr 10 10:01:13 GMT 2020

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

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

Back to the top