2 Commits

Author SHA1 Message Date
James
11b6715082 enjoy 4.9 2020-03-04 17:28:41 +08:00
James
aea176b589 enjoy 4.9 2020-03-04 15:13:22 +08:00

View File

@@ -16,10 +16,6 @@
package com.jfinal.template.expr.ast; package com.jfinal.template.expr.ast;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import com.jfinal.template.TemplateException; import com.jfinal.template.TemplateException;
import com.jfinal.template.expr.Sym; import com.jfinal.template.expr.Sym;
import com.jfinal.template.stat.Location; import com.jfinal.template.stat.Location;
@@ -37,16 +33,6 @@ public class Logic extends Expr {
private Expr left; // ! 运算没有 left 参数 private Expr left; // ! 运算没有 left 参数
private Expr right; private Expr right;
// 默认为新工作模式
private static boolean newWorkMode = true;
/**
* 设置为旧工作模式,为了兼容 jfinal 3.3 之前的版本
*/
@Deprecated
public static void setToOldWorkMode() {
newWorkMode = false;
}
/** /**
* 构造 || && 结点 * 构造 || && 结点
*/ */
@@ -107,12 +93,6 @@ public class Logic extends Expr {
* 2boolean 类型,原值返回 * 2boolean 类型,原值返回
* 3String、StringBuilder 等一切继承自 CharSequence 类的对象,返回 length > 0 * 3String、StringBuilder 等一切继承自 CharSequence 类的对象,返回 length > 0
* 4其它返回 true * 4其它返回 true
*
* 通过 Logic.setToOldWorkMode() 设置,可支持老版本中的以下四个规则:
* 1Number 类型,返回 value != 0
* 2Map、Collection(List被包括在内) 返回 size() > 0
* 3数组返回 length > 0
* 4Iterator 返回 hasNext() 值
*/ */
public static boolean isTrue(Object v) { public static boolean isTrue(Object v) {
if (v == null) { if (v == null) {
@@ -122,38 +102,11 @@ public class Logic extends Expr {
if (v instanceof Boolean) { if (v instanceof Boolean) {
return (Boolean)v; return (Boolean)v;
} }
if (v instanceof CharSequence) { if (v instanceof CharSequence) {
return ((CharSequence)v).length() > 0; return ((CharSequence)v).length() > 0;
} }
// 如果不是新工作模式,则对下面类型进行判断
if ( !newWorkMode ) {
if (v instanceof Number) {
if (v instanceof Double) {
return ((Number)v).doubleValue() != 0;
}
if (v instanceof Float) {
return ((Number)v).floatValue() != 0;
}
return ((Number)v).intValue() != 0;
}
// 下面四种类型的判断已提供了 shared method 扩展,用法如下:
// #if(notEmpty(object)) 以及 #if(isEmpty(object))
if (v instanceof Collection) {
return ((Collection<?>)v).size() > 0;
}
if (v instanceof Map) {
return ((Map<?, ?>)v).size() > 0;
}
if (v.getClass().isArray()) {
return Array.getLength(v) > 0;
}
if (v instanceof Iterator) {
return ((Iterator<?>)v).hasNext();
}
}
return true; return true;
} }