|
Re: Standalone Testing Main function [message #1726414 is a reply to message #1726402] |
Sun, 13 March 2016 05:57 |
|
From the docs
You can use the IResourceValidator to validate a given resource programmatically. Example:
@Inject IResourceValidator resourceValidator
def void checkResource(Resource resource) {
val issues = resourceValidator.validate(resource,
CheckMode.ALL, CancelIndicator.NullImpl)
for (issue: issues) {
switch issue.severity {
case ERROR:
println("ERROR: " + issue.message)
case WARNING:
println("WARNING: " + issue.message)
}
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Standalone Testing Main function [message #1726648 is a reply to message #1726402] |
Tue, 15 March 2016 10:51 |
|
On 12/03/2016 21:48, joao antonio wrote:
> Good afternoon,
>
> I'm following an example from Lorenzo Bettini's book from chapter 7.
> The idea is to create a main function and to compile a program to check
> if some input file provides errors.
>
> Here is the code:
>
>
> public static void main(String[] args) {
> Injector injector = new
> org.example.entities.EntitiesStandaloneSetup().createInjectorAndDoEMFRegistration();
>
> XtextResourceSet resourceSet =
> injector.getInstance(XtextResourceSet.class);
> resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL,
> Boolean.TRUE);
> Resource resource =
> resourceSet.getResource(URI.createURI("a.entities"), true);
> System.out.println(resource.getErrors());
> //Model model = (Model) resource.getContents().get(0); //Trigger
> parsing and validation
> }
>
>
> The problem I get is that resource.getErrors() does not return any
> errors provided by my code in the validator, for example. As a fact, I
> only get errors from XtextLinkingDiagnostic, among other default(?)
> error providers.
>
> Thanks in advance.
>
>
Hi there
if you followed the book from the beginning, you may have a look at the
Main.java in the entities example to get an idea of how to trigger
validation in the standalone main:
IResourceValidator validator =
injector.getInstance(IResourceValidator.class);
// validate the resource
List<Issue> list = validator.validate(resource, CheckMode.ALL,
CancelIndicator.NullImpl);
if (!list.isEmpty()) {
for (Issue issue : list) {
System.err.println(issue);
}
return;
}
hope this helps
cheers
Lorenzo
--
Prof. Lorenzo Bettini, Computer Science, DISIA, Univ. Firenze
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Powered by
FUDForum. Page generated in 0.03680 seconds