Confusion about two ways to get resourceDescription [message #1777172] |
Sat, 25 November 2017 11:46  |
Eclipse User |
|
|
|
Recent days, I'm creating my DSL with xtext.
My DSL has no package mechanism, all element are global visible in one project.
I found that the default NamesAreUniqueValidator only support check duplicate names in one resource, but I need check duplicate names globally.
So I write my own "NamesAreUniqueValidator" (SmlValidator):
class SmlValidator extends AbstractSmlValidator {
@Inject
IResourceServiceProvider.Registry resourceServiceProviderRegistry = IResourceServiceProvider.Registry.INSTANCE;
@Inject
ResourceDescriptionsProvider resourceDescriptionsProvider;
@Inject
IContainer.Manager containerManager;
@Inject
ISmlNamesAreUniqueValidationHelper helper;
@Check
def checkUniqueNamesInProjectOf(SmlModel smlModel) {
println("checkUniqueNamesInProjectOf SmlType " + smlModel + " resource " + smlModel.eResource)
val Resource resource = smlModel.eResource
val IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions(resource)
val IResourceServiceProvider resourceServiceProvider = resourceServiceProviderRegistry.getResourceServiceProvider(resource.getURI());
val IResourceDescription.Manager manager = resourceServiceProvider.getResourceDescriptionManager();
// Issue:
// Two ways to get resourceDescription, whats is the difference???
// If use resourceDescription from manager, it works fine.
val IResourceDescription resourceDescription = manager.getResourceDescription(resource);
// If use resourceDescription from resourceDescriptions, exception thrown when found duplicate names.
// val IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(resource.URI)
val ArrayList<IResourceDescription> outsideVisibleResourceDescriptions = new ArrayList;
for (visibleContainer : containerManager.getVisibleContainers(resourceDescription, resourceDescriptions)) {
for (visibleResourceDesc : visibleContainer.resourceDescriptions) {
if(visibleResourceDesc.URI != resourceDescription.URI){
outsideVisibleResourceDescriptions.add(visibleResourceDesc)
}
}
}
for (eod : resourceDescription.exportedObjects) {
for (ovrd : outsideVisibleResourceDescriptions) {
for (oveod : ovrd.exportedObjects) {
if(eod.name == oveod.name){
helper.createError(eod, eod.EClass, this)
}
}
}
}
}
}
interface ISmlNamesAreUniqueValidationHelper {
def void createError(IEObjectDescription description, EClass clusterType, ValidationMessageAcceptor acceptor)
}
class SmlNamesAreUniqueValidationHelper extends NamesAreUniqueValidationHelper implements ISmlNamesAreUniqueValidationHelper {
// protected to public
override createError(IEObjectDescription description, EClass clusterType, ValidationMessageAcceptor acceptor) {
super.createDuplicateNameError(description, clusterType, acceptor)
}
}
class SmlRuntimeModule extends AbstractSmlRuntimeModule {
override configure(Binder binder) {
super.configure(binder)
binder.bind(ISmlNamesAreUniqueValidationHelper).to(SmlNamesAreUniqueValidationHelper);
}
}
The source code above can works.
But my question is:
There are two ways to get resourceDescription, what is different between
val IResourceDescription resourceDescription = manager.getResourceDescription(resource);
and
val IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(resource.URI)
If I comment
val IResourceDescription resourceDescription = manager.getResourceDescription(resource);
and uncomment
val IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(resource.URI)
After run eclipse, the exception occured when there are some duplicate names in two resources:
0 [Worker-3] ERROR org.eclipse.xtext.validation.CompositeEValidator - Error executing EValidator
java.lang.IllegalArgumentException: You can only add issues for EObjects contained in the currently validated resource 'platform:/resource/test.sml/AAA.sml'. But the given EObject was contained in 'null'
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.checkIsFromCurrentlyCheckedResource(AbstractDeclarativeValidator.java:571)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.acceptError(AbstractDeclarativeValidator.java:554)
I am very confused about this issue.
Very thanks.
[Updated on: Sat, 25 November 2017 12:11] by Moderator
|
|
|
|
|
|
Re: Confusion about get resourceDescription from IReso [message #1777176 is a reply to message #1777175] |
Sat, 25 November 2017 12:30   |
Eclipse User |
|
|
|
Hi, Christian,
I like xtext, but I am very confused about its resource management (IResourceDescription, IResourceDescriptions, IResourceDescription.Manager, IResourceServiceProvider, ResourceDescriptionsProvider, IContainer.Manager, and so on...)
It seems to be very different from emf.
My original understanding is
IResourceDescription is a symbol table for one resource.
IResourceDescriptions is global symbol table, it should be the singleton.
Am I right?
But what is IResourceDescription.Manager? why do we need to get IResourceDescriptions from manager instead of IResourceDescriptions?
(For instance, Why IResourceDescription in manager and IResourceDescription in IResourceDescriptions are not the same object when it point to the same resource?)
Is there any document, tutorial or video about xtext resource management?
IResourceDescription, IResourceDescriptions, IResourceDescription.Manager, IResourceServiceProvider, ResourceDescriptionsProvider, IContainer.Manager, etc...
(To be frank, the official documents looks some difficult..)
Very thanks.
[Updated on: Sat, 25 November 2017 12:34] by Moderator
|
|
|
|
|
|
|
|
Re: Confusion about get resourceDescription from IReso [message #1777182 is a reply to message #1777179] |
Sat, 25 November 2017 13:06   |
Eclipse User |
|
|
|
Christian Dietrich wrote on Sat, 25 November 2017 17:42and no there is no docs. these compontents go very deep into xtext internas
Is there any way to create a simple test bench which integrated IResourceDescription, IResourceDescriptions, IResourceDescription.Manager, IResourceServiceProvider, ResourceDescriptionsProvider, IContainer.Manager, etc?
For instance, the test bench has a clear entry point (use source code instead of decompile class), and we can simply run and debug it.
I want to dig into xtext source code, but I lack eclipse plug-in development knowledge (So it seems to need a lot of effort) .
[Updated on: Sat, 25 November 2017 13:08] by Moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.10910 seconds