use of de.prob.model.representation.AbstractElement in project prob2 by bendisposto.
the class MachineXmlHandler method addRefinedMachine.
private void addRefinedMachine(final Attributes attributes) {
String target = attributes.getValue("org.eventb.core.scTarget");
String machineName = target.substring(target.lastIndexOf('/') + 1, target.lastIndexOf('.'));
model = model.addRelationship(machine.getName(), machineName, ERefType.REFINES);
AbstractElement component = model.getComponent(machineName);
if (component != null) {
EventBMachine mch = (EventBMachine) component;
refines.add(mch);
} else {
try {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser saxParser = parserFactory.newSAXParser();
String fileName = directoryPath + File.separatorChar + machineName + ".bcm";
MachineXmlHandler handler = new MachineXmlHandler(model, fileName, typeEnv);
saxParser.parse(new File(fileName), handler);
axiomCache.putAll(handler.getAxiomCache());
invariantCache.putAll(handler.getInvariantCache());
eventCache.putAll(handler.getEventCache());
refines.add(handler.getMachine());
model = handler.getModel();
} catch (IOException | ParserConfigurationException | SAXException e) {
logger.error("Error parsing XML", e);
}
}
}
use of de.prob.model.representation.AbstractElement in project prob2 by bendisposto.
the class MachineXmlHandler method addSeesContext.
private void addSeesContext(final Attributes attributes) {
String target = attributes.getValue("org.eventb.core.scTarget");
String contextName = target.substring(target.lastIndexOf('/') + 1, target.lastIndexOf('.'));
model = model.addRelationship(machine.getName(), contextName, ERefType.SEES);
seesNames.add(contextName);
AbstractElement context = model.getComponent(contextName);
if (context != null) {
sees.add((Context) context);
}
}
use of de.prob.model.representation.AbstractElement 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.AbstractElement in project prob2 by bendisposto.
the class ContextXmlHandler method addExtendedContext.
private void addExtendedContext(final Attributes attributes) {
String source = attributes.getValue("org.eventb.core.scTarget");
String contextName = source.substring(source.lastIndexOf('#') + 1, source.length());
model.addRelationship(context.getName(), contextName, ERefType.EXTENDS);
if (!inInternalContext) {
extendsNames.add(contextName);
}
AbstractElement component = model.getComponent(contextName);
if (component != null) {
if (inInternalContext) {
internalExtends.add((Context) component);
} else {
extendedContexts.add((Context) component);
}
}
}
use of de.prob.model.representation.AbstractElement in project prob2 by bendisposto.
the class Transition method getParameterPredicates.
/**
* @return a list of string predicates representing the value of the
* parameters for this transition
*/
public List<String> getParameterPredicates() {
if (isArtificialTransition()) {
return Collections.emptyList();
}
evaluate(FormulaExpand.EXPAND);
List<String> predicates = new ArrayList<>();
AbstractElement mainComponent = stateSpace.getMainComponent();
List<String> paramNames = new ArrayList<>();
if (mainComponent instanceof ClassicalBMachine) {
Operation op = ((ClassicalBMachine) mainComponent).getOperation(getName());
paramNames = op.getParameters();
} else if (mainComponent instanceof EventBMachine) {
Event event = ((EventBMachine) mainComponent).getEvent(getName());
for (EventParameter eventParameter : event.getParameters()) {
paramNames.add(eventParameter.getName());
}
}
if (paramNames.size() == this.params.size()) {
for (int i = 0; i < paramNames.size(); i++) {
predicates.add(paramNames.get(i) + " = " + this.params.get(i));
}
}
return predicates;
}
Aggregations