Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » unique name validation in project, not the whole workspace(How to get only Resources of project with IResourceDescriptions?)
unique name validation in project, not the whole workspace [message #766678] Fri, 16 December 2011 08:47 Go to next message
Annette Pohl is currently offline Annette Pohl
Messages: 9
Registered: July 2011
Junior Member
Hello!

I have to check for unique names in my Xtext-project and I do this with a validator and collect all EObjects (in my case EEntities) like this:

		List<EEntity> allEntities = new ArrayList<EEntity>();
		for (IResourceDescription resourceDescription : resourceDescriptions.getAllResourceDescriptions()) {
			for (IEObjectDescription eobjectDescription : resourceDescription.getExportedObjects()) {
				EObject eObjectOrProxy = eobjectDescription.getEObjectOrProxy();
				if (eObjectOrProxy instanceof EEntity) {
					allEntities.add( (EEntity) eobjectDescription.getEObjectOrProxy() );
				}
			}
		}


This is working fine for me. But when we were testing the DSL in a real-life-project we discovered that getAllResourceDescriptions of IResourceDescriptions delievers all ResourceDescriptions of the whole workspace. I will have to narrow this to project-level but do not know how I can do this.

Any help concerning this issue is highly appreciated. Thanks!

Annette
Re: unique name validation in project, not the whole workspace [message #766681 is a reply to message #766678] Fri, 16 December 2011 08:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
Hello Annette,

have a look at this http://www.eclipse.org/forums/index.php/mv/msg/261440/754503/#msg_754503

~Christian
Re: unique name validation in project, not the whole workspace [message #766705 is a reply to message #766681] Fri, 16 December 2011 09:35 Go to previous messageGo to next message
Annette Pohl is currently offline Annette Pohl
Messages: 9
Registered: July 2011
Junior Member
Hi Christian!

Thanks for your reply Smile

I tried the suggestion in the post above and I did not get things right, yet.
If I use

IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription( eEntity.eResource().getURI() );


to get the ResourceDescription only the file of my entity is validated. But I want the validation to consider all entities in all files of one project. So I guess I will have to use getAllResourceDescriptions but somehow filter the list of ResourceDescriptions to get rid of the entities of my workspace which do not belong to my project.

I have one more question:
I inject IResourceDescriptions in my Validator and in your solution ResourceDescriptionsProvider is injected and the ResourceDescriptions is fetched by the eObject of the validation. Should I change this or does not it matter?

[Updated on: Fri, 16 December 2011 09:36]

Report message to a moderator

Re: unique name validation in project, not the whole workspace [message #766724 is a reply to message #766705] Fri, 16 December 2011 10:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
Hi this is why you use the Container Manager. IT takes care of the
project and its resources. Note: standalone The Container is the
resourceset
Re: unique name validation in project, not the whole workspace [message #766852 is a reply to message #766724] Fri, 16 December 2011 14:50 Go to previous messageGo to next message
Annette Pohl is currently offline Annette Pohl
Messages: 9
Registered: July 2011
Junior Member
I never used a Container Manager - I'm quite new to Xtext - but I will try on Monday.
Thanks, Christian!
Re: unique name validation in project, not the whole workspace [message #767941 is a reply to message #766852] Mon, 19 December 2011 08:45 Go to previous messageGo to next message
Annette Pohl is currently offline Annette Pohl
Messages: 9
Registered: July 2011
Junior Member
I just tried using the Container-Manager and it worked instantly and I am once more convinced that the Xtext-Framework is really great Smile
If someone is interested in the code:

	@Inject
	IContainer.Manager containermanager;

	@Inject
	ResourceDescriptionsProvider resourceDescriptionsProvider;

	public List<EEntity> getAllEntitiesFor( EObject eObject ) {
		List<EEntity> allEntities = new ArrayList<EEntity>();
		IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions( eObject.eResource() );
		IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription( eObject.eResource().getURI() );
		List<IContainer> visiblecontainers = containermanager.getVisibleContainers( resourceDescription, resourceDescriptions );
		for (IContainer container : visiblecontainers) {
			for (IEObjectDescription eobjectDescription : container.getExportedObjects()) {
				EObject eObjectOrProxy = eobjectDescription.getEObjectOrProxy();
				if (eObjectOrProxy instanceof EEntity) {
					allEntities.add( (EEntity) eobjectDescription.getEObjectOrProxy() );
				}
			}
		}
		return allEntities;
	}


Thanks for the help, Christian.
Re: unique name validation in project, not the whole workspace [message #1046885 is a reply to message #767941] Mon, 22 April 2013 13:52 Go to previous messageGo to next message
Michal S is currently offline Michal S
Messages: 73
Registered: July 2011
Member
Hello,
I used described approach to collect all EObjects in project previously, but it does not seem to work anymore Sad ...
Problem is here:
IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions( eObject.eResource() );

resourceDescriptions object now contains only descriptions of few resources (the containing resource itself and all resources referenced from that resource) and I would need there descriptions of all resources, not only referenced ones.
I do not understand what happend, this approach worked well before.
Can anyone help me with this issue?
Thank you & Best regards
Michal
Re: unique name validation in project, not the whole workspace [message #1046900 is a reply to message #1046885] Mon, 22 April 2013 14:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
HI,

this is the reason to use the container manager and ask it for (visible) containers
Re: unique name validation in project, not the whole workspace [message #1046916 is a reply to message #1046900] Mon, 22 April 2013 14:39 Go to previous messageGo to next message
Michal S is currently offline Michal S
Messages: 73
Registered: July 2011
Member
Christian,
thank you for your answer.
I also ask for visible containers.
Problem is, that if I use getVisibleContainers(resourceDescription, resourceDescriptions) and resourceDescriptions object contains only descriptions of related resources, than also visible containers contain only limited amount of containers (not all of them...).
Here is my function:
def collectAllDescriptions(EClass clazz){
	val resourceDescriptions = rdp.getResourceDescriptions(resource)
	val resourceDescription = resourceDescriptions.getResourceDescription(resource.URI)
	val containers = containerManager.getVisibleContainers(resourceDescription,resourceDescriptions)
	var out = new ArrayList<IEObjectDescription>()
	for(container:containers){
		out.addAll(container.getExportedObjectsByType(clazz))
	}
	out
}


rdp is injected ResourceDescriptionsProvider and resource is processed resource.

If I use Project->Clean, everything works well, as object resourceDescriptions contains all model files contained in project. Problem occurs only when I save single model file and generator is called (resourceDescriptions contain only limited amount of descriptions).
Thank you,
Michal
Re: unique name validation in project, not the whole workspace [message #1046924 is a reply to message #1046916] Mon, 22 April 2013 14:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
And what is your expected behaviour?
what do you want to achieve?
the code gives you all visible stuff from your context
Re: unique name validation in project, not the whole workspace [message #1046928 is a reply to message #1046924] Mon, 22 April 2013 15:00 Go to previous messageGo to next message
Michal S is currently offline Michal S
Messages: 73
Registered: July 2011
Member
I need to collect all EObjects of specific type across all model files in the project. (E.g. all Greeting objects .... as I need to generate file containing their names...)
Thank you & Regards,
Michal
Re: unique name validation in project, not the whole workspace [message #1046940 is a reply to message #1046928] Mon, 22 April 2013 15:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
If you ask the container for exported objects of that type it should
work. (If you really export them)

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: unique name validation in project, not the whole workspace [message #1047484 is a reply to message #1046940] Tue, 23 April 2013 09:13 Go to previous messageGo to next message
Michal S is currently offline Michal S
Messages: 73
Registered: July 2011
Member
Hello Christian,
I set up new "Greeting" project and it works there out of the box...
Problem is somewhere in my code Sad
I tried to debug, what the difference is and I found out, that following code gives different results:
containerManager.getVisibleContainers(resourceDescription,resourceDescriptions)


In case of greeting project, where everything works perfectly, the result is:
[[StateBasedContainer] container '=rrrrrrrrrrrrrrrrrrrrrrr/src' from org.eclipse.xtext.ui.containers.JavaProjectsState@ffde9e]

And If I watch elementData->0->descriptions, it contains:
org.eclipse.xtext.builder.clustering.CurrentDescriptions$ResourceSetAware@1c60440



In case of my real project, where it does not work, the result is:
[[StateBasedContainer] container 'all' from org.eclipse.xtext.resource.containers.FlatResourceSetBasedAllContainersState@b75459]

And If I watch elementData->0->descriptions, it contains:
[ResourceSetBasedResourceDescriptions
  [DefaultResourceDescription uri=platform:/resource/LCEProject/src/file.tcf]
]


I don't understand, why it behaves differently. Do you have any idea, why could this situation occur?
Thank you & Best regards,
Michal

EDIT:
I found out, that containerManager in Greeting example uses as stateProvider
 org.eclipse.xtext.ui.containers.ContainerStateProvider 
, on the other hand, in case of my real project
org.eclipse.xtext.resource.containers.ResourceSetBasedAllContainersStateProvider
.

Difference between Greeting example is, that I @Inject containerManager and resourceDescriptionsProvider in MyDslGenerator class as follows:
@Inject
ResourceDescriptionsProvider rdp

@Inject
IContainer$Manager containerManager


In case of my real project I use not Injected class and I inject the containerManager in that class in constructor as follows:
val injector = Guice::createInjector(new MyRealRuntimeModule)
this.containerManager = injector.getInstance(typeof(IContainer$Manager))

Could be this the reason of my problems?

[Updated on: Tue, 23 April 2013 11:13]

Report message to a moderator

Re: unique name validation in project, not the whole workspace [message #1047553 is a reply to message #1047484] Tue, 23 April 2013 11:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
No Message Body
Re: unique name validation in project, not the whole workspace [message #1047554 is a reply to message #1047553] Tue, 23 April 2013 11:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
Hi,

Runtime Module != UI Module.
Re: unique name validation in project, not the whole workspace [message #1047591 is a reply to message #1047554] Tue, 23 April 2013 12:25 Go to previous messageGo to next message
Michal S is currently offline Michal S
Messages: 73
Registered: July 2011
Member
Hello Christian,
thank you for your answer.
If I understand you well, I should use
val injector = Guice::createInjector(new MyRealUIModule)

It sounds reasonable, as all "Project" related things are Eclipse UI based. On the other hand, I should not reference from generator to UI module, as the generator is also used out of Eclipse... So how this should be done?

Anyway, I changed the structure of generator to I can use standard @Inject annotation and it works well now, but I am still interested in the previous task...
Thank you for your help & Best regards
Michal
Re: unique name validation in project, not the whole workspace [message #1047595 is a reply to message #1047591] Tue, 23 April 2013 12:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
Hi,

in which kontext do you use this. why at all using an injector yourself??????

http://koehnlein.blogspot.de/2012/11/xtext-tip-how-do-i-get-guice-injector.html
Re: unique name validation in project, not the whole workspace [message #1047652 is a reply to message #1047595] Tue, 23 April 2013 13:34 Go to previous messageGo to next message
Michal S is currently offline Michal S
Messages: 73
Registered: July 2011
Member
No Message Body

[Updated on: Tue, 23 April 2013 13:40]

Report message to a moderator

Re: unique name validation in project, not the whole workspace [message #1047655 is a reply to message #1047595] Tue, 23 April 2013 13:37 Go to previous messageGo to next message
Michal S is currently offline Michal S
Messages: 73
Registered: July 2011
Member
Hello Christian,
to explain my problem:
I use in my DSL multiple generators (I generate various implementations from my models ... and I switch between them using preferencePage or arguments of runGenerator() in Main class).
I created own package for every generator. Default MyDslGenerator.xtend was used just to create objects of my specific generators. Previously, I have not injected them, but just created standardly using constructor. If I injected e.g. ResourceDescriptionsProvider or Container.Manager in this standardly created objects, it was always null injected. That is why I tried to use
val injector = Guice::createInjector(new MyDslRuntimeModule)
this.containerManager = injector.getInstance(typeof(IContainer$Manager))

Now, after reading Jan's blog, I realize, this was bad approach.

Just before you answered, I changed the structure of my generator that way, that I @Inject all specific generators in MyDslGenerator.xtend ... and consequently I can @Inject ResourceDescriptionsProvider or Container.Manager without any problem in my specific generators, so it works very well now.
Thank you & Best regards
Michal
Re: unique name validation in project, not the whole workspace [message #1047672 is a reply to message #1047655] Tue, 23 April 2013 14:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
Hi,

still the question: why dont you generate the classes via guice directly?
Re: unique name validation in project, not the whole workspace [message #1047690 is a reply to message #1047672] Tue, 23 April 2013 14:25 Go to previous messageGo to next message
Michal S is currently offline Michal S
Messages: 73
Registered: July 2011
Member
What you mean be "generate the classes via guice directly"?
As I mentioned in the last sentence of my previous message I already inject my generator classes using @Inject keyword. Is this not "directly"?
Regards,
Michal
Re: unique name validation in project, not the whole workspace [message #1047716 is a reply to message #1047690] Tue, 23 April 2013 15:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6384
Registered: July 2009
Senior Member
Yes but then you wont get null for container manager etc
Re: unique name validation in project, not the whole workspace [message #1047733 is a reply to message #1047716] Tue, 23 April 2013 15:16 Go to previous message
Michal S is currently offline Michal S
Messages: 73
Registered: July 2011
Member
Yes, and as I wrote, it works now perfectly... There are no nulls anymore.
The result is, that my workaround with "createInjector" was wrong.
Thank you for all your help.
Regards,
Michal
Previous Topic:cross-file references does not work after update (missing .classpath file)
Next Topic:How to manufacture model elements
Goto Forum:
  


Current Time: Wed Oct 22 12:26:35 GMT 2014

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

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