Search in sources :

Example 1 with Severity

use of org.eclipse.xtext.diagnostics.Severity in project dsl-devkit by dsldevkit.

the class ModelValidator method logIssue.

/**
 * Log issue.
 *
 * @param resource
 *          the resource
 * @param issue
 *          the issue
 * @param logger
 *          the logger
 */
private void logIssue(final Resource resource, final Issue issue, final Logger logger) {
    final String message = NLS.bind(MESSAGE_TEMPLATE, new Object[] { resource.getURI().lastSegment(), issue.getLineNumber(), issue.getMessage() });
    final Severity severity = issue.getSeverity();
    switch(severity) {
        case ERROR:
            logger.error(message);
            break;
        case WARNING:
            logger.warn(message);
            break;
        case INFO:
            if (logger.isInfoEnabled()) {
                logger.info(message);
            }
            break;
        default:
            break;
    }
}
Also used : Severity(org.eclipse.xtext.diagnostics.Severity)

Example 2 with Severity

use of org.eclipse.xtext.diagnostics.Severity in project xtext-xtend by eclipse.

the class PartialParserTest method validateWithoutException.

protected void validateWithoutException(XtextResource resource) {
    ResourceValidatorImpl validator = resourceValidatorProvider.get();
    assertNotSame(validator, resource.getResourceServiceProvider().getResourceValidator());
    validator.setDiagnosticConverter(new IDiagnosticConverter() {

        @Override
        public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof BasicDiagnostic) {
                List<?> data = diagnostic.getData();
                if (!data.isEmpty() && data.get(0) instanceof Throwable) {
                    Throwable t = (Throwable) data.get(0);
                    // and AssertionError does not take a throwable as argument
                    throw new Error(t);
                }
                if (EObjectValidator.DIAGNOSTIC_SOURCE.equals(diagnostic.getSource()) && diagnostic.getCode() == EObjectValidator.EOBJECT__EVERY_REFERENCE_IS_CONTAINED) {
                    throw new Error(new RuntimeException("Dangling reference found."));
                }
            }
        }

        @Override
        public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof ExceptionDiagnostic) {
                Exception e = ((ExceptionDiagnostic) diagnostic).getException();
                // and AssertionError does not take a throwable as argument
                throw new Error(new RuntimeException(e));
            }
        }
    });
    validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
}
Also used : Issue(org.eclipse.xtext.validation.Issue) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) Severity(org.eclipse.xtext.diagnostics.Severity) IOException(java.io.IOException) ResourceValidatorImpl(org.eclipse.xtext.validation.ResourceValidatorImpl) IDiagnosticConverter(org.eclipse.xtext.validation.IDiagnosticConverter) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) List(java.util.List)

Example 3 with Severity

use of org.eclipse.xtext.diagnostics.Severity in project xtext-xtend by eclipse.

the class NoJRESmokeTester method checkNoErrorsInValidator.

protected void checkNoErrorsInValidator(final String model, XtextResource resource) {
    ResourceValidatorImpl validator = resourceValidatorProvider.get();
    Assert.assertNotSame(validator, resource.getResourceServiceProvider().getResourceValidator());
    validator.setDiagnosticConverter(new IDiagnosticConverter() {

        @Override
        public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof BasicDiagnostic) {
                List<?> data = diagnostic.getData();
                if (!data.isEmpty() && data.get(0) instanceof Throwable) {
                    Throwable t = (Throwable) data.get(0);
                    throwError(t);
                }
                if (EObjectValidator.DIAGNOSTIC_SOURCE.equals(diagnostic.getSource()) && diagnostic.getCode() == EObjectValidator.EOBJECT__EVERY_REFERENCE_IS_CONTAINED) {
                    throwError(new RuntimeException("Dangling reference found."));
                }
            }
        }

        private void throwError(Throwable e) {
            ComparisonFailure result = new ComparisonFailure(e.getMessage(), model, "");
            result.setStackTrace(e.getStackTrace());
            throw result;
        }

        @Override
        public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof ExceptionDiagnostic) {
                Exception e = ((ExceptionDiagnostic) diagnostic).getException();
                throwError(e);
            }
        }
    });
    validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
}
Also used : Issue(org.eclipse.xtext.validation.Issue) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) Severity(org.eclipse.xtext.diagnostics.Severity) ResourceValidatorImpl(org.eclipse.xtext.validation.ResourceValidatorImpl) IDiagnosticConverter(org.eclipse.xtext.validation.IDiagnosticConverter) ComparisonFailure(org.junit.ComparisonFailure) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) List(java.util.List)

Example 4 with Severity

use of org.eclipse.xtext.diagnostics.Severity in project xtext-eclipse by eclipse.

