/** * Construct the main function. * * @param filter The single SIRFilter of the application. * @return A JBlock with the statements of the main function. */ private JBlock mainFunction(SIRFilter filter) { JBlock statements = new JBlock(null, new JStatement[0], null); // create the params list, for some reason // calling toArray() on the list breaks a later pass List paramList = filter.getParams(); JExpression[] paramArray; if (paramList == null || paramList.size() == 0) paramArray = new JExpression[0]; else paramArray = (JExpression[]) paramList.toArray(new JExpression[0]); // add the call to the init function statements.addStatement( new JExpressionStatement( null, new JMethodCallExpression( null, new JThisExpression(null), filter.getInit().getName(), paramArray), null)); // add the call to the pre(init)work function if this filter // is a two stage.. if (filter instanceof SIRTwoStageFilter) { SIRTwoStageFilter two = (SIRTwoStageFilter) filter; statements.addStatement( new JExpressionStatement( null, new JMethodCallExpression( null, new JThisExpression(null), two.getInitWork().getName(), new JExpression[0]), null)); } // add the call to the work function statements.addStatement(generateSteadyStateLoop(filter)); return statements; }