Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Initialization in Xtext Validation(Initialization in Xtext Validation)
icon5.gif  Initialization in Xtext Validation [message #1662866] Tue, 10 March 2015 06:49 Go to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi all,
I have a validation class. My all validation warnings/ error markers use some common data.

So I want to prepare some common data before even a single validation check is triggered.

Is there something already available to initialize data before checks are invoked ?


Thanks for any help Smile


Arshad
Re: Initialization in Xtext Validation [message #1662876 is a reply to message #1662866] Tue, 10 March 2015 06:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

is the common data context free or not (depends on model)?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Initialization in Xtext Validation [message #1663016 is a reply to message #1662876] Tue, 10 March 2015 08:17 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi Christian,
Thanks for the reply.
Yes its context free data. It does not depend on the model.

Regards,
Arshad


Arshad
Re: Initialization in Xtext Validation [message #1663066 is a reply to message #1663016] Tue, 10 March 2015 08:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you could do this eg. in the register method of the validator then

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Initialization in Xtext Validation [message #1663128 is a reply to message #1663066] Tue, 10 March 2015 09:24 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi,

Thanks Christian..

Can't I write a static block for the validation class ?

Will it have problems ?


Regards,
Arshad


Arshad
Re: Initialization in Xtext Validation [message #1663145 is a reply to message #1663128] Tue, 10 March 2015 09:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i dont know

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Initialization in Xtext Validation [message #1679122 is a reply to message #1663145] Mon, 16 March 2015 13:32 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Let me chime in here:
In some validators I do some caching which is valid for the duration of validating one resource.
I would be interested in hooks for (initializing and) clearing that cache.
I.e., more importantly than initialization (which I can do on-demand), I'd need a hook that is triggered when validation for a particular resource is done.
It seems I would need to override one of the final validate or internalValidate methods :-/

Stephan
Re: Initialization in Xtext Validation [message #1679123 is a reply to message #1679122] Mon, 16 March 2015 13:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

have a look at org.eclipse.xtext.validation.AbstractDeclarativeValidator.getContext() maybe it can be used as cache storage


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

[Updated on: Mon, 16 March 2015 13:37]

Report message to a moderator

Re: Initialization in Xtext Validation [message #1679214 is a reply to message #1679123] Mon, 16 March 2015 14:20 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Quote:
have a look at org.eclipse.xtext.validation.AbstractDeclarativeValidator.getContext() maybe it can be used as cache storage


Thanks.
Can you say what is the lifecycle of that map? Is it ever cleared?
Re: Initialization in Xtext Validation [message #1679224 is a reply to message #1679214] Mon, 16 March 2015 14:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

afaik it is per resource


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Initialization in Xtext Validation [message #1679243 is a reply to message #1679224] Mon, 16 March 2015 14:32 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Quote:
afaik it is per resource


sounds good, thanks.
Re: Initialization in Xtext Validation [message #1679274 is a reply to message #1679243] Mon, 16 March 2015 14:47 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
To close the loop: the following method defines the lifecycle of that context map:
org.eclipse.emf.ecore.util.Diagnostician.validate(EObject, Map<?, ?>)

So if no-one leaks the reference to the map it should be subject to GC after that method terminates.
And indeed this validate method is invoked for the main element of each resource.
While it does not provide a hook for cleanup it should implicitly free the memory.

thanks again.
Previous Topic:Xtext grammar : mismatched input '0' expecting RULE_INT
Next Topic:Warning for unused declarations
Goto Forum:
  


Current Time: Fri Apr 19 03:15:58 GMT 2024

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

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

Back to the top