|Re: Accessing the validator from the build participant [message #896774 is a reply to message #896758]
||Thu, 19 July 2012 16:48
| Henrik Lindberg
Registered: July 2009
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:
protected void afterModelLinked(EObject model, IDiagnosticConsumer
IMessageAcceptor acceptor = new
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).
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()?
Powered by FUDForum
. Page generated in 0.03299 seconds