Skip to content

Commit 76cea26

Browse files
committed
update version 3.2.1
1 parent 6ca414a commit 76cea26

File tree

16 files changed

+285
-396
lines changed

16 files changed

+285
-396
lines changed

VERSIONS.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,17 @@ public Object execute(InstructionSet[] instructionSets,IExpressContext<String,Ob
103103
## 18、3.1.7版本[2017-11-17]
104104
(1)bugfix 在自定义操作符的情况下,调用 runner.getOutVarNames Api 可能引发的空指针问题
105105

106-
## 18、3.1.8版本[2018-1-30]
107-
(1)增加扩展功能:ExpressRunner#setIgnoreConstChar(Boolean),设置可以忽略单字符操作,即 'a'自动变成"a"。
106+
## 19、发布到github,修改pom文件标识
107+
108+
```xml
109+
<dependency>
110+
<groupId>com.alibaba</groupId>
111+
<artifactId>QLExpress</artifactId>
112+
<packaging>jar</packaging>
113+
<version>3.2.0</version>
114+
</dependency>
115+
```
116+
117+
## 3.2.1版本[2018-2-23]
118+
(1)增加扩展功能:ExpressRunner#setIgnoreConstChar(Boolean),设置可以忽略单字符操作,即 'a'自动变成"a"。
119+
(2)增加接口来支持绑定自定义classloader的class的method:ExpressRunner#addFunctionOfClassMethod(String name, Class<?> aClass,...)。

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>com.alibaba</groupId>
77
<artifactId>QLExpress</artifactId>
88
<packaging>jar</packaging>
9-
<version>3.2.0</version>
9+
<version>3.2.1</version>
1010
<name>QLExpress</name>
1111
<description>QLExpress is a powerful, lightweight, dynamic language for the Java platform aimed at improving developers’ productivity in different business scenes.</description>
1212
<url>https://github.com/alibaba/QLExpress</url>

src/main/java/com/ql/util/express/ExpressRunner.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,24 @@ public void addFunctionOfClassMethod(String name, String aClassName,
283283
aClassName, aFunctionName, aParameterClassTypes,null,null, errorInfo));
284284

285285
}
286+
287+
/**
288+
* 添加一个类的函数定义,例如:Math.abs(double) 映射为表达式中的 "取绝对值(-5.0)"
289+
* @param name 函数名称
290+
* @param aClass 类
291+
* @param aFunctionName 类中的方法名称
292+
* @param aParameterClassTypes 方法的参数类型名称
293+
* @param errorInfo 如果函数执行的结果是false,需要输出的错误信息
294+
* @throws Exception
295+
*/
296+
public void addFunctionOfClassMethod(String name, Class<?> aClass,
297+
String aFunctionName, Class<?>[] aParameterClassTypes,
298+
String errorInfo) throws Exception {
299+
this.addFunction(name, new OperatorSelfDefineClassFunction(name,
300+
aClass, aFunctionName, aParameterClassTypes,null,null, errorInfo));
301+
302+
}
303+
286304
/**
287305
* 添加一个类的函数定义,例如:Math.abs(double) 映射为表达式中的 "取绝对值(-5.0)"
288306
* @param name 函数名称
@@ -735,4 +753,19 @@ public boolean isShortCircuit() {
735753
public void setShortCircuit(boolean isShortCircuit) {
736754
this.isShortCircuit = isShortCircuit;
737755
}
756+
757+
/**
758+
* 是否忽略charset类型的数据,而识别为string,比如'a' -> "a"
759+
* 默认为不忽略,正常识别为String
760+
*/
761+
public boolean isIgnoreConstChar() {
762+
return this.parse.isIgnoreConstChar();
763+
}
764+
public void setIgnoreConstChar(boolean ignoreConstChar) {
765+
this.parse.setIgnoreConstChar(ignoreConstChar);
766+
}
767+
public void checkySyntax(String text) throws Exception {
768+
Map<String,String> selfDefineClass = new HashMap<String,String> ();
769+
this.parse.parse(this.rootExpressPackage,text, true,selfDefineClass);
770+
}
738771
}

