1

如何获取未知变量的所有警告信息?

我有一个表达式,我想评估并知道所有缺失的变量。

例子:

jexl.setStrict(false);
Expression e = (Expression) jexl.createExpression("(pqr||abc)&&xyx&&!(rsw||ruy)&&!sss");

JexlContext context = new MapContext();
 context.set("rsw",false);  
 context.set("xyx",true);   
 Object obj=e.evaluate(context);
 System.out.println(obj);

输出:

Aug 11, 2017 10:58:24 AM org.apache.commons.jexl2.Interpreter unknownVariable
WARNING: com.AdhocPrograms.JexlExample.main@40![1,4]: '(pqr || abc) && xyx && !(rsw || ruy) && !sss;' undefined variable pqr
false
Aug 11, 2017 10:58:24 AM org.apache.commons.jexl2.Interpreter unknownVariable
WARNING: com.AdhocPrograms.JexlExample.main@40![8,11]: '(pqr || abc) && xyx && !(rsw || ruy) && !sss;' undefined variable abc

我想捕获两个未定义的变量。如果我设置 jexl.setStrict(true) 并添加 try and catch 块,我只能捕获一个变量。

  catch(JexlException.Variable xjexl)       {
            System.out.println("Exception:" +xjexl.getVariable());          
            xjexl.printStackTrace();
        }

我也愿意使用另一种技术。

4

1 回答 1

1

我能够使用下面的 getVariables() 方法。

样本:

jexl.createScript("(pqr||abc)&&xyx&&!(rsw||ruy)&&!sss").getVariables();

于 2017-08-15T20:16:28.110 回答