Accumulate accumulate = null;
if ( accumDescr.isExternalFunction() ) {
// if it is an external function, build a method for it
// TODO: add the support to multiple functions
AccumulateFunctionCallDescr func = accumDescr.getFunctions().get( 0 );
AccumulateFunction function = context.getConfiguration().getAccumulateFunction( func.getFunction() );
if ( function == null ) {
context.getErrors().add( new DescrBuildError( accumDescr,
context.getRuleDescr(),
null,
"Unknown accumulate function: '" + func.getFunction() + "' on rule '" + context.getRuleDescr().getName() + "'. All accumulate functions must be registered before building a resource." ) );
return null;
}
final JavaAnalysisResult analysis = (JavaAnalysisResult) context.getDialect().analyzeBlock( context,
accumDescr,
func.getParams().length > 0 ? func.getParams()[0] : "\"\"",
new BoundIdentifiers( declCls, context.getPackageBuilder().getGlobals() ) );
final BoundIdentifiers usedIdentifiers = analysis.getBoundIdentifiers();
final Declaration[] previousDeclarations = usedIdentifiers.getDeclarations().values().toArray(new Declaration[usedIdentifiers.getDeclarations().size()]);
final Declaration[] sourceDeclArr = (Declaration[]) source.getOuterDeclarations().values().toArray( new Declaration[0] );
final String className = "accumulateExpression" + context.getNextId();
final Map<String, Object> map = createVariableContext( className,
func.getParams().length > 0 ? func.getParams()[0] : "\"\"",
context,
previousDeclarations,
sourceDeclArr,
usedIdentifiers.getGlobals(),
null );