@Override
public void emitRendezvous(Context context) {
ModelFactory f = context.getModelFactory();
MasterKindFlowAnalyzer masterAnalyzer = new MasterKindFlowAnalyzer(context);
FlowElementPortDescription tx = context.getInputPort(MasterBranch.ID_INPUT_TRANSACTION);
OperatorDescription desc = context.getOperatorDescription();
List<Expression> arguments = Lists.create();
arguments.add(masterAnalyzer.getGetCheckedMasterExpression());
arguments.add(context.getProcessInput(tx));
for (OperatorDescription.Parameter param : desc.getParameters()) {
arguments.add(Models.toLiteral(f, param.getValue()));
}
Method method = desc.getDeclaration().toMethod();
assert method != null : desc.getDeclaration();
Class<?> enumType = method.getReturnType();
List<Tuple2<Enum<?>, FlowElementPortDescription>> constants =
EnumUtil.extractConstants(enumType, desc.getOutputPorts());
Expression impl = context.createImplementation();
SimpleName branch = context.createName("branch");
context.addProcess(tx, new ExpressionBuilder(f, impl)
.method(desc.getDeclaration().getName(), arguments)
.toLocalVariableDeclaration(
context.convert(enumType),
branch));
List<Statement> cases = Lists.create();
for (Tuple2<Enum<?>, FlowElementPortDescription> tuple : constants) {
Enum<?> constant = tuple.first;
FlowElementPortDescription port = tuple.second;
ResultMirror next = context.getOutput(port);
cases.add(f.newSwitchCaseLabel(f.newSimpleName(constant.name())));
cases.add(next.createAdd(context.getProcessInput(tx)));
cases.add(f.newBreakStatement());
}