@Override public void reportError(Resource file, String message, String errorCode, Severity severity, String markerType) { EList<Diagnostic> errors = file.getErrors(); errors.add(new EObjectDiagnosticImpl(Severity.ERROR, markerType, message, null, null, -1, null)); }
protected Resource getResource(String input, IResourceFactory resourceFactory) throws IOException { InputStream inputStream = new ByteArrayInputStream(input.getBytes(INTERNAL_ENCODING)); try { Resource resource = resourceFactory.createResource(URI.createURI("dummy.simpleexpressions")); resource.load(inputStream, Collections.singletonMap(XtextResource.OPTION_ENCODING, INTERNAL_ENCODING)); if (!resource.getErrors().isEmpty()) { throw new RuntimeException(input + " - " + resource.getErrors().toString()); } inputStream.close(); return resource; } finally { inputStream.close(); } }
/** * Added error indication to import declaration URI * * @param resource * zen model * @param importDeclaration * import declaration statement * @param message * error message */ private void addError(Resource resource, EObject importDeclaration, String message) { resource.getErrors().add(new EObjectDiagnosticImpl(Severity.ERROR, "", //$NON-NLS-1$ message, importDeclaration, RapidmlPackage.Literals.IMPORT_DECLARATION__IMPORT_URI, -1, null)); } }
public ZenModel loadAndValidateModel(URI modelUri) { Resource resource = getResource(modelUri); if (validator != null) { List<Issue> issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl); if (!issues.isEmpty()) { throw new RuntimeException(String.format(errorMessage, issues.get(0).getMessage())); } } else if (!resource.getErrors().isEmpty()) { throw new RuntimeException(String.format(errorMessage, resource.getErrors().get(0).getMessage())); } return (ZenModel) resource.getContents().get(0); }
@Override public void clearMarkers(Resource resource, final String markerType) { if (resource != null) { EList<Diagnostic> errors = resource.getErrors(); errors.removeIf(input -> input instanceof EObjectDiagnosticImpl && markerType.contentEquals(((EObjectDiagnosticImpl)input).getCode())); } }
@Override public void reportError(EObject ctx, String message, String errorCode, Severity severity, String markerType) { Resource resource = ctx.eResource(); if (resource != null) { EList<Diagnostic> errors = resource.getErrors(); errors.add(new EObjectDiagnosticImpl(Severity.ERROR, markerType, message, ctx, null, -1, null)); } }
public void generate() { ModelLoader modelLoader = prepareGeneratorEnvironment(); for (Resource resource : modelLoader.getResources()) { if (resource.getErrors().size() > 0) { StringBuilder errorMsg = new StringBuilder(); errorMsg.append("Error loading model " + resource.getURI().toString() + ". The following errors occured: \n"); for (Diagnostic error : resource.getErrors()) { errorMsg.append(error.getMessage()); } logger.log(Level.SEVERE, errorMsg.toString()); System.exit(-1); } else { generator.doGenerate(resource, outputFileSystem); } } }
@Override public void reportErrorNoLocation(EObject ctx, String message, String errorCode, Severity severity, String markerType) { Resource resource = ctx.eResource(); if (resource != null) { EList<Diagnostic> errors = resource.getErrors(); errors.add(new EObjectDiagnosticImpl(Severity.ERROR, markerType, message, resource.getContents().get(0), null, -1, null)); } }
private void handleUnknownProperty(JsonParser jp, Resource resource, DeserializationContext ctxt) throws IOException { if (resource != null && ctxt.getConfig().hasDeserializationFeatures(FAIL_ON_UNKNOWN_PROPERTIES.getMask())) { resource.getErrors().add(new JSONException("Unknown feature " + jp.getCurrentName(), jp.getCurrentLocation())); } // we didn't find a feature so consume // the field and move on jp.nextToken(); jp.skipChildren(); }
private void handleUnknownProperty(JsonParser jp, Resource resource, DeserializationContext ctxt) throws IOException { if (resource != null && ctxt.getConfig().hasDeserializationFeatures(FAIL_ON_UNKNOWN_PROPERTIES.getMask())) { resource.getErrors().add(new JSONException("Unknown feature " + jp.getCurrentName(), jp.getCurrentLocation())); } // we didn't find a feature so consume // the field and move on jp.nextToken(); jp.skipChildren(); }
public Object evaluate(final XExpression expression, final JvmTypeReference expectedType) { try { final Object result = this.interpreter.evaluate(expression, expectedType); return this.translate(result); } catch (final Throwable _t) { if (_t instanceof ConstantExpressionEvaluationException) { final ConstantExpressionEvaluationException e = (ConstantExpressionEvaluationException)_t; String _message = e.getMessage(); final EObjectDiagnosticImpl error = new EObjectDiagnosticImpl(Severity.ERROR, "constant_expression_evaluation_problem", _message, expression, null, (-1), null); expression.eResource().getErrors().add(error); return null; } else { throw Exceptions.sneakyThrow(_t); } } }
/** * @param model * model * @return list of resource definitions that imported using import RESTfulInterfaces */ static List<ResourceDefinition> getImportedResources(ZenModel model) { ArrayList<ResourceDefinition> result = new ArrayList<>(); for (ImportDeclaration importDecl : model.getImports()) { String uri = importDecl.getImportURI(); if (!Strings.isNullOrEmpty(uri)) { Resource modelResource = importDecl.eResource(); Resource resource = getResource(modelResource, uri); if (resource != null && resource.getErrors().isEmpty() && !resource.getContents().isEmpty()) { ZenModel zenModel = (ZenModel) resource.getContents().get(0); String namespace = Strings.isNullOrEmpty(zenModel.getNamespace()) ? zenModel.getName() : zenModel .getNamespace() + "." + zenModel.getName(); //$NON-NLS-1$ for (ResourceAPI resourceAPI : zenModel.getResourceAPIs()) { String ifaceFQN = namespace + "." + resourceAPI.getName(); //$NON-NLS-1$ if (ifaceFQN.equals(importDecl.getImportedNamespace())) { result.addAll(resourceAPI.getOwnedResourceDefinitions()); } } } } } return result; }
@Override public void addError(final Element element, final String message) { this.checkCanceled(); this.checkValidationAllowed(); final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element); EList<Resource.Diagnostic> _errors = resAndObj.getKey().getErrors(); EObject _value = resAndObj.getValue(); EStructuralFeature _significantFeature = this.getSignificantFeature(resAndObj.getValue()); EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, "user.issue", message, _value, _significantFeature, (-1), null); _errors.add(_eObjectDiagnosticImpl); }
private XExpression parseScriptIntoXTextEObject(String scriptAsString) throws ScriptParsingException { XtextResourceSet resourceSet = getResourceSet(); Resource resource = resourceSet.createResource(computeUnusedUri(resourceSet)); // IS-A XtextResource try { resource.load(new StringInputStream(scriptAsString, StandardCharsets.UTF_8.name()), resourceSet.getLoadOptions()); } catch (IOException e) { throw new ScriptParsingException( "Unexpected IOException; from close() of a String-based ByteArrayInputStream, no real I/O; how is that possible???", scriptAsString, e); } List<Diagnostic> errors = resource.getErrors(); if (errors.size() != 0) { throw new ScriptParsingException("Failed to parse expression (due to managed SyntaxError/s)", scriptAsString).addDiagnosticErrors(errors); } EList<EObject> contents = resource.getContents(); if (!contents.isEmpty()) { Iterable<Issue> validationErrors = getValidationErrors(contents.get(0)); if (!validationErrors.iterator().hasNext()) { return (XExpression) contents.get(0); } else { throw new ScriptParsingException("Failed to parse expression (due to managed ValidationError/s)", scriptAsString).addValidationIssues(validationErrors); } } else { return null; } }
@Override public List<? extends Problem> getProblems(final Element element) { this.checkCanceled(); final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element); final Resource resource = resAndObj.getKey(); EList<Resource.Diagnostic> _errors = resource.getErrors(); EList<Resource.Diagnostic> _warnings = resource.getWarnings(); final Iterable<EObjectDiagnosticImpl> issues = Iterables.<EObjectDiagnosticImpl>filter(Iterables.<Resource.Diagnostic>concat(_errors, _warnings), EObjectDiagnosticImpl.class); final Function1<EObjectDiagnosticImpl, Boolean> _function = (EObjectDiagnosticImpl diag) -> { EObject _problematicObject = diag.getProblematicObject(); EObject _value = resAndObj.getValue(); return Boolean.valueOf(Objects.equal(_problematicObject, _value)); }; final Function1<EObjectDiagnosticImpl, Problem> _function_1 = (EObjectDiagnosticImpl diag) -> { String _code = diag.getCode(); String _message = diag.getMessage(); Problem.Severity _translateSeverity = this.translateSeverity(diag.getSeverity()); ProblemImpl _problemImpl = new ProblemImpl(_code, _message, _translateSeverity); return ((Problem) _problemImpl); }; final Iterable<Problem> result = IterableExtensions.<EObjectDiagnosticImpl, Problem>map(IterableExtensions.<EObjectDiagnosticImpl>filter(issues, _function), _function_1); return IterableExtensions.<Problem>toList(result); }
public PatternSetValidationDiagnostics validate(Resource resource) { BasicDiagnostic chain = new BasicDiagnostic(); PatternSetValidationDiagnostics collectedIssues = new PatternSetValidationDiagnostics(); for (Diagnostic diag : resource.getErrors()) { if (diag instanceof AbstractDiagnostic) { AbstractDiagnostic abstractDiagnostic = (AbstractDiagnostic) diag; converter.convertResourceDiagnostic(abstractDiagnostic, Severity.ERROR, collectedIssues); } } for (EObject obj : resource.getContents()) { diagnostician.validate(obj, chain); } for (org.eclipse.emf.common.util.Diagnostic diag : chain.getChildren()) { converter.convertValidatorDiagnostic(diag, collectedIssues); } return collectedIssues; }
public void assertSerializeWithoutNodeModel(EObject semanticObject) { try { EObject parsed; if (semanticObject.eResource().getContents().contains(semanticObject)) { List<Pair<EObject, ICompositeNode>> nodes = detachNodeModel(semanticObject); String serialized = serializeWithoutNodeModel(semanticObject); parsed = parseHelper.parse(serialized, semanticObject.eResource().getResourceSet()); reattachNodes(nodes); } else { INode oldNode = NodeModelUtils.getNode(semanticObject); String oldtext = oldNode.getRootNode().getText(); String oldURI = semanticObject.eResource().getURIFragment(semanticObject); List<Pair<EObject, ICompositeNode>> nodes = detachNodeModel(semanticObject); String serialized = serializeWithoutNodeModel(semanticObject); String newtext = oldtext.substring(0, oldNode.getOffset()) + serialized + oldtext.substring(oldNode.getOffset() + oldNode.getLength()); EObject newmodel = parseHelper.parse(newtext, semanticObject.eResource().getResourceSet()); parsed = newmodel.eResource().getEObject(oldURI); reattachNodes(nodes); } EcoreUtil.resolveAll(parsed); Assert.assertTrue(parsed.eResource().getErrors().toString(), parsed.eResource().getErrors().isEmpty()); assertEqualWithEmfFormatter(semanticObject, parsed); } catch (Exception e) { throw new RuntimeException(e); } }
public void assertSerializeWithoutNodeModel(EObject semanticObject) { try { EObject parsed; if (semanticObject.eResource().getContents().contains(semanticObject)) { List<Pair<EObject, ICompositeNode>> nodes = detachNodeModel(semanticObject); String serialized = serializeWithoutNodeModel(semanticObject); parsed = parseHelper.parse(serialized, semanticObject.eResource().getResourceSet()); reattachNodes(nodes); } else { INode oldNode = NodeModelUtils.getNode(semanticObject); String oldtext = oldNode.getRootNode().getText(); String oldURI = semanticObject.eResource().getURIFragment(semanticObject); List<Pair<EObject, ICompositeNode>> nodes = detachNodeModel(semanticObject); String serialized = serializeWithoutNodeModel(semanticObject); String newtext = oldtext.substring(0, oldNode.getOffset()) + serialized + oldtext.substring(oldNode.getOffset() + oldNode.getLength()); EObject newmodel = parseHelper.parse(newtext, semanticObject.eResource().getResourceSet()); parsed = newmodel.eResource().getEObject(oldURI); reattachNodes(nodes); } EcoreUtil.resolveAll(parsed); Assert.assertTrue(parsed.eResource().getErrors().toString(), parsed.eResource().getErrors().isEmpty()); parsed.eResource().getResourceSet().getResources().remove(parsed.eResource()); assertEqualWithEmfFormatter(semanticObject, parsed); } catch (Exception e) { throw new RuntimeException(e); } }
public void assertSerializeWithoutNodeModel(EObject semanticObject) { try { EObject parsed; if (semanticObject.eResource().getContents().contains(semanticObject)) { List<Pair<EObject, ICompositeNode>> nodes = detachNodeModel(semanticObject); String serialized = serializeWithoutNodeModel(semanticObject); parsed = parseHelper.parse(serialized, semanticObject.eResource().getResourceSet()); reattachNodes(nodes); } else { INode oldNode = NodeModelUtils.getNode(semanticObject); String oldtext = oldNode.getRootNode().getText(); String oldURI = semanticObject.eResource().getURIFragment(semanticObject); List<Pair<EObject, ICompositeNode>> nodes = detachNodeModel(semanticObject); String serialized = serializeWithoutNodeModel(semanticObject); ITextRegion oldRegion = oldNode.getTextRegion(); String newtext = oldtext.substring(0, oldRegion.getOffset()) + serialized + oldtext.substring(oldRegion.getOffset() + oldRegion.getLength()); EObject newmodel = parseHelper.parse(newtext, semanticObject.eResource().getResourceSet()); parsed = newmodel.eResource().getEObject(oldURI); reattachNodes(nodes); } EcoreUtil.resolveAll(parsed); Assert.assertTrue(parsed.eResource().getErrors().toString(), parsed.eResource().getErrors().isEmpty()); parsed.eResource().getResourceSet().getResources().remove(parsed.eResource()); assertEqualWithEmfFormatter(semanticObject, parsed); } catch (Exception e) { throw new RuntimeException(e); } }
final DomainModel result = this.parseHelper.parse(_builder); Assert.assertNotNull(result); Assert.assertTrue(result.eResource().getErrors().isEmpty()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e);