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);
}
}
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;
}
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));
}
Aggregations