When to use createLiveScopeResourceDescriptions? [message #804653] |
Wed, 22 February 2012 16:28  |
Eclipse User |
|
|
|
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:
- ResourceDescriptionsProvider.createLiveScopeResourceDescriptions()
- 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 #805320 is a reply to message #805235] |
Thu, 23 February 2012 11:26   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03746 seconds