Search in sources :

Example 21 with IResourceValidator

use of org.eclipse.xtext.validation.IResourceValidator in project xtext-xtend by eclipse.

the class ActiveAnnotationsRuntimeTest method assertIssues.

public void assertIssues(final Pair<String, String> macroFile, final Pair<String, String> clientFile, final Procedure1<? super List<Issue>> expectations) {
    try {
        final XtextResourceSet resourceSet = this.compileMacroResourceSet(macroFile, clientFile);
        Resource _head = IterableExtensions.<Resource>head(resourceSet.getResources());
        final XtextResource singleResource = ((XtextResource) _head);
        boolean _isLoaded = singleResource.isLoaded();
        boolean _not = (!_isLoaded);
        if (_not) {
            singleResource.load(resourceSet.getLoadOptions());
        }
        final IResourceValidator validator = singleResource.getResourceServiceProvider().getResourceValidator();
        expectations.apply(validator.validate(singleResource, CheckMode.ALL, CancelIndicator.NullImpl));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 22 with IResourceValidator

use of org.eclipse.xtext.validation.IResourceValidator in project mechanoid by robotoworks.

the class Compiler method validate.

private List<Issue> validate() {
    List<Issue> issues = Lists.newArrayList();
    for (Resource resource : mResourceSet.getResources()) {
        IResourceServiceProvider resourceServiceProvider = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(resource.getURI());
        if (resourceServiceProvider != null) {
            IResourceValidator resourceValidator = resourceServiceProvider.getResourceValidator();
            List<Issue> result = resourceValidator.validate(resource, CheckMode.ALL, null);
            for (Issue issue : result) {
                if (!issue.getCode().equals(MechanoidIssueCodes.MISSING_MECHANOID_LIBS)) {
                    issues.add(issue);
                }
            }
        }
    }
    return issues;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) Issue(org.eclipse.xtext.validation.Issue) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 23 with IResourceValidator

use of org.eclipse.xtext.validation.IResourceValidator in project vorto by eclipse.

the class AbstractModelParser method parse.

@Override
public ModelInfo parse(InputStream is) {
    Injector injector = getInjector();
    XtextResourceSet resourceSet = workspace.getResourceSet();
    Resource resource = createResource(fileName, getContent(is), resourceSet).orElseThrow(() -> new ValidationException("Xtext is not able to create a resource for this model. Check if you are using the correct parser.", getModelInfoFromFilename()));
    if (resource.getContents().size() <= 0) {
        throw new ValidationException("Xtext is not able to create a model out of this file. Check if the file you are using is correct.", getModelInfoFromFilename());
    }
    Model model = (Model) resource.getContents().get(0);
    // always load direct references to make the model complete
    workspace.loadFromRepository(getReferences(model));
    if (this.isValidationEnabled) {
        /* Execute validators */
        IResourceValidator validator = injector.getInstance(IResourceValidator.class);
        List<Issue> issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
        if (issues.size() > 0) {
            List<ModelId> missingReferences = getMissingReferences(model, issues);
            if (missingReferences.size() > 0) {
                throw new CouldNotResolveReferenceException(getModelInfo(model).orElse(getModelInfoFromFilename()), missingReferences);
            } else {
                Set<ValidationIssue> validationIssues = convertIssues(issues);
                throw new ValidationException(collate(validationIssues), validationIssues, getModelInfo(model).orElse(getModelInfoFromFilename()));
            }
        }
        if (!resource.getErrors().isEmpty()) {
            throw new ValidationException(resource.getErrors().get(0).getMessage(), getModelInfo(model).orElse(getModelInfoFromFilename()));
        }
    }
    return new ModelResource((Model) resource.getContents().get(0));
}
Also used : ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) Issue(org.eclipse.xtext.validation.Issue) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) CouldNotResolveReferenceException(org.eclipse.vorto.repository.core.impl.validation.CouldNotResolveReferenceException) ModelResource(org.eclipse.vorto.repository.core.ModelResource) Resource(org.eclipse.emf.ecore.resource.Resource) ModelResource(org.eclipse.vorto.repository.core.ModelResource) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Model(org.eclipse.vorto.core.api.model.model.Model) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

IResourceValidator (org.eclipse.xtext.validation.IResourceValidator)23 Issue (org.eclipse.xtext.validation.Issue)18 XtextResource (org.eclipse.xtext.resource.XtextResource)16 Test (org.junit.Test)14 Resource (org.eclipse.emf.ecore.resource.Resource)7 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 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)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 Injector (com.google.inject.Injector)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 N4JSResource (org.eclipse.n4js.resource.N4JSResource)1 Model (org.eclipse.vorto.core.api.model.model.Model)1