Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Accessing the validator from the build participant
Accessing the validator from the build participant [message #896758] Thu, 19 July 2012 15:41 Go to next message
Veldema Missing name is currently offline Veldema Missing nameFriend
Messages: 4
Registered: June 2011
Location: Germany
Junior Member
Hi all,
in my project I have a builder and runner that can generate some more precise error
messages than that I generate from the validator itself.
How do I get these error messages to the validator so that these error messages are displayed correctly?
I can't call the generated XXXJavaValidator.error() method directly
as that causes a null pointer exception due to some thread-local object not
being set in the xtext validator classes (and the builder thread != validator thread).

So far I've stored these error messages in a global list as tuples (String, EObject).
In a validation method (@Check void checkBla()) I call the JavaValidator error/warning methods over the messages stored in the list.
This works fine, except that I need to trigger a revalidation by typing a space
to force a revalidate of the model so that the stored messages are picked up.

So my question is:
- can I send some object/message somewhere to force a revalidation?
- or alternatively, can I send the error/warning in some way other than
calling XXJavaValidator.error()/warning()?
Cheers,
Ronald.
Re: Accessing the validator from the build participant [message #896774 is a reply to message #896758] Thu, 19 July 2012 16:48 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
I am doing something similar in cloudsmith / geppetto @ github.
I perform the extra validation in the Linker.afterModeledLinked(...)
callback. You then have access to instances that can be used to issue
warnings and errors.

Here is the method from my specilized linker:
@Override
protected void afterModelLinked(EObject model, IDiagnosticConsumer
diagnosticsConsumer) {
IMessageAcceptor acceptor = new
DiagnosticConsumerBasedMessageAcceptor(diagnosticsConsumer);
documentationAssociator.linkDocumentation(model, acceptor);
resourceLinker.link(model, acceptor, false);
}

When you do this, and the validity of resources depend on the state of
other / external resources, you will naturally not get a
rebuild/revalidation performed automatically. For that to happen you
need to tell the xtext builder about those. (This is a greatly
simplified explanation of what happens).

In my implementation, the class
org.cloudsmith.geppetto.pp.dsl.linking.PPResourceLinker does this by
recording references to the things it uses (or fails to find and need to
try again if the element becomes available). Then (naturally), these
recorded "dependencies" are presented by the ResourceDescription for the
resource being validated.

My implementation sort of mimics how the default linking does things.

There were numerous things to tweak to get things working right.
If possible, try instead to create a model that uses the standard EMF
references and out of the box Xtext support. (though - If your external
context does not change, it may be enough to just do more validation in
the afterModelLinked callback. In any case that is a starting point).

- henrik

On 2012-19-07 17:41, Veldema Mising name wrote:
> Hi all,
> in my project I have a builder and runner that can generate some more
> precise error
> messages than that I generate from the validator itself.
> How do I get these error messages to the validator so that these error
> messages are displayed correctly?
> I can't call the generated XXXJavaValidator.error() method directly as
> that causes a null pointer exception due to some thread-local object not
> being set in the xtext validator classes (and the builder thread !=
> validator thread).
>
> So far I've stored these error messages in a global list as tuples
> (String, EObject).
> In a validation method (@Check void checkBla()) I call the JavaValidator
> error/warning methods over the messages stored in the list.
> This works fine, except that I need to trigger a revalidation by typing
> a space
> to force a revalidate of the model so that the stored messages are
> picked up.
>
> So my question is:
> - can I send some object/message somewhere to force a revalidation?
> - or alternatively, can I send the error/warning in some way other than
> calling XXJavaValidator.error()/warning()?
> Cheers,
> Ronald.
Re: Accessing the validator from the build participant [message #896918 is a reply to message #896774] Fri, 20 July 2012 12:37 Go to previous message
Veldema Missing name is currently offline Veldema Missing nameFriend
Messages: 4
Registered: June 2011
Location: Germany
Junior Member
Thanks, I'll give it a shot.
R.
Previous Topic:Auto-fold text regions
Next Topic:can't use any word same than a keyword in my custom Enum rule
Goto Forum:
  


Current Time: Fri Mar 29 00:24:22 GMT 2024

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

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

Back to the top