Search in sources :

Example 6 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 7 with Severity

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

the class LanguageServerImpl method publishDiagnostics.

private void publishDiagnostics(final URI uri, final Iterable<? extends Issue> issues) {
    PublishDiagnosticsParams _publishDiagnosticsParams = new PublishDiagnosticsParams();
    final Procedure1<PublishDiagnosticsParams> _function = (PublishDiagnosticsParams it) -> {
        it.setUri(this._uriExtensions.toUriString(uri));
        final Function1<Issue, Boolean> _function_1 = (Issue it_1) -> {
            Severity _severity = it_1.getSeverity();
            return Boolean.valueOf((_severity != Severity.IGNORE));
        };
        final Function1<Issue, Diagnostic> _function_2 = (Issue it_1) -> {
            return this.toDiagnostic(it_1);
        };
        it.setDiagnostics(IterableExtensions.<Diagnostic>toList(IterableExtensions.map(IterableExtensions.filter(issues, _function_1), _function_2)));
    };
    final PublishDiagnosticsParams diagnostics = ObjectExtensions.<PublishDiagnosticsParams>operator_doubleArrow(_publishDiagnosticsParams, _function);
    this.client.publishDiagnostics(diagnostics);
}
Also used : Issue(org.eclipse.xtext.validation.Issue) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Diagnostic(org.eclipse.lsp4j.Diagnostic) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Severity(org.eclipse.xtext.diagnostics.Severity)

Example 8 with Severity

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

the class LanguageServerImpl method toDiagnostic.

private Diagnostic toDiagnostic(final Issue issue) {
    Diagnostic _diagnostic = new Diagnostic();
    final Procedure1<Diagnostic> _function = (Diagnostic it) -> {
        it.setCode(issue.getCode());
        DiagnosticSeverity _switchResult = null;
        Severity _severity = issue.getSeverity();
        if (_severity != null) {
            switch(_severity) {
                case ERROR:
                    _switchResult = DiagnosticSeverity.Error;
                    break;
                case WARNING:
                    _switchResult = DiagnosticSeverity.Warning;
                    break;
                case INFO:
                    _switchResult = DiagnosticSeverity.Information;
                    break;
                default:
                    _switchResult = DiagnosticSeverity.Hint;
                    break;
            }
        } else {
            _switchResult = DiagnosticSeverity.Hint;
        }
        it.setSeverity(_switchResult);
        it.setMessage(issue.getMessage());
        Integer _elvis = null;
        Integer _lineNumber = issue.getLineNumber();
        if (_lineNumber != null) {
            _elvis = _lineNumber;
        } else {
            _elvis = Integer.valueOf(1);
        }
        final int lineNumber = ((_elvis).intValue() - 1);
        Integer _elvis_1 = null;
        Integer _column = issue.getColumn();
        if (_column != null) {
            _elvis_1 = _column;
        } else {
            _elvis_1 = Integer.valueOf(1);
        }
        final int column = ((_elvis_1).intValue() - 1);
        Integer _elvis_2 = null;
        Integer _length = issue.getLength();
        if (_length != null) {
            _elvis_2 = _length;
        } else {
            _elvis_2 = Integer.valueOf(0);
        }
        final Integer length = _elvis_2;
        Position _position = new Position(lineNumber, column);
        Position _position_1 = new Position(lineNumber, (column + (length).intValue()));
        Range _range = new Range(_position, _position_1);
        it.setRange(_range);
    };
    return ObjectExtensions.<Diagnostic>operator_doubleArrow(_diagnostic, _function);
}
Also used : DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Position(org.eclipse.lsp4j.Position) Diagnostic(org.eclipse.lsp4j.Diagnostic) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Severity(org.eclipse.xtext.diagnostics.Severity) Range(org.eclipse.lsp4j.Range)

Example 9 with Severity

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

the class DiagnosticConverterImpl method convertValidatorDiagnostic.

@Override
public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
    Severity severity = getSeverity(diagnostic);
    if (severity == null)
        return;
    IssueImpl issue = new Issue.IssueImpl();
    issue.setSeverity(severity);
    IssueLocation locationData = getLocationData(diagnostic);
    if (locationData != null) {
        issue.setLineNumber(locationData.lineNumber);
        issue.setColumn(locationData.column);
        issue.setOffset(locationData.offset);
        issue.setLength(locationData.length);
    }
    final EObject causer = getCauser(diagnostic);
    if (causer != null)
        issue.setUriToProblem(EcoreUtil.getURI(causer));
    issue.setCode(getIssueCode(diagnostic));
    issue.setType(getIssueType(diagnostic));
    issue.setData(getIssueData(diagnostic));
    // marker.put(IXtextResourceChecker.DIAGNOSTIC_KEY, diagnostic);
    issue.setMessage(diagnostic.getMessage());
    // marker.put(IMarker.PRIORITY, Integer.valueOf(IMarker.PRIORITY_LOW));
    acceptor.accept(issue);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IssueImpl(org.eclipse.xtext.validation.Issue.IssueImpl) Severity(org.eclipse.xtext.diagnostics.Severity)

Example 10 with Severity

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

the class XtextDiagnosticConverter method getSeverity.

@Override
protected Severity getSeverity(Diagnostic diagnostic) {
    Severity result = super.getSeverity(diagnostic);
    String issueCode = getIssueCode(diagnostic);
    if (result == Severity.WARNING && issueCode != null) {
        // only warnings can be suppressed
        EObject causer = getCauser(diagnostic);
        if (causer != null) {
            if (isMarkedAsIgnored(causer, issueCode)) {
                return null;
            }
            if (!(causer instanceof AbstractRule)) {
                AbstractRule rule = GrammarUtil.containingRule(causer);
                if (rule != null && isMarkedAsIgnored(rule, issueCode)) {
                    return null;
                }
            }
            Grammar grammar = GrammarUtil.getGrammar(causer);
            if (grammar != null && isMarkedAsIgnored(grammar, issueCode)) {
                return null;
            }
        }
    }
    return result;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Severity(org.eclipse.xtext.diagnostics.Severity) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule)

Aggregations

Severity (org.eclipse.xtext.diagnostics.Severity)20 Issue (org.eclipse.xtext.validation.Issue)8 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 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)2 DecorationOverlayIcon (org.eclipse.jface.viewers.DecorationOverlayIcon)2 Diagnostic (org.eclipse.lsp4j.Diagnostic)2 DiagnosticSeverity (org.eclipse.lsp4j.DiagnosticSeverity)2 Check (org.eclipse.xtext.validation.Check)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