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.");
}
}
Aggregations