src/main/java/com/ql/util/express/instruction/op/OperatorSelfDefineClassFunction.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ public class OperatorSelfDefineClassFunction extends OperatorBase implements Can
2020
Method method;
2121
boolean isReturnVoid;
2222
boolean maybeDynamicParams;
23+
24+
public OperatorSelfDefineClassFunction(String aOperName,Class<?> aOperClass, String aFunctionName,
25+
Class<?>[] aParameterClassTypes,String[] aParameterDesc,String[] aParameterAnnotation,String aErrorInfo) throws Exception {
26+
if (errorInfo != null && errorInfo.trim().length() == 0) {
27+
errorInfo = null;
28+
}
29+
this.name = aOperName;
30+
this.errorInfo = aErrorInfo;
31+
this.functionName = aFunctionName;
32+
this.parameterClasses = aParameterClassTypes;
33+
this.parameterTypes = new String[aParameterClassTypes.length];
34+
this.operDataDesc = aParameterDesc;
35+
this.operDataAnnotation = aParameterAnnotation;
36+
for(int i=0;i<this.parameterClasses.length;i++){
37+
this.parameterTypes[i] = this.parameterClasses[i].getName();
38+
}
39+
operClass = aOperClass;
40+
method = operClass.getMethod(functionName,parameterClasses);
41+
this.isReturnVoid = method.getReturnType().equals(void.class);
42+
this.maybeDynamicParams = DynamicParamsUtil.maybeDynamicParams(parameterClasses);
43+
}
2344

2445
public OperatorSelfDefineClassFunction(String aOperName,String aClassName, String aFunctionName,
2546
Class<?>[] aParameterClassTypes,String[] aParameterDesc,String[] aParameterAnnotation,String aErrorInfo) throws Exception {

src/main/java/com/ql/util/express/match/NodeTypeManagerTestImpl.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/main/java/com/ql/util/express/parse/ExpressParse.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,26 @@ public class ExpressParse {
1919
private static final Log log = LogFactory.getLog(ExpressParse.class);
2020
NodeTypeManager nodeTypeManager;
2121
IExpressResourceLoader expressResourceLoader;
22+
23+
/**
24+
* 是否忽略charset类型的数据,而识别为string,比如'a' -> "a"
25+
* 在计算比如 '1'+'2'=='12'
26+
*/
27+
private boolean ignoreConstChar = false;
2228
/**
2329
* 是否需要高精度计算
2430
*/
2531
private boolean isPrecise = false;
26-
public ExpressParse(NodeTypeManager aNodeTypeManager,IExpressResourceLoader aLoader,boolean aIsPrecise){
32+
33+
public boolean isIgnoreConstChar() {
34+
return ignoreConstChar;
35+
}
36+
37+
public void setIgnoreConstChar(boolean ignoreConstChar) {
38+
this.ignoreConstChar = ignoreConstChar;
39+
}
40+
41+
public ExpressParse(NodeTypeManager aNodeTypeManager, IExpressResourceLoader aLoader, boolean aIsPrecise){
2742
this.nodeTypeManager = aNodeTypeManager;
2843
this.expressResourceLoader = aLoader;
2944
this.isPrecise = aIsPrecise;
@@ -174,7 +189,7 @@ public List<ExpressNode> transferWord2ExpressNode(ExpressPackage aRootExpressPac
174189
tempWord = tempWord.substring(1,tempWord.length() -1);
175190

176191
treeNodeType = nodeTypeManager.findNodeType("CONST");
177-
if(tempWord.length() == 1){ //转换为字符串
192+
if(tempWord.length() == 1 && !ignoreConstChar){ //转换为字符串
178193
tempType =nodeTypeManager.findNodeType("CONST_CHAR");
179194
objectValue = tempWord.charAt(0);
180195
}else{

src/main/java/com/ql/util/express/parse/KeyWordDefine4SQL.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/main/java/com/ql/util/express/parse/NodeTypeManager.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ public class NodeTypeManager implements INodeTypeManager {
2525
public NodeTypeManager() {
2626
this(new KeyWordDefine4Java());
2727
}
28-
public NodeTypeManager(KeyWordDefine4SQL keyWorkdDefine){
29-
this.splitWord = keyWorkdDefine.splitWord;
30-
this.keyWords = keyWorkdDefine.keyWords;
31-
this.nodeTypeDefines = keyWorkdDefine.nodeTypeDefines;
32-
this.initial();
33-
34-
}
3528
public NodeTypeManager(KeyWordDefine4Java keyWorkdDefine){
3629
this.splitWord = keyWorkdDefine.splitWord;
3730
com.ql.util.express.parse.WordSplit.sortSplitWord(this.splitWord);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.ql.util.express.bugfix;
2+
3+
import com.ql.util.express.DefaultContext;
4+
import com.ql.util.express.ExpressRunner;
5+
import com.ql.util.express.IExpressContext;
6+
import org.junit.Test;
7+
8+
/**
9+
* Created by tianqiao on 18/1/29.
10+
*/
11+
public class IgnoreConstCharTest {
12+
13+
@Test
14+
public void test() throws Exception{
15+
ExpressRunner runner = new ExpressRunner();
16+
runner.setIgnoreConstChar(true);
17+
String exp = "'1'+'2'==\"12\"";
18+
IExpressContext<String, Object> context = new DefaultContext<String, Object>();
19+
Object result = runner.execute(exp,context,null,false,true);
20+
assert ((Boolean) result);
21+
}
22+
}

0 commit comments

Comments
 (0)