Search in sources :

Example 1 with IResourceValidator

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI)

Example 2 with IResourceValidator

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());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) Issue(org.eclipse.xtext.validation.Issue) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) Test(org.junit.Test)

Example 3 with IResourceValidator

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();
}
Also used : IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) RevisionIndex(com.b2international.index.revision.RevisionIndex) Builder(com.b2international.snowowl.test.commons.snomed.TestBranchContext.Builder) IParser(org.eclipse.xtext.parser.IParser) ISerializer(org.eclipse.xtext.serializer.ISerializer) Before(org.junit.Before)

Example 4 with IResourceValidator

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());
}
Also used : Issue(org.eclipse.xtext.validation.Issue) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 5 with IResourceValidator

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());
}
Also used : Issue(org.eclipse.xtext.validation.Issue) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

IResourceValidator (org.eclipse.xtext.validation.IResourceValidator)22 Issue (org.eclipse.xtext.validation.Issue)17 XtextResource (org.eclipse.xtext.resource.XtextResource)16 Test (org.junit.Test)14 Resource (org.eclipse.emf.ecore.resource.Resource)6 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)4 IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 URI (org.eclipse.emf.common.util.URI)2 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)2 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)2 MarkerCreator (org.eclipse.xtext.ui.editor.validation.MarkerCreator)2 RevisionIndex (com.b2international.index.revision.RevisionIndex)1 Builder (com.b2international.snowowl.test.commons.snomed.TestBranchContext.Builder)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 N4JSResource (org.eclipse.n4js.resource.N4JSResource)1 AbstractRule (org.eclipse.xtext.AbstractRule)1 Assignment (org.eclipse.xtext.Assignment)1 Grammar (org.eclipse.xtext.Grammar)1