use of de.be4.classicalb.core.parser.rules.AbstractOperation in project prob2 by bendisposto.
the class RulesChecker method evalOperations.
public Map<AbstractOperation, OperationStatus> evalOperations(State state, Collection<AbstractOperation> operations) {
ArrayList<IEvalElement> formulas = new ArrayList<>();
for (AbstractOperation abstractOperation : operations) {
if (abstractOperation instanceof ComputationOperation || abstractOperation instanceof RuleOperation) {
formulas.add(rulesModel.getEvalElement(abstractOperation));
}
}
state.getStateSpace().subscribe(this, formulas);
Map<IEvalElement, AbstractEvalResult> values = state.getValues();
final Map<AbstractOperation, OperationStatus> states = new HashMap<>();
for (AbstractOperation op : operations) {
if (op instanceof RuleOperation) {
states.put(op, RuleStatus.valueOf(values.get(rulesModel.getEvalElement(op))));
} else if (op instanceof ComputationOperation) {
states.put(op, ComputationStatus.valueOf(values.get(rulesModel.getEvalElement(op))));
}
}
return states;
}
use of de.be4.classicalb.core.parser.rules.AbstractOperation in project prob2 by bendisposto.
the class RulesTestUtil method checkRulesMachineRunForConsistency.
public static void checkRulesMachineRunForConsistency(RulesMachineRun rulesMachineRun) {
RulesProject rulesProject = rulesMachineRun.getRulesProject();
RuleResults ruleResults = rulesMachineRun.getRuleResults();
Map<String, RuleResult> ruleResultMap = ruleResults.getRuleResultMap();
for (AbstractOperation abstractOperation : rulesProject.getOperationsMap().values()) {
if (abstractOperation instanceof RuleOperation) {
String ruleName = abstractOperation.getName();
assertTrue(String.format("Rule operation '%s' is not contained in the result map.", ruleName), ruleResultMap.containsKey(ruleName));
RuleResult ruleResult = ruleResultMap.get(ruleName);
if (ruleResult.getRuleState() == RuleStatus.FAIL) {
assertTrue(String.format("No violation found but rule failed: '%s'", ruleName), ruleResult.getNumberOfViolations() > 0);
}
if (ruleResult.getRuleState() == RuleStatus.NOT_CHECKED) {
List<String> notCheckedCauses = ruleResult.getFailedDependencies();
assertTrue(String.format("There is no cause why rule '%s' is not checked.", ruleName), !notCheckedCauses.isEmpty());
}
}
}
}
use of de.be4.classicalb.core.parser.rules.AbstractOperation in project probparsers by bendisposto.
the class RulesProject method collectAllOperations.
private void collectAllOperations() {
for (IModel iModel : bModels) {
final RulesParseUnit unit = (RulesParseUnit) iModel;
final List<AbstractOperation> operations = unit.getOperations();
for (AbstractOperation abstractOperation : operations) {
final String name = abstractOperation.getName();
if (allOperations.containsKey(name)) {
this.bExceptionList.add(new BException(abstractOperation.getFileName(), new CheckException("Duplicate operation name: '" + name + "'.", abstractOperation.getNameLiteral())));
}
allOperations.put(name, abstractOperation);
}
}
}
use of de.be4.classicalb.core.parser.rules.AbstractOperation in project probparsers by bendisposto.
the class RulesProject method checkVisibilityOfTIdentifierList.
private void checkVisibilityOfTIdentifierList(AbstractOperation operation, List<TIdentifierLiteral> dependencyList) {
List<String> machineReferences = operation.getMachineReferencesAsString();
machineReferences.add(operation.getMachineName());
for (TIdentifierLiteral tIdentifierLiteral : dependencyList) {
String otherOpName = tIdentifierLiteral.getText();
if (allOperations.containsKey(otherOpName)) {
AbstractOperation abstractOperation = allOperations.get(otherOpName);
String otherMachineName = abstractOperation.getMachineName();
if (!machineReferences.contains(otherMachineName)) {
this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Operation '" + otherOpName + "' is not visible in RULES_MACHINE '" + operation.getMachineName() + "'.", tIdentifierLiteral)));
}
}
}
}
use of de.be4.classicalb.core.parser.rules.AbstractOperation in project probparsers by bendisposto.
the class RulesProject method checkFunctionCalls.
private void checkFunctionCalls(AbstractOperation abstractOperation) {
boolean errorOccured = false;
for (TIdentifierLiteral tIdentifierLiteral : abstractOperation.getFunctionCalls()) {
final String functionName = tIdentifierLiteral.getText();
if (!allOperations.containsKey(functionName) || !(allOperations.get(functionName) instanceof FunctionOperation)) {
this.bExceptionList.add(new BException(abstractOperation.getFileName(), new CheckException("Unknown FUNCTION name '" + functionName + "'", tIdentifierLiteral)));
errorOccured = true;
}
}
if (!errorOccured) {
checkVisibilityOfTIdentifierList(abstractOperation, abstractOperation.getFunctionCalls());
}
}
Aggregations