the class IssueUtil method createIssue.

/**
 * Creates an Issue out of a Marker.
 * setSyntaxError is unset since the current API does not allow fixing systax errors anyway.
 *
 * @param marker The marker to create an issue from
 * @return an issue created out of the given marker or <code>null</code>
 */
public Issue createIssue(IMarker marker) {
    Issue.IssueImpl issue = new Issue.IssueImpl();
    try {
        Map<String, Object> attributes = marker.getAttributes();
        String markerType = marker.getType();
        Object message = attributes.get(IMarker.MESSAGE);
        issue.setMessage(message instanceof String ? (String) message : null);
        Object lineNumber = attributes.get(IMarker.LINE_NUMBER);
        issue.setLineNumber(lineNumber instanceof Integer ? (Integer) lineNumber : null);
        Object column = attributes.get(Issue.COLUMN_KEY);
        issue.setColumn(column instanceof Integer ? (Integer) column : null);
        Object offset = attributes.get(IMarker.CHAR_START);
        Object endOffset = attributes.get(IMarker.CHAR_END);
        if (offset instanceof Integer && endOffset instanceof Integer) {
            issue.setOffset((Integer) offset);
            issue.setLength((Integer) endOffset - (Integer) offset);
        } else {
            issue.setOffset(-1);
            issue.setLength(0);
        }
        Object code = attributes.get(Issue.CODE_KEY);
        issue.setCode(code instanceof String ? (String) code : null);
        Object data = attributes.get(Issue.DATA_KEY);
        issue.setData(data instanceof String ? Strings.unpack((String) data) : null);
        Object uri = attributes.get(Issue.URI_KEY);
        issue.setUriToProblem(uri instanceof String ? URI.createURI((String) uri) : null);
        Object severity = attributes.get(IMarker.SEVERITY);
        Severity translatedSeverity = translateSeverity(severity instanceof Integer ? (Integer) severity : 0);
        if (translatedSeverity == null)
            throw new IllegalArgumentException(marker.toString());
        issue.setSeverity(translatedSeverity);
        if (markerTypeProvider != null)
            issue.setType(markerTypeProvider.getCheckType(markerType));
        else
            issue.setType(MarkerTypes.toCheckType(markerType));
    } catch (CoreException e) {
        return null;
    }
    return issue;
}
Also used : Issue(org.eclipse.xtext.validation.Issue) CoreException(org.eclipse.core.runtime.CoreException) Severity(org.eclipse.xtext.diagnostics.Severity)

Example 5 with Severity

use of org.eclipse.xtext.diagnostics.Severity in project xtext-eclipse by eclipse.

the class XtextEditorErrorTickUpdater method updateEditorImage.

protected void updateEditorImage(XtextEditor xtextEditor) {
    Severity severity = getSeverity(xtextEditor);
    if (severity != null && severity != Severity.INFO) {
        ImageDescriptor descriptor = severity == Severity.ERROR ? XtextPluginImages.DESC_OVR_ERROR : XtextPluginImages.DESC_OVR_WARNING;
        DecorationOverlayIcon decorationOverlayIcon = new DecorationOverlayIcon(defaultImage, descriptor, IDecoration.BOTTOM_LEFT);
        scheduleUpdateEditor(decorationOverlayIcon);
    } else {
        scheduleUpdateEditor(defaultImage);
    }
}
Also used : DecorationOverlayIcon(org.eclipse.jface.viewers.DecorationOverlayIcon) Severity(org.eclipse.xtext.diagnostics.Severity) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)

Aggregations

Severity (org.eclipse.xtext.diagnostics.Severity)19 Issue (org.eclipse.xtext.validation.Issue)7 List (java.util.List)5 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)5 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)5 ExceptionDiagnostic (org.eclipse.xtext.diagnostics.ExceptionDiagnostic)5 IDiagnosticConverter (org.eclipse.xtext.validation.IDiagnosticConverter)5 ResourceValidatorImpl (org.eclipse.xtext.validation.ResourceValidatorImpl)5 IOException (java.io.IOException)3 EObject (org.eclipse.emf.ecore.EObject)3 Check (org.eclipse.xtext.validation.Check)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)2 DecorationOverlayIcon (org.eclipse.jface.viewers.DecorationOverlayIcon)2 ComparisonFailure (org.junit.ComparisonFailure)2 Function (com.google.common.base.Function)1 CoreException (org.eclipse.core.runtime.CoreException)1 URI (org.eclipse.emf.common.util.URI)1 EClass (org.eclipse.emf.ecore.EClass)1 EClassifier (org.eclipse.emf.ecore.EClassifier)1 EReference (org.eclipse.emf.ecore.EReference)1