Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to retrieve all visible entities from the global index?
How to retrieve all visible entities from the global index? [message #1776101] Fri, 10 November 2017 19:21 Go to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
Hi,

My language is supposed to be used in Eclipse project only (with Xtext nature). I am interested to retrieve all globally visible entities contained in several files of such project.

For example, if one takes 'arithmetics' Xtext example, each source file contains a 'module' and a number of 'def's. I would like to retrieve list of such modules and the full list of defs from all sources of my project.

This is similar to a list obtained through Ctrl-Shift-R3.

- Would you please advise the best way to do so programatically?
- Is there a way to build single EMF model containing entities from all source files? Or, what is the best way to merge the EMF models from all the files taking into account references resolving?

Thank you,
Serge
Re: How to retrieve all visible entities from the global index? [message #1776102 is a reply to message #1776101] Fri, 10 November 2017 20:00 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

You will find some good starting points in DefaultGlobalScopeProvider. Use the IResourceDescriptionsProvider and IContainer.Manager.

I do not see a sense in merging the EMF models to one. You would have to create a new Resource and move all entries after reading and linking them with plain EMF API.
Re: How to retrieve all visible entities from the global index? [message #1776294 is a reply to message #1776102] Wed, 15 November 2017 07:23 Go to previous messageGo to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
I think I found a compact way to traverse all model's entities. It does not use IResourceDescriptionsProvider and IContainer.Manager directly.

	@Inject
	private IResourceDescriptions descriptions;

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		for (IResourceDescription resDescription : descriptions.getAllResourceDescriptions()) {
			System.out.println(resDescription.getURI());
			for (IEObjectDescription eobjDescription : resDescription.getExportedObjects()) {
				System.out.println("    " + eobjDescription.getName() + " : " + eobjDescription.getEClass().getName());
			}
		}
		return null;
	}


Do you see a pitfall with such approach of retrieving of all globally visible entities?

Thank you

Re: How to retrieve all visible entities from the global index? [message #1776295 is a reply to message #1776294] Wed, 15 November 2017 07:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
this breaks multi project visibility. thus the global scope provider as karsten proposed traverses containers and visible containers

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to retrieve all visible entities from the global index? [message #1776297 is a reply to message #1776294] Wed, 15 November 2017 07:30 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Also note that you get only the descriptions of the entities. It is not guaranteed that IEObjectDescription#EObjectOrProxy will give you the actual objects, and not the proxies only.
Also do not inject IResourceDescriptions directly, use IResourceDescriptionsProvider.
Re: How to retrieve all visible entities from the global index? [message #1776934 is a reply to message #1776297] Wed, 22 November 2017 23:24 Go to previous messageGo to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
Thank you for your great support!

Based on your replies, I came with the code below. Would it be possible for you to review/confirm it? Is it a right approach?

I didn't find a way to do the same without requiring URI of an arbitrary resource of the project.

@Inject
private ResourceDescriptionsProvider resourceDescriptionsProvider;

@Inject
IContainer.Manager containerManager;
...
// Some way to retrieve a resource URI. Your way may differ
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);

IResourceDescriptions index = resourceDescriptionsProvider.createPersistedResourceDescriptions();
IResourceDescription resDesc = index.getResourceDescription(uri);
List<IContainer> visibleContainers = containerManager.getVisibleContainers(resDesc, index);
for (IContainer c : visibleContainers) {
    System.out.println("Container " + c.toString() + " consists of the resource descriptions:");
    for (IResourceDescription rd : c.getResourceDescriptions()) {
        System.out.println(" " + rd);
    }
    System.out.println("Container " + c.toString() + " consists of the exported objects:");
    for (IEObjectDescription eod : c.getExportedObjects()) {
        System.out.println(" " + eod.getName() + " " + eod.getEClass().getName());
    }
}

Re: How to retrieve all visible entities from the global index? [message #1776942 is a reply to message #1776934] Thu, 23 November 2017 05:41 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
I thought you have a file
The visible contains could differ forearch file in a project
Cause they could be in different containers that have different visible containers
(Don't know your tool, your dsl, the zoo of other dsls in your target eclipse, the thing you want to do with that code etc
But you it could work this way.



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Remove warning/error marker
Next Topic:Tracing, StringConcatenationClient and String
Goto Forum:
  


Current Time: Thu Apr 25 22:17:39 GMT 2024

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

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

Back to the top