use of org.eclipse.xtext.validation.IResourceValidator in project dsl-devkit by dsldevkit.
the class ValidMarkerUpdateJob method run.
/**
* {@inheritDoc}
*/
@Override
protected IStatus run(final IProgressMonitor monitor) {
final IResourceValidator resourceValidator = resourceServiceProvider.getResourceValidator();
// Object the list of resources
final List<URI> uris = getResourceDescriptionURIs();
// Let's start (number of task = number of resource * 2 (loading + validating))
// $NON-NLS-1$
monitor.beginTask("", uris.size() * 2);
for (final URI uri : uris) {
// Last chance to cancel before next validation
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
// Get the file; only local files will be re-validated, derived files are ignored
final IFile iFile = getFileFromStorageMapper(uri);
if (iFile != null && !iFile.isDerived(IFile.CHECK_ANCESTORS)) {
// $NON-NLS-1$
monitor.subTask("loading " + iFile.getName());
// Load the corresponding resource
boolean loaded = false;
Resource eResource = null;
try {
eResource = resourceSet.getResource(uri, false);
if ((eResource == null) || (eResource != null && !eResource.isLoaded())) {
// if the resource does not exist in the resource set, or is not loaded yet
// load it.
eResource = resourceSet.getResource(uri, true);
loaded = true;
}
monitor.worked(1);
// CHECKSTYLE:OFF
} catch (final RuntimeException e) {
// CHECKSTYLE:ON
// $NON-NLS-1$
LOGGER.error(MessageFormat.format("{0} could not be validated.", iFile.getName()), e);
} finally {
if (eResource != null) {
validate(resourceValidator, iFile, eResource, monitor);
if (loaded) {
// NOPMD
// unload any resource that was previously loaded as part of this loop.
eResource.unload();
}
}
}
}
}
monitor.done();
return Status.OK_STATUS;
}
use of org.eclipse.xtext.validation.IResourceValidator in project xtext-xtend by eclipse.
the class LinkingTest method testBug345433_01.
@Test
public void testBug345433_01() throws Exception {
String classAsString = "import static extension org.eclipse.xtext.GrammarUtil.*\n" + "class Foo {" + " org.eclipse.xtext.Grammar grammar\n" + " def function1() {\n" + " grammar.containedRuleCalls.filter(e | " + " !e.isAssigned() && !e.isEObjectRuleCall()" + " ).map(e | e.rule)\n" + " }\n" + " def function2() {\n" + " newArrayList(function1().head())\n" + " }\n" + "}";
XtendClass clazz = clazz(classAsString);
IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator();
List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
XtendFunction function1 = (XtendFunction) clazz.getMembers().get(1);
JvmOperation operation1 = associator.getDirectlyInferredOperation(function1);
assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", operation1.getReturnType().getIdentifier());
XtendFunction function2 = (XtendFunction) clazz.getMembers().get(2);
JvmOperation operation2 = associator.getDirectlyInferredOperation(function2);
assertEquals("java.util.ArrayList<org.eclipse.xtext.AbstractRule>", operation2.getReturnType().getIdentifier());
}
use of org.eclipse.xtext.validation.IResourceValidator in project snow-owl by b2ihealthcare.
the class SnomedEclLabelerRequestTest method setup.
@Before
public void setup() {
final IParser parser = ECL_INJECTOR.getInstance(IParser.class);
final IResourceValidator resourceValidator = ECL_INJECTOR.getInstance(IResourceValidator.class);
final ISerializer serializer = ECL_INJECTOR.getInstance(ISerializer.class);
Builder contextBuilder = TestBranchContext.on(MAIN).with(EclParser.class, new DefaultEclParser(parser, resourceValidator)).with(EclSerializer.class, new DefaultEclSerializer(serializer)).with(Index.class, rawIndex()).with(RevisionIndex.class, index()).with(ObjectMapper.class, getMapper());
CodeSystemResource.configureCodeSystem(contextBuilder);
context = contextBuilder.build();
}
use of org.eclipse.xtext.validation.IResourceValidator in project xtext-core by eclipse.
the class XtextValidationTest method testOutOfSequenceArgument_01.
@Test
public void testOutOfSequenceArgument_01() throws Exception {
XtextResource resource = getResourceFromString("grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "Model: rule=Rule<true, C=false, B=true>;\n" + "Rule<A, B, C>: name=ID;");
IResourceValidator validator = get(IResourceValidator.class);
List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
assertEquals(issues.toString(), 2, issues.size());
assertEquals("Out of sequence named argument. Expected value for B", issues.get(0).getMessage());
assertEquals("Out of sequence named argument. Expected value for C", issues.get(1).getMessage());
}
use of org.eclipse.xtext.validation.IResourceValidator in project xtext-core by eclipse.
the class XtextValidationTest method testMissingArgument2.
@Test
public void testMissingArgument2() throws Exception {
XtextResource resource = getResourceFromString("grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "Model: rule=Rule<First=true>;\n" + "Rule<First, Missing, AlsoMissing>: name=ID;");
IResourceValidator validator = get(IResourceValidator.class);
List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
assertEquals(issues.toString(), 1, issues.size());
assertEquals("2 missing arguments for the following parameters: Missing, AlsoMissing", issues.get(0).getMessage());
}
Aggregations