use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class ClausesCheck method checkConstantsClause.
private void checkConstantsClause() {
/*
* CONCRETE_CONSTANTS || CONSTANTS || ABSTRACT_CONSTANTS => PROPERTIES
*/
if ((clauses.containsKey(NAME_CONSTANTS) || clauses.containsKey(NAME_ABSTRACT_CONSTANTS)) && !clauses.containsKey(NAME_PROPERTIES)) {
final Set<Node> nodes = new HashSet<>();
if (clauses.containsKey(NAME_CONSTANTS)) {
nodes.addAll(clauses.get(NAME_CONSTANTS));
}
if (clauses.containsKey(NAME_ABSTRACT_CONSTANTS)) {
nodes.addAll(clauses.get(NAME_ABSTRACT_CONSTANTS));
}
exceptions.add(new CheckException("Clause(s) missing: PROPERTIES", nodes.toArray(new Node[nodes.size()])));
}
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class ClausesCheck method checkVariablesClauses.
private void checkVariablesClauses() {
/*
* CONCRETE_VARIABLES || VARIABLES || ABSTRACT_VARIABLES => INVARIANT &&
* INITIALISATION
*/
if ((clauses.containsKey(NAME_VARIABLES) || clauses.containsKey(NAME_CONCRETE_VARIABLES)) && (!clauses.containsKey(NAME_INVARIANT) || !clauses.containsKey(NAME_INITIALISATION))) {
final Set<Node> nodes = new HashSet<>();
if (clauses.containsKey(NAME_VARIABLES)) {
nodes.addAll(clauses.get(NAME_VARIABLES));
}
if (clauses.containsKey(NAME_CONCRETE_VARIABLES)) {
nodes.addAll(clauses.get(NAME_CONCRETE_VARIABLES));
}
final StringBuilder message = new StringBuilder("Clause(s) missing: ");
boolean first = true;
if (!clauses.containsKey(NAME_INVARIANT)) {
message.append("INVARIANT");
first = false;
}
if (!clauses.containsKey(NAME_INITIALISATION)) {
if (!first) {
message.append(", ");
}
message.append("INITIALISATION");
}
exceptions.add(new CheckException(message.toString(), nodes.toArray(new Node[nodes.size()])));
}
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class ClausesCheck method checkDoubleClauses.
/**
* Checks if one clause is used more than once in the machine.
*
* @throws CheckException
*/
private void checkDoubleClauses() {
for (final Iterator<Set<Node>> iterator = clauses.values().iterator(); iterator.hasNext(); ) {
final Set<Node> nodesforClause = iterator.next();
if (nodesforClause.size() > 1) {
final Node clauseNode = nodesforClause.iterator().next();
final String simpleClassName = clauseNode.getClass().getSimpleName();
final int endIndex = simpleClassName.indexOf("MachineClause");
final String clauseName = simpleClassName.substring(1, endIndex).toUpperCase();
exceptions.add(new CheckException("Clause '" + clauseName + "' is used more than once", nodesforClause.toArray(new Node[nodesforClause.size()])));
}
}
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class DefinitionCollector method caseAConversionDefinition.
@Override
public void caseAConversionDefinition(AConversionDefinition node) {
PDefinition def = node.getDefinition();
if (def instanceof AExpressionDefinitionDefinition) {
AExpressionDefinitionDefinition exprDef = (AExpressionDefinitionDefinition) def;
final String defName = exprDef.getName().getText();
final Type type = defTypes.getType(defName);
addDefinition(node, type, defName);
} else {
this.exceptions.add(new CheckException("Only an expression is allowed on the right hand side of a conversion definition.", node));
}
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class DefinitionUsageCheck method runChecks.
public void runChecks(final Start rootNode) {
// only need to check complete machines
if (!Utils.isCompleteMachine(rootNode)) {
return;
}
erroneousNodes.clear();
rootNode.apply(this);
if (!erroneousNodes.isEmpty()) {
exceptions.add(new CheckException("Number of parameters doesn't match declaration of definition", erroneousNodes.toArray(new Node[erroneousNodes.size()])));
}
}
Aggregations