use of org.eclipse.vorto.repository.core.impl.validation.CouldNotResolveReferenceException 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