Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Confusion about two ways to get resourceDescription
Confusion about two ways to get resourceDescription [message #1777172] Sat, 25 November 2017 16:46 Go to next message
serio adamo is currently offline serio adamoFriend
Messages: 24
Registered: September 2017
Junior Member
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 17:11]

Report message to a moderator

Re: Confusion about get resourceDescription from IReso [message #1777173 is a reply to message #1777172] Sat, 25 November 2017 16:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Adding errors and retrieving stuff from the index are two different things.
=> you should only add errors to the stuff you are currently validating

smlModel and it's children.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Confusion about get resourceDescription from IReso [message #1777174 is a reply to message #1777173] Sat, 25 November 2017 16:59 Go to previous messageGo to next message
serio adamo is currently offline serio adamoFriend
Messages: 24
Registered: September 2017
Junior Member
Christian Dietrich wrote on Sat, 25 November 2017 16:49
Adding errors and retrieving stuff from the index are two different things.
=> you should only add errors to the stuff you are currently validating

smlModel and it's children.


Thanks for your answer.
Yes, I understand I should ony add errors to the stuff I am currently validating.

But what is difference between
val IResourceDescription resourceDescription = manager.getResourceDescription(resource);
and
val IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(resource.URI)

Only if I use the second one, the exception occur.
Both two resourceDescription point to the same resource which the smlModel(currently validating) in.

[Updated on: Sat, 25 November 2017 17:08]

Report message to a moderator

Re: Confusion about get resourceDescription from IReso [message #1777175 is a reply to message #1777174] Sat, 25 November 2017 17:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
the manager does create the index entry from the scratch,
the resourcedescriptions.getResourseDescription(uri) does give you the existing index entry


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Confusion about get resourceDescription from IReso [message #1777176 is a reply to message #1777175] Sat, 25 November 2017 17:30 Go to previous messageGo to next message
serio adamo is currently offline serio adamoFriend
Messages: 24
Registered: September 2017
Junior Member
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 17:34]

Report message to a moderator

Re: Confusion about get resourceDescription from IReso [message #1777177 is a reply to message #1777176] Sat, 25 November 2017 17:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
No the problem is how you validate.
Not how you get the index entry

the NamesAreUniqueValidationHelper is not designed to work on more than one file


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 25 November 2017 17:38]

Report message to a moderator

Re: Confusion about get resourceDescription from IReso [message #1777178 is a reply to message #1777177] Sat, 25 November 2017 17:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
and

IResourceDescription is a symbol table for one resource.
IResourceDescriptions is global symbol table, it should be the singleton.

thats correct.

and the manager is used by xtext to create the index entries. see e.g. org.eclipse.xtext.builder.clustering.ClusteringBuilderState.writeNewResourceDescriptions(BuildData, IResourceDescriptions, CurrentDescriptions, IProgressMonitor)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Confusion about get resourceDescription from IReso [message #1777179 is a reply to message #1777178] Sat, 25 November 2017 17:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
and no there is no docs. these compontents go very deep into xtext internas

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Confusion about get resourceDescription from IReso [message #1777180 is a reply to message #1777177] Sat, 25 November 2017 17:43 Go to previous messageGo to next message
serio adamo is currently offline serio adamoFriend
Messages: 24
Registered: September 2017
Junior Member
Christian Dietrich wrote on Sat, 25 November 2017 17:34

the NamesAreUniqueValidationHelper is not designed to work on more than one file


Yes, so I write my own validator. I only reuse createDuplicateNameError method in NamesAreUniqueValidationHelper. (as util function)
Re: Confusion about get resourceDescription from IReso [message #1777181 is a reply to message #1777180] Sat, 25 November 2017 17:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes but: the vaidtor checks in the objects you pass are from the curret resource.
but they are not for entries in the index. they even might be proxies.
so you should use the index entries only to find out which are duplicates and which are not

if you call the manager it will simply wrap the current resource this is why its working.

if you are standing on a street you can walk to the houses you see on a map in your google glasses,
but you cant if you use the same map on a browser at home


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 25 November 2017 17:50]

Report message to a moderator

Re: Confusion about get resourceDescription from IReso [message #1777182 is a reply to message #1777179] Sat, 25 November 2017 18:06 Go to previous messageGo to next message
serio adamo is currently offline serio adamoFriend
Messages: 24
Registered: September 2017
Junior Member
Christian Dietrich wrote on Sat, 25 November 2017 17:42
and 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 18:08]

Report message to a moderator

Re: Confusion about get resourceDescription from IReso [message #1777183 is a reply to message #1777182] Sat, 25 November 2017 18:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
if you install xtext e.g. from http://download.eclipse.org/modeling/tmf/xtext/updates/composite/releases/ you ususally get sources as well.
so open the classes, set a breakpoint,
and start your runtime application in debug mode.

and you can try https://github.com/eclipse/xtext/blob/master/CONTRIBUTING.md which describes how to do a developer setup


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Confusion about get resourceDescription from IReso [message #1777184 is a reply to message #1777183] Sat, 25 November 2017 18:24 Go to previous message
serio adamo is currently offline serio adamoFriend
Messages: 24
Registered: September 2017
Junior Member
Thanks again, Christian.
Previous Topic:Formatter inner block indentation
Next Topic:What the thread "owns: ClusteringBuilderState" do?
Goto Forum:
  


Current Time: Fri Apr 19 16:13:38 GMT 2024

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

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

Back to the top