Search in sources :

Example 1 with SafetyContractImpl

use of edu.umn.cs.crisys.safety.safety.impl.SafetyContractImpl in project AMASE by loonwerks.

the class SafetyValidator method checkAnalysisStatement.

/**
 * Check for multiple analysis statements in SafetyContractImpl.
 * Check behavior of analysis statements and values for n and
 * probability.
 * @param analysisStmt
 */
@Check(CheckType.FAST)
public void checkAnalysisStatement(AnalysisStatement analysisStmt) {
    AnalysisBehavior behavior = analysisStmt.getBehavior();
    SafetyContractImpl contract = (SafetyContractImpl) analysisStmt.eContainer();
    boolean fcount = false;
    boolean probspec = false;
    for (SpecStatement spec : contract.getSpecs()) {
        if (spec instanceof AnalysisStatement) {
            if (((AnalysisStatement) spec).getBehavior() instanceof FaultCountBehavior) {
                fcount = true;
            } else if (((AnalysisStatement) spec).getBehavior() instanceof ProbabilityBehavior) {
                probspec = true;
            }
        }
    }
    if (fcount && probspec) {
        error(analysisStmt, "Only one analysis statement can be defined in the annex.");
    }
    if (behavior instanceof FaultCountBehavior) {
        FaultCountBehavior fc = (FaultCountBehavior) behavior;
        if (!testIntegerString(fc.getMaxFaults())) {
            error(analysisStmt, "Max N value must be a valid string representing a positive integer.");
        }
    } else if (behavior instanceof ProbabilityBehavior) {
        ProbabilityBehavior prob = (ProbabilityBehavior) behavior;
        if (!testProbabilityString(prob.getProbabilty())) {
            error(analysisStmt, "Probability must be a valid string between 0 and 1 inclusive.");
        }
    } else {
        error(analysisStmt, "Analysis behavior must be either 'analyze: max n fault' or 'analyze: probability r' for integer n and real number r.");
    }
}
Also used : AnalysisStatement(edu.umn.cs.crisys.safety.safety.AnalysisStatement) SafetyContractImpl(edu.umn.cs.crisys.safety.safety.impl.SafetyContractImpl) FaultCountBehavior(edu.umn.cs.crisys.safety.safety.FaultCountBehavior) AnalysisBehavior(edu.umn.cs.crisys.safety.safety.AnalysisBehavior) ProbabilityBehavior(edu.umn.cs.crisys.safety.safety.ProbabilityBehavior) SpecStatement(edu.umn.cs.crisys.safety.safety.SpecStatement) Check(org.eclipse.xtext.validation.Check)

Aggregations

AnalysisBehavior (edu.umn.cs.crisys.safety.safety.AnalysisBehavior)1 AnalysisStatement (edu.umn.cs.crisys.safety.safety.AnalysisStatement)1 FaultCountBehavior (edu.umn.cs.crisys.safety.safety.FaultCountBehavior)1 ProbabilityBehavior (edu.umn.cs.crisys.safety.safety.ProbabilityBehavior)1 SpecStatement (edu.umn.cs.crisys.safety.safety.SpecStatement)1 SafetyContractImpl (edu.umn.cs.crisys.safety.safety.impl.SafetyContractImpl)1 Check (org.eclipse.xtext.validation.Check)1