API

compileExpression()

Returns an int value
and has the following parameters:

  • FormulaField expessionField
  • [, CalculationContext calculationContext]

int compileExpression(FormulaField expressionField [, CalculationContext calculationContext])

This method compiles the expessionField formula, which is called an expression because it doesn't refer to any input or formula field. The optional CalculationContext parameter's udfClassName property is used for the expressions that reference user defined functions. If the expression compilation fails this method returns the relevant error code and stores it in the expessionField. This method is used to verify the correctness of an expression syntax.

The first example shows how to compile the following expression:

import com.crystalprism.ce.formula.HybridFormulaEvaluator;
import com.crystalprism.ce.usermodel.ComputeFieldType;
import com.crystalprism.ce.usermodel.FormulaField;

public class CompileExpressionExample1 {
    public static void main(String[] args) {
        String myExpressionText = "ROUND(165.78, 1)";
        FormulaField myExpressionField = new FormulaField(ComputeFieldType.NUMERIC, myExpressionText);
        int rc = HybridFormulaEvaluator.compileExpression(myExpressionField);
        System.out.println("Expression compilation return code: " + rc);
    }
}

Expression compilation return code: 0

This example makes an intentional mistake by adding an extra bracket to the myExpressionText variable from the previous example. This results in an error code 101, corresponding to an unbalanced parentheses condition:

import com.crystalprism.ce.formula.HybridFormulaEvaluator;
import com.crystalprism.ce.usermodel.ComputeFieldType;
import com.crystalprism.ce.usermodel.FormulaField;

public class CompileExpressionExample2 {
    public static void main(String[] args) {
        String myExpressionText = "ROUND(165.78), 1)";
        FormulaField myExpressionField = new FormulaField(ComputeFieldType.NUMERIC, myExpressionText);
        int rc = HybridFormulaEvaluator.compileExpression(myExpressionField);
        System.out.println("Compilation error code: " + rc);
    }
}

Compilation error code: 101