提交 5f921d8d 编写于 作者: T tianqiao

//bugfix处理ExpressRunner嵌套情况下,cache还原的问题

上级 cdc53ece
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<groupId>com.taobao.util</groupId> <groupId>com.taobao.util</groupId>
<artifactId>taobao-express</artifactId> <artifactId>taobao-express</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>3.1.5</version> <version>3.1.6</version>
<name>taobao-express</name> <name>taobao-express</name>
<dependencies> <dependencies>
......
...@@ -86,8 +86,17 @@ class RunnerDataCache{ ...@@ -86,8 +86,17 @@ class RunnerDataCache{
return this.cache; return this.cache;
} }
public void pop(ExpressRunner aRunner){ public void pop(ExpressRunner aRunner){
this.cache = this.stack.pop().getOperateDataCache();
// 原有的逻辑
// this.cache = this.stack.pop().getOperateDataCache();
//bugfix处理ExpressRunner嵌套情况下,cache还原的问题
this.stack.pop();
if(!this.stack.isEmpty()){
this.cache = this.stack.peek().getOperateDataCache();
}else{
this.cache = null;
}
} }
} }
package com.ql.util.express.bugfix;
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import com.ql.util.express.Operator;
import org.junit.Test;
import java.lang.reflect.Method;
public class RecursivelyRunnerTest {
@Test
public void testEvalOperator() throws Exception{
ExpressRunner runner = new ExpressRunner();
runner.addFunction("eval",new EvalOperator());
String express = "eval('10')+eval('20')+eval('30')";
Object r = runner.execute(express, null, null, true, false);
System.out.println(r);
}
@Test
public void testSubRunner() throws Exception{
ExpressRunner runner = new ExpressRunner();
//bind SubRunner.evel method
SubRunner subRunner = new SubRunner();
Method [] methods = SubRunner.class.getDeclaredMethods();
for (Method m : methods) {
String name = m.getName();
runner.addFunctionOfServiceMethod(name, subRunner, name, m.getParameterTypes(), null);
}
String express = "eval('10')+eval('20')+eval('30')";
Object r = runner.execute(express, null, null, true, false);
System.out.println(r);
}
public static class EvalOperator extends Operator{
private ExpressRunner subRun = new ExpressRunner();
@Override
public Object executeInner(Object[] list) throws Exception {
Object result = subRun.execute((String) list[0], new DefaultContext(), null, true, false);
return result;
}
}
public static class SubRunner {
private ExpressRunner subRun = new ExpressRunner();
public Object eval(String obj) throws Exception {
Object result = subRun.execute(obj, new DefaultContext(), null, true, false);
return result;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册