use of de.prob.model.representation.ModelElementList in project prob2 by bendisposto.
the class ComponentExtractor method caseAMachineParseUnit.
@Override
public void caseAMachineParseUnit(final AMachineParseUnit node) {
String name = node.getName().getText();
MachineModifier machineM = new MachineModifier(new EventBMachine(name), typeEnv);
ModelElementList<Context> seen = new ModelElementList<>();
for (TIdentifierLiteral contextName : node.getSeenNames()) {
String cName = contextName.getText();
AbstractElement context = getContext(cName);
seen = seen.addElement((Context) context);
}
machineM = machineM.setSees(seen);
if (node.getRefinesNames().size() == 1) {
String mname = node.getRefinesNames().getFirst().getText();
EventBMachine machine = getMachine(mname);
machineM = machineM.setRefines(machine);
} else if (node.getRefinesNames().size() > 1) {
throw new IllegalArgumentException("Machines can only refine one abstract machine. Found " + node.getRefinesNames().size() + " refined machines");
}
machineM = machineM.addComment(getComment(node.getComments()));
MachineExtractor mE = new MachineExtractor(machineM, typeEnv);
node.apply(mE);
modelM = modelM.addMachine(mE.getMachine());
}
use of de.prob.model.representation.ModelElementList in project prob2 by bendisposto.
the class DomBuilder method inAOperation.
@Override
public void inAOperation(final AOperation node) {
String name = extractIdentifierName(node.getOpName());
if (prefix != null && !prefix.equals(name)) {
name = prefix + "." + name;
}
List<PExpression> paramIds = node.getParameters();
final List<String> params = extractIdentifiers(paramIds);
final List<String> output = extractIdentifiers(node.getReturnValues());
Operation operation = new Operation(name, params, output);
PSubstitution body = node.getOperationBody();
List<ClassicalBGuard> guards = new ArrayList<>();
if (body instanceof ASelectSubstitution) {
PPredicate condition = ((ASelectSubstitution) body).getCondition();
List<PPredicate> predicates = getPredicates(condition);
for (PPredicate pPredicate : predicates) {
guards.add(new ClassicalBGuard(createPredicateAST(pPredicate)));
}
}
if (body instanceof APreconditionSubstitution) {
PPredicate condition = ((APreconditionSubstitution) body).getPredicate();
List<PPredicate> predicates = getPredicates(condition);
for (PPredicate pPredicate : predicates) {
guards.add(new ClassicalBGuard(createPredicateAST(pPredicate)));
}
}
List<ClassicalBAction> actions = new ArrayList<>();
actions.add(new ClassicalBAction(createSubstitutionAST(body)));
operation = operation.set(Action.class, new ModelElementList<>(actions));
operation = operation.set(Guard.class, new ModelElementList<>(guards));
operations.add(operation);
}
Aggregations