unique name validation in project, not the whole workspace [message #766678] |
Fri, 16 December 2011 03:47  |
Eclipse User |
|
|
|
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 #1046916 is a reply to message #1046900] |
Mon, 22 April 2013 10:39   |
Eclipse User |
|
|
|
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 #1047484 is a reply to message #1046940] |
Tue, 23 April 2013 05:13   |
Eclipse User |
|
|
|
Hello Christian,
I set up new "Greeting" project and it works there out of the box...
Problem is somewhere in my code 
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 07:13] by Moderator
|
|
|
|
|
|
|
|
Re: unique name validation in project, not the whole workspace [message #1047655 is a reply to message #1047595] |
Tue, 23 April 2013 09:37   |
Eclipse User |
|
|
|
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
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06893 seconds