Releases: killme2008/aviatorscript
Aviator 4.2.6 released
Main changes:
- Fixed NPE when compare date instances #175
Aviator 4.2.5 released
Main changes:
- Deprecated
AviatorEvaluator#exec
, please useAviatorEvaluator#execute
instead. - Function missing mechanism #170, #171, you can custom your own behaviours when calling function is not found by implement
FunctionMissing
interface. - A default function missing implementation
JavaMethodReflectionFunctionMissing
. With this handler, you can call any java class's public instance methods by reflection even when you don't import them. The example is here,but you have to pay performance cost(almost 3x times slower than implements custom functions). - New doc 调用 Java 方法和 Function Missing
Aviator 4.2.4 released
Main features:
- Fixed #162 , long type promption error.
- Fixed #166 , call varidic methods in java class.
- Adds
seq.array(clazz, arg1, arg2, ...)
function to create an array ofclazz
type,seq.array(int, 1, 2, 3)
for example that creates an int arraynew int[] {1, 2, 3}
. - Adds annotations for importing java class methods:
Function
for java method to set custom function name.Ignore
to ignore java method for importing.Import
annotation with new methodAviatorEvaluatorInstance#importFunctions
to set imported methods scope and namespace.
- Breaking change: aviator generated bytecode version bump to Java 1.7
map
andreduce
function now supportjava.util.Map
, the element type isMap.Entry
, #164- Constant pool for constants(number/string etc.) to reduce CPU and memory consumption #167
Aviator 4.2.3 released
- Fixed:
AviatorEvaluator.addStaticFunctions
shoud be static. - New feature: imports java class's instance methods by
AviatorEvaluator.addInstanceFunctions(String, Class)
orAviatorEvaluatorInstance#addInstanceFunctions(String, Class)
. For example:
AviatorEvaluator.addInstanceFunctions("s", String.class);
Then you can use all java.lang.String
's all public instance methods by passing the string instance as the first argument:
s.indexOf('hello', 'l')
s.replaceAll('hello', 'l', 'x')
Aviator 4.2.2 released
Main features:
- Added new methods
AviatorEvaluator.addStaticFunctions(namespace, clazz)
andAviatorEvaluatorInstanc#addStaticFunctions(namespace, clazz)
to import class public static methods as custom functions under namespace #155 - Breaking change: the regular pattern's value is the compiled java
Pattern
instance, it's a string before. - Improve runtime exceptions.
Aviator 4.2.1 released
- Fixed typo:
SringContextFunctionLoader.java
->SpringContextFunctionLoader
- Fixed NPE in tracing mode #145
Many code style,compile warnings and document errors fixed, thanks to @oldratlee contribution.
Aviator 4.2.0 released
Main features:
- Fixed closured over wrong variable in nested lambda #134
- Adds a new opiton
Options.ALWAYS_PARSE_INTEGRAL_NUMBER_INTO_DECIMAL
that will parse all integral numbers into big decimal, thanks to @aliiohs #124 - Adds
seq.contains_key(map, key)
to check if the key object is exists in a map and fixedEnv#contains_key
#122 - Adds a new feature: capture function invocation arguments into env, for example:
List<FunctionArgument> args = (List<FunctionArgument>) AviatorEvaluator
.execute("f = lambda(a,bc, d) -> __args__ end; f(1,2,100+2)");
The args
list is retrieved from env
as __args__
var,and it's a list of FunctionArgument
:
[
FunctionArgument [index=0, expression=1],
FunctionArgument [index=1, expression=2],
FunctionArgument [index=2, expression=100+2]
]
This feature is useful for function invocation caching or parameter vailidation, and it's optional, if you want it, you can enable it by setting Options.CAPTURE_FUNCTION_ARGS
to be true
, default is false.
The argument list can also be captured in custom functions, you can get it through FunctionUtils.getFunctionArguments(env)
or env.get("__args__")
.
Aviator 4.1.2 released
Main features:
- Fixed a bug in
FunctionUtils#getJavaObject
to retrieve java collection type such as (user.roles) #106 - Fixed NPE when tracing expression evaluation.
- Variables captured by closure should be immutable. #101
- Adds a new option
Options.DISABLE_ASSIGNMENT
to disable variable assignment. - Literal expression performance issue #96
- New functions to create java collections
seq.set(x,y,z...)
to create aHashSet
instance from varidic arguments.seq.list(x,y,z...)
to create a 'ArrayList` instance from varidic arguments.seq.map(k1,v1, k2, v2,...)
to create aHashMap
instance from varidic arguments.- New functions
seq.add
,seq.remove
andseq.get
to add/remove/get elements(values) from collections.
seq.max(coll)
andseq.min(coll)
to retrieve min/max element in a sequence.min(x,y,z...)
andmax(x,y,z...)
to retrieve min/max value from varidic arguments.identity(x)
function to return the argument itself.- Adds a new document 4.0 features explain.
Maven
<dependency>
<groupId>com.googlecode.aviator</groupId>
<artifactId>aviator</artifactId>
<version>4.1.2</version>
</dependency>
Aviator 4.1.1 发布
主要改动如下:
- 性能优化,从简单测试来看,对比 4.1.0 有近 30% 的提升,整体性能接近 3.3.0 版本。
- 废弃
AviatorEvaluator.exec(exp, args...)
方法,都推荐使用execute
方法明确传入env
map 的方式。
此版本推荐升级。
`Maven 依赖:
<dependency>
<groupId>com.googlecode.aviator</groupId>
<artifactId>aviator</artifactId>
<version>4.1.1</version>
</dependency>
Aviator 4.1.0 发布
新功能列表
- 支持赋值语句,可以在表达式中给变量赋值,一些例子:
assertEquals(3, AviatorEvaluator.execute("a=1; a+2"));
assertEquals(5, AviatorEvaluator.execute("a=3; b=2; a+b"));
assertEquals(20.0, AviatorEvaluator.execute("a=3; b=2; c=a+b; c*4.0"));
assertEquals(6, AviatorEvaluator.execute("square = lambda(x) -> x *2 end; square(3)"));
assertEquals(1, AviatorEvaluator.execute("a=5;b=4.2 ; c= a > b? 1: 0; c"));
assertEquals(6, AviatorEvaluator.execute("add_n = lambda(x) -> lambda(y) -> x + y end end ; "
+ "add_1 = add_n(1) ; " + "add_2 = add_n(2) ;" + " add_1(add_2(3))"));
可以看到处了基本类型赋值之外,还可以支持将 lambda 表达式赋值给一个变量,函数也将作为 first class 成员使用。
AviatorEvaulatorInstance
和AviatorEvaulator
新增方法isExpressionCached()
和getExpressionCacheSize()
分别用于判断表达式是否缓存编译结果,以及返回缓存的编译表达式总数。AbstractFunction
和AbstractVariadicFunction
都继承了AviatorObject
,函数作为 first class 成员提供,他们的值就是自身。- 新增可变参数函数
tuple(x, y, z, ...)
用于返回一个Object []
数组,适用于需要返回多参数的场景。 - 对于
a.b.c
的嵌套访问语法糖做了性能改进,如果a
和b
都是Map
,将直接访问,避免全局锁和反射,感谢阿里同事的 idea 贡献。性能测试来看有接近一倍的提升。 - 一些代码重构和改进,感谢 @einverne
Bug 修复
- #77 开启高精度计算情况下,正则表达式错误。
- #87
long
和double
函数不支持 decimal 和 bigint 类型。 - #92 转义符号处理异常。
- 修复编译优化丢失 env 的 bug。
兼容问题
FunctionUtils#getStringValue(AviatorObject, Map)
当 string 为 null 的时候直接返回,不再抛出异常 #674.0.0-RC
版本为了支持 lambda 闭包,引入了嵌套 scope 的概念,并且不再直接修改用户传入的 env map,但是发现很多用户依赖这个修改行为,因此 4.1.0 引入了Options.USE_USER_ENV_AS_TOP_ENV_DIRECTLY
选项,默认为 true,表示将直接使用用户的 env 作为 top 级别的 env 使用,兼容老版本的行为 #74 #94
推荐跳过此版本,直接升级到最新版本,此版本有一定性能问题
Maven 依赖:
<dependency>
<groupId>com.googlecode.aviator</groupId>
<artifactId>aviator</artifactId>
<version>4.1.0</version>
</dependency>