Search in sources :

Example 1 with SeverityRange

use of com.avaloq.tools.ddk.check.check.SeverityRange in project dsl-devkit by dsldevkit.

the class CheckJavaValidator method checkDefaultSeverityInRange.

/**
 * Checks that the default severity is within given severity range. There must not be a conflict such
 * that the severity range defines severities do not contain the default.
 * <p>
 * Note that this check works even if {@link #checkSeverityRangeOrder(com.avaloq.tools.ddk.check.check.Check)} is violated.
 * </p>
 *
 * @param check
 *          the check
 */
@Check
public void checkDefaultSeverityInRange(final com.avaloq.tools.ddk.check.check.Check check) {
    if (check.getSeverityRange() == null) {
        // only applicable if both range and default severity given
        return;
    }
    final SeverityRange range = check.getSeverityRange();
    final SeverityKind minSeverity = SeverityKind.get(Math.min(range.getMinSeverity().getValue(), range.getMaxSeverity().getValue()));
    final SeverityKind maxSeverity = SeverityKind.get(Math.max(range.getMinSeverity().getValue(), range.getMaxSeverity().getValue()));
    if (check.getDefaultSeverity().compareTo(minSeverity) < 0 || check.getDefaultSeverity().compareTo(maxSeverity) > 0) {
        List<String> issueCodes = Lists.newArrayList();
        SeverityKind temp = minSeverity;
        while (temp != null && temp.compareTo(maxSeverity) <= 0) {
            issueCodes.add(temp.getName());
            temp = SeverityKind.get(temp.getValue() + 1);
        }
        String[] codes = issueCodes.toArray(new String[issueCodes.size()]);
        error(Messages.CheckJavaValidator_DEFAULT_SEVERITY_NOT_IN_RANGE, check, CheckPackage.Literals.CHECK__DEFAULT_SEVERITY, IssueCodes.DEFAULT_SEVERITY_NOT_IN_RANGE, issueCodes.isEmpty() ? // NOPMD
        null : codes);
    }
}
Also used : SeverityKind(com.avaloq.tools.ddk.check.check.SeverityKind) SeverityRange(com.avaloq.tools.ddk.check.check.SeverityRange) Check(org.eclipse.xtext.validation.Check)

Example 2 with SeverityRange

use of com.avaloq.tools.ddk.check.check.SeverityRange in project dsl-devkit by dsldevkit.

the class CheckCfgJavaValidator method checkConfiguredSeverityAllowed.

/**
 * Checks that a configured check's severity is allowed. If referenced check has a {@link SeverityRange severity range} defined, it must be checked that
 * configured value is within defined range.
 *
 * @param configuredCheck
 *          the configured check
 */
@Check
public void checkConfiguredSeverityAllowed(final ConfiguredCheck configuredCheck) {
    // @Format-Off
    if (isSeverityConfigured(configuredCheck) && configuredCheck.getCheck() != null && !configuredCheck.getCheck().eIsProxy() && configuredCheck.getCheck().getSeverityRange() != null) {
        final SeverityRange range = configuredCheck.getCheck().getSeverityRange();
        final com.avaloq.tools.ddk.check.check.SeverityKind configuredSeverity = com.avaloq.tools.ddk.check.check.SeverityKind.getByName(configuredCheck.getSeverity().getName());
        final com.avaloq.tools.ddk.check.check.SeverityKind minSeverity = com.avaloq.tools.ddk.check.check.SeverityKind.get(Math.min(range.getMinSeverity().getValue(), range.getMaxSeverity().getValue()));
        final com.avaloq.tools.ddk.check.check.SeverityKind maxSeverity = com.avaloq.tools.ddk.check.check.SeverityKind.get(Math.max(range.getMinSeverity().getValue(), range.getMaxSeverity().getValue()));
        List<String> issueCodes = Lists.newArrayList();
        if (configuredSeverity.compareTo(minSeverity) < 0 || configuredSeverity.compareTo(maxSeverity) > 0) {
            com.avaloq.tools.ddk.check.check.SeverityKind temp = minSeverity;
            while (temp != null && temp.compareTo(maxSeverity) <= 0) {
                issueCodes.add(temp.getName());
                temp = com.avaloq.tools.ddk.check.check.SeverityKind.get(temp.getValue() + 1);
            }
            String[] codes = issueCodes.toArray(new String[issueCodes.size()]);
            error(Messages.CheckCfgJavaValidator_SEVERITY_NOT_ALLOWED, CheckcfgPackage.Literals.CONFIGURED_CHECK__SEVERITY, IssueCodes.SEVERITY_NOT_ALLOWED, // NOPMD
            issueCodes.isEmpty() ? null : codes);
        }
    // @Format-On
    }
}
Also used : SeverityRange(com.avaloq.tools.ddk.check.check.SeverityRange) Check(org.eclipse.xtext.validation.Check) ConfiguredCheck(com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)

Example 3 with SeverityRange

use of com.avaloq.tools.ddk.check.check.SeverityRange in project dsl-devkit by dsldevkit.

the class CheckImpl method basicSetSeverityRange.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetSeverityRange(SeverityRange newSeverityRange, NotificationChain msgs) {
    SeverityRange oldSeverityRange = severityRange;
    severityRange = newSeverityRange;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CheckPackage.CHECK__SEVERITY_RANGE, oldSeverityRange, newSeverityRange);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) SeverityRange(com.avaloq.tools.ddk.check.check.SeverityRange)

Aggregations

SeverityRange (com.avaloq.tools.ddk.check.check.SeverityRange)3 Check (org.eclipse.xtext.validation.Check)2 SeverityKind (com.avaloq.tools.ddk.check.check.SeverityKind)1 ConfiguredCheck (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1