All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cdc.mf.checks.atts.visibility.AbstractVisibilityMustBePublic Maven / Gradle / Ivy

The newest version!
package cdc.mf.checks.atts.visibility;

import cdc.issues.IssueSeverity;
import cdc.issues.checks.CheckContext;
import cdc.issues.checks.CheckResult;
import cdc.issues.checks.SnapshotManager;
import cdc.issues.locations.Location;
import cdc.issues.rules.Rule;
import cdc.issues.rules.RuleDescription;
import cdc.mf.checks.IssueDescription;
import cdc.mf.checks.MfAbstractRuleChecker;
import cdc.mf.model.MfVisibility;
import cdc.mf.model.MfVisibilityItem;

public abstract class AbstractVisibilityMustBePublic extends MfAbstractRuleChecker {
    public static final IssueSeverity SEVERITY = IssueSeverity.CRITICAL;

    protected static String describe(String article,
                                     String item) {
        return RuleDescription.wrap(article, true, item) + WS + RuleDescription.wrap(N_VISIBILITY)
                + " must be public (or undefined).";
    }

    protected AbstractVisibilityMustBePublic(SnapshotManager manager,
                                             Class objectClass,
                                             Rule rule) {
        super(manager,
              objectClass,
              rule);
    }

    @Override
    public CheckResult check(CheckContext context,
                             O object,
                             Location location) {
        final MfVisibility visibility = object.getVisibility();
        if (visibility != null && visibility != MfVisibility.PUBLIC) {
            final IssueDescription.Builder description = IssueDescription.builder();

            description.header(getHeader(object))
                       .value(visibility.name())
                       .violation("is not public");

            add(issue().description(description)
                       .location(location)
                       .build());
            return CheckResult.FAILURE;
        } else {
            return CheckResult.SUCCESS;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy