Example: Extension of intermediate form statements

As an example of an intermediate form statement extension, you can create a new kind of action for the local variable declaration.

Deprecated feature:

Deprecation icon Support for custom business rule languages is deprecated in V8.8.1. This feature will be removed in a future release of the product. See Deprecated features for migration details.

If you want to create a new kind of action for the local variable declaration, you introduce a new intermediate form statement.

You implement the process method for a new intermediate form statement as follows:

/**
 * The node translator for <T-local-var> node type. 
 */
public static class LocalVarNodeTranslator implements IlrNodeTranslator {

  public static final int LOCAL_VAR = 
                       IlrSimpleActionStatement.CUSTOM_EXTENSION + 1;

  public IlrStatement process(IlrSyntaxTree.Node node,
                              IlrTranslationContext context) {
    IlrSimpleActionStatement statement = new IlrSimpleActionStatement(node);
    statement.setKind(LOCAL_VAR);
    statement.setVarName(IlrBRL.getVariableName(node.getSubNode(0)));
    return statement;
  }
}

In this code, you create a new instance of IlrSimpleActionStatement with a custom kind LOCAL_VAR. The process method returns the statement. It does not need to explore any subnodes.

You register this node translator in the concrete syntax as follows:

<T-local-var>.translatorClass = balsample_extensions.brl.LocalVarNodeTranslator