Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Testing the validator, programmatically
Testing the validator, programmatically [message #633042] Fri, 15 October 2010 08:06 Go to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
In chapter 5. Runtime Concepts, section Test Validators of the users guide, methods for testing the validator are described. Unfortunately, only method for building a model manually is described, but not how to use the "can ...use EMF's ResourceSet to load models from your hard disk" method.

Does someone have some example (code) for me how to do that?

Thanks!
Re: Testing the validator, programmatically [message #633064 is a reply to message #633042] Fri, 15 October 2010 08:20 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
You can call the validation like this:

XtextResource res = (XtextResource) myResource;
List<Issue> issues = res.getResourceServiceProvider()
.getResourceValidator()
.validate(res,
CheckMode.ALL,
CancelIndicator.NullImpl);

Sven


Am 10/15/10 10:06 AM, schrieb Bodo:
> In chapter 5. Runtime Concepts, section Test Validators of the users
> guide, methods for testing the validator are described. Unfortunately,
> only method for building a model manually is described, but not how to
> use the "can ...use EMF's ResourceSet to load models from your hard
> disk" method.
> Does someone have some example (code) for me how to do that?
>
> Thanks!
>


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: Testing the validator, programmatically [message #633509 is a reply to message #633064] Mon, 18 October 2010 09:42 Go to previous messageGo to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
Hello Sven,

I just tried to insert this code schnipsel, but in vain. 1st I got an error message with "CancelIndicator.NullImpl" I can't resolve. Either import from "org.eclipse.xtext.util" nor from "org.eclipse.xtext.validation" works!

BTW. where I have to place this code schnipsel? I added two classes under validation extending AbstractXtextTests and AbstractDeclarativeValidator as suggested by the user guide.

... and what is "myResource", is this just an input stream for the text of my DSL? A think, one have to convert the text file into something for getting a "myResource"?

Thanks ...

Bodo

Re: Testing the validator, programmatically [message #633800 is a reply to message #633509] Tue, 19 October 2010 13:35 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 10/18/10 11:42 AM, schrieb Bodo:
> Hello Sven,
>
> I just tried to insert this code schnipsel, but in vain. 1st I got an
> error message with "CancelIndicator.NullImpl" I can't resolve. Either
> import from "org.eclipse.xtext.util" nor from
> "org.eclipse.xtext.validation" works!

Sorry, I think it's "new CancelIndicator.NullImpl()"

>
> BTW. where I have to place this code schnipsel? I added two classes
> under validation extending AbstractXtextTests and
> AbstractDeclarativeValidator as suggested by the user guide.

In your unit test.
If you extend AbstractXtextTests, then you can obtain a Resource for
your model (string literal) like this:

XtextResource myResource = getResource(new
StringInputStream("my.dsl(expression)"));

Sven


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Previous Topic:Problem with stale line numbers
Next Topic:How to set k=1 in a mwe2 file
Goto Forum:
  


Current Time: Sat Sep 21 23:10:23 GMT 2024

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

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

Back to the top