ModelFactory f = context.getModelFactory();
OperatorDescription desc = context.getOperatorDescription();
FlowElementPortDescription master = desc.getInputPorts().get(0);
FlowElementPortDescription tx = desc.getInputPorts().get(1);
ListBufferMirror list = context.createListBuffer(master.getDataType(), InputBuffer.EXPAND);
context.addBegin(list.createBegin());
Expression proc = context.getProcessInput(master);
context.addProcess(master, list.createAdvance(proc));
context.addEnd(list.createEnd());
List<Expression> arguments = Lists.create();
arguments.add(list.get());
arguments.add(context.getProcessInput(tx));
for (OperatorDescription.Parameter param : desc.getParameters()) {
arguments.add(Models.toLiteral(f, param.getValue()));
}
assert selector.getParameterTypes().size() <= arguments.size();
if (selector.getParameterTypes().size() <= arguments.size()) {
arguments = arguments.subList(0, selector.getParameterTypes().size());
}
context.addProcess(tx, list.createEnd());
Expression impl = context.createImplementation();
SimpleName selected = context.createName("selected");
context.addProcess(tx, new ExpressionBuilder(f, impl)
.method(selector.getName(), arguments)
.toLocalVariableDeclaration(
context.convert(master.getDataType()),
selected));
context.addEnd(list.createShrink());
this.hasMasterExpresion = new ExpressionBuilder(f, selected)
.apply(InfixOperator.NOT_EQUALS, Models.toNullLiteral(f))
.toExpression();
this.getMasterExpression = selected;