ModelFactory f = context.getModelFactory();
OperatorDescription desc = context.getOperatorDescription();
FlowElementPortDescription master = desc.getInputPorts().get(0);
Expression hasMaster = context.createField(boolean.class, "sawMaster");
DataObjectMirror masterCache = context.createModelCache(master.getDataType());
context.addBegin(new ExpressionBuilder(f, hasMaster)
.assignFrom(Models.toLiteral(f, false))
.toStatement());
context.addProcess(master, f.newIfStatement(
new ExpressionBuilder(f, hasMaster)
.apply(InfixOperator.EQUALS, Models.toLiteral(f, false))
.toExpression(),
f.newBlock(new Statement[] {
masterCache.createSet(context.getProcessInput(master)),
new ExpressionBuilder(f, hasMaster)
.assignFrom(Models.toLiteral(f, true))
.toStatement()
}),
null));
this.hasMasterExpresion = hasMaster;
this.getMasterExpression = masterCache.get();
this.getCheckedMasterExpression = f.newConditionalExpression(
hasMasterExpresion,
getMasterExpression,
Models.toNullLiteral(f));
}