Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Storing list of eobjects before calling xtext validations
Storing list of eobjects before calling xtext validations [message #1851452] Wed, 06 April 2022 08:08 Go to next message
Yusuf A is currently offline Yusuf AFriend
Messages: 9
Registered: April 2022
Junior Member
Dear all,
I am very new to xtext. I am working on a xtext project that has so many validations and number of resources (DSLs) is also large.

I have a rule in my grammar called "BlocksRequirement". This can be defined in any DSL of a project. Let's consider I have 10 resources (DSLs) in my project and in 5 of these resources, I have "BlocksRequirement" defined.

This list of "BlocksRequirement" will be used by many validations. So I want to read all the "BlocksRequirement" from all the resources before any validation check is called to avoid reading resources again and again for every validation.

Could you please help me to solve it?


Thanks in advance.
Re: Storing list of eobjects before calling xtext validations [message #1851473 is a reply to message #1851452] Wed, 06 April 2022 11:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
maybe you can add an adapter to the resourceset you manage yourself (e.g. on first access - trick might be invalidation for open editors)
or you cache on per resource via IResourceScopeCache class.
maybe you can also work with the list in a cheaper way without having an actual list (depends what your actual usecase is - see e.g. UniqueClassNameValidator


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

[Updated on: Wed, 06 April 2022 11:38]

Report message to a moderator

Re: Storing list of eobjects before calling xtext validations [message #1851485 is a reply to message #1851473] Wed, 06 April 2022 12:48 Go to previous messageGo to next message
Rubén Porras Campo is currently offline Rubén Porras CampoFriend
Messages: 67
Registered: July 2009
Member
Hi Yusuf,

we use the adapter in the resource set, as suggested by Christian. Our adapter uses com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/IResourceSetCache.java

you can find in the same source code that we use the adapter to cache scoping results.

We have then subclassed org.eclipse.xtext.resource.XtextResourceSet to add one of such adapters to the resource set when it is created (see class ScopeCacheAdapter and CacheConfiguration in same code base).

Something like
public class CustomXtextResourceSet extends XtextResourceSet {
public CustomXtextResourceSet() {
eAdapters().add(new ScopeCacheAdapter(new CacheConfiguration().useSoftValues()));
}
...

To solve the invalidation for open editor, we have disabled the adapter for those editors, but I do not remember now the details of how we did that.

Regards
Re: Storing list of eobjects before calling xtext validations [message #1851488 is a reply to message #1851485] Wed, 06 April 2022 13:32 Go to previous messageGo to next message
Yusuf A is currently offline Yusuf AFriend
Messages: 9
Registered: April 2022
Junior Member
Hi Christian,
thanks for the response.
I had a look at https://www.tabnine.com/web/assistant/code/rs/5c6684151095a50001caffb2#L56 for UniqueClassNameValidator. I am sorry but I did not understand it.
My use case after I get a list of eobjects is not complecated. I would like to read all the resources, filter an Eobject "BlocksRequirement" and keep this ready for validations and use it as many times possible.
Could you kindly provide more help on this ?
Re: Storing list of eobjects before calling xtext validations [message #1851489 is a reply to message #1851488] Wed, 06 April 2022 13:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
the question is: what do you do with that in your validation?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Storing list of eobjects before calling xtext validations [message #1851492 is a reply to message #1851489] Wed, 06 April 2022 14:37 Go to previous messageGo to next message
Yusuf A is currently offline Yusuf AFriend
Messages: 9
Registered: April 2022
Junior Member
Let's I am writing a check method for <Requirement>, So when I already have this list<BlocksRequirement> in my validator, I try to find a suitable entry from this list in validation method based on some comparisons. Depending on the results of these comparison I put an error or ignore it.

I currently do like below:

.. List<BlocksRequirement> getAllBlocksReqs(){
        List<BlocksRequirement> reqs= new ArrayList<>(EObject object);
        Resource eResource = object.eContainer().eResource();
        IResourceDescriptions index = resourceDescriptionsProvider.getResourceDescriptions(eResource);
        IResourceDescription iResourceDescription = index.getResourceDescription(eResource.getURI());

        List<IContainer> visibleContainers = containerManager.getVisibleContainers(iResourceDescription, index);
        
        ...iterate over visibleContainers to filter the result and return list.

}


but at the moment I call this method multiple times in my validations. So I was looking for a way to read it once and somehow keep it ready before validations are called. I do not know how to do that.
Re: Storing list of eobjects before calling xtext validations [message #1851495 is a reply to message #1851492] Wed, 06 April 2022 15:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you store the information in the userdata
and query index once
per file by putting validation on model root?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Storing list of eobjects before calling xtext validations [message #1851497 is a reply to message #1851495] Wed, 06 April 2022 15:59 Go to previous messageGo to next message
Yusuf A is currently offline Yusuf AFriend
Messages: 9
Registered: April 2022
Junior Member
No, putting validation on model root is not an option for me since there are so many checks already done and I started working on xtext recently.
Re: Storing list of eobjects before calling xtext validations [message #1851505 is a reply to message #1851497] Thu, 07 April 2022 03:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
then you should digg into adapter to resource or resourceset

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Storing list of eobjects before calling xtext validations [message #1851510 is a reply to message #1851505] Thu, 07 April 2022 07:49 Go to previous messageGo to next message
Yusuf A is currently offline Yusuf AFriend
Messages: 9
Registered: April 2022
Junior Member
Could you provide some more info on how to do it or may be some example that can help? I did not get much of help when I browsed.
Re: Storing list of eobjects before calling xtext validations [message #1851519 is a reply to message #1851510] Thu, 07 April 2022 10:12 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
no i dont. just check the link ruben have and the uses of IResourceScopeCache in xtext codebase or byy search on github or in the forum

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

[Updated on: Thu, 07 April 2022 10:12]

Report message to a moderator

Previous Topic:Using Quickfixes and a LanguageServer
Next Topic:Same keywords xtext formatter
Goto Forum:
  


Current Time: Thu Apr 25 12:54:43 GMT 2024

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

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

Back to the top