Search in sources :

Example 11 with Severity

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

the class XtextValidator method checkOppositeReferenceUsed.

@Check
public void checkOppositeReferenceUsed(Assignment assignment) {
    Severity severity = getIssueSeverities(getContext(), getCurrentObject()).getSeverity(BIDIRECTIONAL_REFERENCE);
    if (severity == null || severity == Severity.IGNORE) {
        // Don't perform any check if the result is ignored
        return;
    }
    EClassifier classifier = GrammarUtil.findCurrentType(assignment);
    if (classifier instanceof EClass) {
        EStructuralFeature feature = ((EClass) classifier).getEStructuralFeature(assignment.getFeature());
        if (feature instanceof EReference) {
            EReference reference = (EReference) feature;
            if (reference.getEOpposite() != null && !(reference.isContainment() || reference.isContainer())) {
                addIssue("The feature '" + assignment.getFeature() + "' is a bidirectional reference." + " This may cause problems in the linking process.", assignment, XtextPackage.eINSTANCE.getAssignment_Feature(), BIDIRECTIONAL_REFERENCE);
            }
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EClassifier(org.eclipse.emf.ecore.EClassifier) Severity(org.eclipse.xtext.diagnostics.Severity) EReference(org.eclipse.emf.ecore.EReference) Check(org.eclipse.xtext.validation.Check)

Example 12 with Severity

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

the class DerivedResourceMarkerCopier method getMaxSeverity.

private int getMaxSeverity(IFile srcFile) {
    URI resourceURI = URI.createPlatformResourceURI(srcFile.getFullPath().toString(), true);
    IResourceServiceProvider serviceProvider = serviceProviderRegistry.getResourceServiceProvider(resourceURI);
    if (serviceProvider == null)
        return Integer.MAX_VALUE;
    IssueSeveritiesProvider severitiesProvider = serviceProvider.get(IssueSeveritiesProvider.class);
    Severity severity = severitiesProvider.getIssueSeverities(new ResourceImpl(resourceURI)).getSeverity(COPY_JAVA_PROBLEMS_ISSUECODE);
    switch(severity) {
        case WARNING:
            return IMarker.SEVERITY_WARNING;
        case ERROR:
            return IMarker.SEVERITY_ERROR;
        case INFO:
        case IGNORE:
            return Integer.MAX_VALUE;
        default:
            break;
    }
    return Integer.MAX_VALUE;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) IssueSeveritiesProvider(org.eclipse.xtext.validation.IssueSeveritiesProvider) Severity(org.eclipse.xtext.diagnostics.Severity) URI(org.eclipse.emf.common.util.URI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI)

Example 13 with Severity

use of org.eclipse.xtext.diagnostics.Severity in project statecharts by Yakindu.

the class DefaultValidationIssueStore method processIssues.

@Override
public synchronized void processIssues(List<Issue> issues, IProgressMonitor monitor) {
    final Multimap<String, SCTIssue> newVisibleIssues = ArrayListMultimap.create();
    for (Issue issue : issues) {
        if (issue instanceof SCTIssue) {
            String semanticURI = ((SCTIssue) issue).getSemanticURI();
            newVisibleIssues.put(semanticURI, (SCTIssue) issue);
        }
    }
    final Multimap<String, SCTIssue> oldVisibleIssues = ArrayListMultimap.create();
    synchronized (visibleIssues) {
        oldVisibleIssues.putAll(visibleIssues);
        // normal and expensive checks will not be executed by the live
        // validation, so persistent markers have to be copied
        Iterable<SCTIssue> persistentIssues = Iterables.filter(visibleIssues.values(), new Predicate<SCTIssue>() {

            public boolean apply(SCTIssue input) {
                CheckType type = input.getType();
                Severity severity = input.getSeverity();
                return CheckType.NORMAL == type || CheckType.EXPENSIVE == type || Severity.INFO == severity;
            }
        });
        for (SCTIssue sctIssue : persistentIssues) {
            newVisibleIssues.put(sctIssue.getSemanticURI(), sctIssue);
        }
        visibleIssues.clear();
        visibleIssues.putAll(newVisibleIssues);
    }
    SetView<String> changes = Sets.symmetricDifference(oldVisibleIssues.keySet(), newVisibleIssues.keySet());
    for (String string : changes) {
        notifyListeners(string);
    }
    SetView<String> intersection = Sets.intersection(oldVisibleIssues.keySet(), newVisibleIssues.keySet());
    for (String string : intersection) {
        if (changedSeverity(string, oldVisibleIssues, newVisibleIssues) || changedErrorCount(string, oldVisibleIssues, newVisibleIssues)) {
            notifyListeners(string);
        }
    }
}
Also used : SCTIssue(org.yakindu.sct.model.sgraph.ui.validation.SCTIssue) Issue(org.eclipse.xtext.validation.Issue) SCTIssue(org.yakindu.sct.model.sgraph.ui.validation.SCTIssue) CheckType(org.eclipse.xtext.validation.CheckType) Severity(org.eclipse.xtext.diagnostics.Severity)

Example 14 with Severity

use of org.eclipse.xtext.diagnostics.Severity in project statecharts by Yakindu.

the class DefaultValidationIssueStore method changedSeverity.

protected boolean changedSeverity(String semanticElementID, Multimap<String, SCTIssue> oldVisibleIssues, Multimap<String, SCTIssue> newVisibleIssues) {
    Severity minOldSeverity = getMinSeverity(oldVisibleIssues.get(semanticElementID));
    Severity minNewSeverity = getMinSeverity(newVisibleIssues.get(semanticElementID));
    return minNewSeverity.ordinal() != minOldSeverity.ordinal();
}
Also used : Severity(org.eclipse.xtext.diagnostics.Severity)

Example 15 with Severity

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

the class SmokeTest method checkNoErrorsInValidator.

protected void checkNoErrorsInValidator(final String model, LazyLinkingResource 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);
                    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) IOException(java.io.IOException) 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)

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