Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
34c1a9e53a | ||
|
f6a855b6bf | ||
|
4377d19e2f | ||
|
820f2806ec | ||
|
808bdf6079 | ||
|
eac1d8d055 | ||
|
d5a88b8be4 | ||
|
fd5d554171 | ||
|
6d18be3df8 | ||
|
869824e2bb | ||
|
84573be584 | ||
|
3cc94a5b32 | ||
|
3a4f4f4495 | ||
|
d250b431a4 | ||
|
5e133e7de5 | ||
|
ef39843a25 | ||
|
0e5f3b7249 | ||
|
6f5cd47376 | ||
|
b23a1a9133 | ||
|
4c63d00157 | ||
|
972c7e7673 | ||
|
6d7d0af2b2 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -51,3 +51,4 @@ a_little_config_pro.txt
|
||||
|
||||
dev_plan.txt
|
||||
|
||||
|
||||
|
11
README.md
11
README.md
@@ -1,10 +1,10 @@
|
||||
### Enjoy
|
||||
|
||||
Enjoy 是基于 Java 语言的极轻量极魔板引擎。极轻量级仅 171K 并且不依赖任何第三方。极简设计仅 if、for、set、define、include、render 六个核心指令,让学习成本低到极致。独创 DKFF(Dynamic Key Feature Forward) 词法分析算法与 DLRD (Double Layer Recursive Descent)语法分析算法,避免使用 javacc、antlr、jflex 生成器,令代码量少到极致。
|
||||
Enjoy 是基于 Java 语言的极轻量极魔板引擎。极轻量级仅 171K 并且不依赖任何第三方。极简设计仅 if、for、switch、set、define、include、render 七个核心指令,让学习成本低到极致。独创 DKFF(Dynamic Key Feature Forward) 词法分析算法与 DLRD (Double Layer Recursive Descent)语法分析算法,避免使用 javacc、antlr、jflex 生成器,令代码量少到极致。
|
||||
|
||||
#### Enjoy 主要特点
|
||||
- 消灭传统模板引擎中大量繁杂概念,仅六个核心指令,学习成本极低
|
||||
- 独创 DKFF 词法分析算法与 DLRD 语法分析算法,避免使用javacc、antlr
|
||||
- 消灭传统模板引擎中大量繁杂概念,仅七个核心指令,学习成本极低
|
||||
- 独创 DKFF 词法分析算法与 DLRD 语法分析算法,避免使用 javacc、antlr
|
||||
- 功能强大,极为简单覆盖掉 freemarker、velocity 的核心功能
|
||||
- 扩展性强,支持多种扩展方式,且是唯一支持指令级扩展的模板引擎
|
||||
- 与 java 打通式设计,在模板中与 java 交互极为方便
|
||||
@@ -34,9 +34,10 @@ Enjoy 是基于 Java 语言的极轻量极魔板引擎。极轻量级仅 171K
|
||||
```
|
||||
|
||||
**2.详细使用方法见 jfinal 手册**
|
||||
read me 正在补充,详细使用文档请下载 jfinal.com 官网的 jfinal 手册[http://www.jfinal.com](http://www.jfinal.com)
|
||||
|
||||
**JFinal 官方网站:[http://www.jfinal.com](http://www.jfinal.com)**
|
||||
read me 正在补充,详细使用文档见官网:[https://www.jfinal.com/doc/6-1](https://www.jfinal.com/doc/6-1)
|
||||
|
||||
**JFinal Enjoy 官方文档:[https://www.jfinal.com/doc/6-1](https://www.jfinal.com/doc/6-1)**
|
||||
|
||||
|
||||
|
||||
|
6
pom.xml
6
pom.xml
@@ -4,7 +4,7 @@
|
||||
<artifactId>enjoy</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>enjoy</name>
|
||||
<version>3.5</version>
|
||||
<version>4.0</version>
|
||||
<url>http://www.jfinal.com</url>
|
||||
<description>Enjoy is a simple, light, rapid, independent, extensible Java Template Engine.</description>
|
||||
|
||||
@@ -73,8 +73,8 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
@@ -30,11 +30,6 @@ import java.util.Map;
|
||||
@SuppressWarnings({"serial", "rawtypes", "unchecked"})
|
||||
public class Kv extends HashMap {
|
||||
|
||||
@Deprecated
|
||||
private static final String STATE_OK = "isOk";
|
||||
@Deprecated
|
||||
private static final String STATE_FAIL = "isFail";
|
||||
|
||||
public Kv() {
|
||||
}
|
||||
|
||||
@@ -46,73 +41,25 @@ public class Kv extends HashMap {
|
||||
return new Kv();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Kv ok() {
|
||||
return new Kv().setOk();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Kv ok(Object key, Object value) {
|
||||
return ok().set(key, value);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Kv fail() {
|
||||
return new Kv().setFail();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Kv fail(Object key, Object value) {
|
||||
return fail().set(key, value);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Kv setOk() {
|
||||
super.put(STATE_OK, Boolean.TRUE);
|
||||
super.put(STATE_FAIL, Boolean.FALSE);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Kv setFail() {
|
||||
super.put(STATE_FAIL, Boolean.TRUE);
|
||||
super.put(STATE_OK, Boolean.FALSE);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isOk() {
|
||||
Boolean isOk = (Boolean)get(STATE_OK);
|
||||
if (isOk != null) {
|
||||
return isOk;
|
||||
}
|
||||
Boolean isFail = (Boolean)get(STATE_FAIL);
|
||||
if (isFail != null) {
|
||||
return !isFail;
|
||||
}
|
||||
|
||||
throw new IllegalStateException("调用 isOk() 之前,必须先调用 ok()、fail() 或者 setOk()、setFail() 方法");
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isFail() {
|
||||
Boolean isFail = (Boolean)get(STATE_FAIL);
|
||||
if (isFail != null) {
|
||||
return isFail;
|
||||
}
|
||||
Boolean isOk = (Boolean)get(STATE_OK);
|
||||
if (isOk != null) {
|
||||
return !isOk;
|
||||
}
|
||||
|
||||
throw new IllegalStateException("调用 isFail() 之前,必须先调用 ok()、fail() 或者 setOk()、setFail() 方法");
|
||||
}
|
||||
|
||||
public Kv set(Object key, Object value) {
|
||||
super.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Kv setIfNotBlank(Object key, String value) {
|
||||
if (StrKit.notBlank(value)) {
|
||||
set(key, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Kv setIfNotNull(Object key, Object value) {
|
||||
if (value != null) {
|
||||
set(key, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Kv set(Map map) {
|
||||
super.putAll(map);
|
||||
return this;
|
||||
|
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.jfinal.kit;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
|
||||
/**
|
||||
* 反射工具类
|
||||
*/
|
||||
@@ -24,11 +27,50 @@ public class ReflectKit {
|
||||
public static Object newInstance(Class<?> clazz) {
|
||||
try {
|
||||
return clazz.newInstance();
|
||||
} catch (Exception e) {
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getMethodSignature(Method method) {
|
||||
StringBuilder ret = new StringBuilder()
|
||||
.append(method.getDeclaringClass().getName())
|
||||
.append(".")
|
||||
.append(method.getName())
|
||||
.append("(");
|
||||
|
||||
int index = 0;
|
||||
Parameter[] paras = method.getParameters();
|
||||
for (Parameter p : paras) {
|
||||
if (index++ > 0) {
|
||||
ret.append(", ");
|
||||
}
|
||||
ret.append(p.getParameterizedType().getTypeName());
|
||||
}
|
||||
|
||||
return ret.append(")").toString();
|
||||
}
|
||||
|
||||
/*
|
||||
public static String getMethodSignature(Method method) {
|
||||
StringBuilder ret = new StringBuilder()
|
||||
.append(method.getDeclaringClass().getName())
|
||||
.append(".")
|
||||
.append(method.getName())
|
||||
.append("(");
|
||||
|
||||
int index = 0;
|
||||
java.lang.reflect.Type[] paraTypes = method.getGenericParameterTypes();
|
||||
for (java.lang.reflect.Type type : paraTypes) {
|
||||
if (index++ > 0) {
|
||||
ret.append(", ");
|
||||
}
|
||||
ret.append(type.getTypeName());
|
||||
}
|
||||
|
||||
return ret.append(")").toString();
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -26,6 +26,7 @@ import com.jfinal.template.expr.ast.FieldGetter;
|
||||
import com.jfinal.template.expr.ast.FieldKeyBuilder;
|
||||
import com.jfinal.template.expr.ast.FieldKit;
|
||||
import com.jfinal.template.expr.ast.MethodKit;
|
||||
import com.jfinal.template.io.EncoderFactory;
|
||||
import com.jfinal.template.source.ClassPathSourceFactory;
|
||||
import com.jfinal.template.source.ISource;
|
||||
import com.jfinal.template.source.ISourceFactory;
|
||||
@@ -471,6 +472,17 @@ public class Engine {
|
||||
return config.getEncoding();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enjoy 模板引擎对 UTF-8 的 encoding 做过性能优化,某些偏门字符在
|
||||
* 被编码为 UTF-8 时会出现异常,此时可以通过继承扩展 EncoderFactory
|
||||
* 来解决编码异常,具体用法参考:
|
||||
* http://www.jfinal.com/feedback/5340
|
||||
*/
|
||||
public Engine setEncoderFactory(EncoderFactory encoderFactory) {
|
||||
config.setEncoderFactory(encoderFactory);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Engine setWriterBufferSize(int bufferSize) {
|
||||
config.setWriterBufferSize(bufferSize);
|
||||
return this;
|
||||
@@ -520,8 +532,8 @@ public class Engine {
|
||||
* Engine.addFieldGetter(1, new IsMethodFieldGetter());
|
||||
*
|
||||
* 注:IsMethodFieldGetter 系统已经提供,只是默认没有启用。该实现类通过调用
|
||||
* target.isXxx() 方法获取 target.xxx 表达式的值,其中 xxx 字段必须是
|
||||
* Boolean/boolean 类型
|
||||
* target.isXxx() 方法获取 target.xxx 表达式的值,其中 isXxx() 返回值
|
||||
* 必须是 Boolean/boolean 类型才会被调用
|
||||
*/
|
||||
public static void addFieldGetter(int index, FieldGetter fieldGetter) {
|
||||
FieldKit.addFieldGetter(index, fieldGetter);
|
||||
|
@@ -73,9 +73,9 @@ public class EngineConfig {
|
||||
addDirective("string", StringDirective.class);
|
||||
addDirective("random", RandomDirective.class);
|
||||
addDirective("number", NumberDirective.class);
|
||||
addDirective("call", CallDirective.class);
|
||||
|
||||
// Add official shared method of Template Engine
|
||||
// addSharedMethod(new Json());
|
||||
addSharedMethod(new SharedMethodLib());
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ public class EngineConfig {
|
||||
* Add shared function with file
|
||||
*/
|
||||
public void addSharedFunction(String fileName) {
|
||||
fileName = fileName.replace("\\", "/");
|
||||
// FileSource fileSource = new FileSource(baseTemplatePath, fileName, encoding);
|
||||
ISource source = sourceFactory.getSource(baseTemplatePath, fileName, encoding);
|
||||
doAddSharedFunction(source, fileName);
|
||||
@@ -261,8 +262,9 @@ public class EngineConfig {
|
||||
throw new IllegalArgumentException("baseTemplatePath can not be blank");
|
||||
}
|
||||
baseTemplatePath = baseTemplatePath.trim();
|
||||
baseTemplatePath = baseTemplatePath.replace("\\", "/");
|
||||
if (baseTemplatePath.length() > 1) {
|
||||
if (baseTemplatePath.endsWith("/") || baseTemplatePath.endsWith("\\")) {
|
||||
if (baseTemplatePath.endsWith("/")) {
|
||||
baseTemplatePath = baseTemplatePath.substring(0, baseTemplatePath.length() - 1);
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.jfinal.template;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -117,16 +116,10 @@ public class Template {
|
||||
* 适用于代码生成器类似应用场景
|
||||
*/
|
||||
public void render(Map<?, ?> data, File file) {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
render(data, fos);
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {fos.close();} catch (IOException e) {e.printStackTrace(System.err);}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -28,8 +28,8 @@ public class TemplateException extends RuntimeException {
|
||||
super(loc != null ? msg + loc : msg);
|
||||
}
|
||||
|
||||
public TemplateException(String msg, Location loc, Throwable t) {
|
||||
super(loc != null ? msg + loc : msg, t);
|
||||
public TemplateException(String msg, Location loc, Throwable cause) {
|
||||
super(loc != null ? msg + loc : msg, cause);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,28 +21,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import com.jfinal.template.EngineConfig;
|
||||
import com.jfinal.template.expr.Sym;
|
||||
import com.jfinal.template.expr.ast.Arith;
|
||||
import com.jfinal.template.expr.ast.Array;
|
||||
import com.jfinal.template.expr.ast.Assign;
|
||||
import com.jfinal.template.expr.ast.Compare;
|
||||
import com.jfinal.template.expr.ast.Const;
|
||||
import com.jfinal.template.expr.ast.Expr;
|
||||
import com.jfinal.template.expr.ast.ExprList;
|
||||
import com.jfinal.template.expr.ast.Field;
|
||||
import com.jfinal.template.expr.ast.ForCtrl;
|
||||
import com.jfinal.template.expr.ast.Id;
|
||||
import com.jfinal.template.expr.ast.IncDec;
|
||||
import com.jfinal.template.expr.ast.Index;
|
||||
import com.jfinal.template.expr.ast.Logic;
|
||||
import com.jfinal.template.expr.ast.Map;
|
||||
import com.jfinal.template.expr.ast.Method;
|
||||
import com.jfinal.template.expr.ast.NullSafe;
|
||||
import com.jfinal.template.expr.ast.RangeArray;
|
||||
import com.jfinal.template.expr.ast.SharedMethod;
|
||||
import com.jfinal.template.expr.ast.StaticField;
|
||||
import com.jfinal.template.expr.ast.StaticMethod;
|
||||
import com.jfinal.template.expr.ast.Ternary;
|
||||
import com.jfinal.template.expr.ast.Unary;
|
||||
import com.jfinal.template.expr.ast.*;
|
||||
import com.jfinal.template.stat.Location;
|
||||
import com.jfinal.template.stat.ParaToken;
|
||||
import com.jfinal.template.stat.ParseException;
|
||||
|
@@ -28,10 +28,10 @@ import com.jfinal.template.stat.Scope;
|
||||
*
|
||||
* field 表达式取值优先次序,以 user.name 为例
|
||||
* 1:假如 user.getName() 存在,则优先调用
|
||||
* 2:假如 user 为 Model 子类,则调用 user.get("name")
|
||||
* 3:假如 user 为 Record,则调用 user.get("name")
|
||||
* 4:假如 user 为 Map,则调用 user.get("name")
|
||||
* 5:假如 user 具有 public name 属性,则取 user.name 属性值
|
||||
* 2:假如 user 具有 public name 属性,则取 user.name 属性值
|
||||
* 3:假如 user 为 Model 子类,则调用 user.get("name")
|
||||
* 4:假如 user 为 Record,则调用 user.get("name")
|
||||
* 5:假如 user 为 Map,则调用 user.get("name")
|
||||
*/
|
||||
public class Field extends Expr {
|
||||
|
||||
@@ -73,9 +73,7 @@ public class Field extends Expr {
|
||||
if (fieldGetter.notNull()) {
|
||||
return fieldGetter.get(target, fieldName);
|
||||
}
|
||||
} catch (TemplateException e) {
|
||||
throw e;
|
||||
} catch (ParseException e) {
|
||||
} catch (TemplateException | ParseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new TemplateException(e.getMessage(), location, e);
|
||||
|
@@ -69,9 +69,9 @@ public class FieldGetters {
|
||||
java.lang.reflect.Method[] methodArray = targetClass.getMethods();
|
||||
for (java.lang.reflect.Method method : methodArray) {
|
||||
if (method.getName().equals(getterName) && method.getParameterTypes().length == 0) {
|
||||
if (MethodKit.isForbiddenMethod(getterName)) {
|
||||
throw new RuntimeException("Forbidden method: " + getterName);
|
||||
}
|
||||
// if (MethodKit.isForbiddenMethod(getterName)) {
|
||||
// throw new RuntimeException("Forbidden method: " + getterName);
|
||||
// }
|
||||
|
||||
return new GetterMethodFieldGetter(method);
|
||||
}
|
||||
|
@@ -44,10 +44,13 @@ public class FieldKit {
|
||||
LinkedList<FieldGetter> ret = new LinkedList<FieldGetter>();
|
||||
|
||||
ret.addLast(new GetterMethodFieldGetter(null));
|
||||
ret.addLast(new RealFieldGetter(null));
|
||||
// ret.addLast(new ModelFieldGetter());
|
||||
// ret.addLast(new RecordFieldGetter());
|
||||
ret.addLast(new MapFieldGetter());
|
||||
ret.addLast(new RealFieldGetter(null));
|
||||
|
||||
// 挪到第二的位置,addSharedObject(..., modelObj) 用法可以获取到 model 中的 public 属性
|
||||
// ret.addLast(new RealFieldGetter(null));
|
||||
ret.addLast(new ArrayLengthGetter());
|
||||
// ret.addLast(new IsMethodFieldGetter());
|
||||
|
||||
@@ -133,6 +136,10 @@ public class FieldKit {
|
||||
|
||||
getters = ret.toArray(new FieldGetter[ret.size()]);
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
fieldGetterCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -88,9 +88,7 @@ public class Method extends Expr {
|
||||
}
|
||||
throw new TemplateException(buildMethodNotFoundSignature("public method not found: " + target.getClass().getName() + ".", methodName, argValues), location);
|
||||
|
||||
} catch (TemplateException e) {
|
||||
throw e;
|
||||
} catch (ParseException e) {
|
||||
} catch (TemplateException | ParseException e) {
|
||||
throw e;
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable t = e.getTargetException();
|
||||
|
@@ -48,7 +48,8 @@ public class MethodKit {
|
||||
Class<?>[] cs = {
|
||||
System.class, Runtime.class, Thread.class, Class.class, ClassLoader.class, File.class,
|
||||
Compiler.class, InheritableThreadLocal.class, Package.class, Process.class,
|
||||
RuntimePermission.class, SecurityManager.class, ThreadGroup.class, ThreadLocal.class
|
||||
RuntimePermission.class, SecurityManager.class, ThreadGroup.class, ThreadLocal.class,
|
||||
java.lang.reflect.Method.class
|
||||
};
|
||||
for (Class<?> c : cs) {
|
||||
forbiddenClasses.add(c);
|
||||
@@ -59,7 +60,7 @@ public class MethodKit {
|
||||
static {
|
||||
String[] ms = {
|
||||
"getClass", "getDeclaringClass", "forName", "newInstance", "getClassLoader",
|
||||
"getMethod", "getMethods", "getField", "getFields",
|
||||
"invoke", // "getMethod", "getMethods", // "getField", "getFields",
|
||||
"notify", "notifyAll", "wait",
|
||||
"load", "exit", "loadLibrary", "halt",
|
||||
"stop", "suspend", "resume", "setDaemon", "setPriority",
|
||||
@@ -98,6 +99,10 @@ public class MethodKit {
|
||||
forbiddenClasses.add(clazz);
|
||||
}
|
||||
|
||||
public static void removeForbiddenClass(Class<?> clazz) {
|
||||
forbiddenClasses.remove(clazz);
|
||||
}
|
||||
|
||||
public static boolean isForbiddenMethod(String methodName) {
|
||||
return forbiddenMethods.contains(methodName);
|
||||
}
|
||||
@@ -106,6 +111,14 @@ public class MethodKit {
|
||||
forbiddenMethods.add(methodName);
|
||||
}
|
||||
|
||||
public static void removeForbiddenMethod(String methodName) {
|
||||
forbiddenMethods.remove(methodName);
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
methodCache.clear();
|
||||
}
|
||||
|
||||
public static MethodInfo getMethod(Class<?> targetClass, String methodName, Object[] argValues) {
|
||||
Class<?>[] argTypes = getArgTypes(argValues);
|
||||
Long key = getMethodKey(targetClass, methodName, argTypes);
|
||||
|
@@ -63,9 +63,7 @@ public class SharedMethod extends Expr {
|
||||
throw new TemplateException(Method.buildMethodNotFoundSignature("Shared method not found: ", methodName, argValues), location);
|
||||
}
|
||||
|
||||
} catch (TemplateException e) {
|
||||
throw e;
|
||||
} catch (ParseException e) {
|
||||
} catch (TemplateException | ParseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new TemplateException(e.getMessage(), location, e);
|
||||
|
@@ -72,9 +72,7 @@ public class StaticMethod extends Expr {
|
||||
throw new TemplateException(Method.buildMethodNotFoundSignature("public static method not found: " + clazz.getName() + "::", methodName, argValues), location);
|
||||
}
|
||||
|
||||
} catch (TemplateException e) {
|
||||
throw e;
|
||||
} catch (ParseException e) {
|
||||
} catch (TemplateException | ParseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new TemplateException(e.getMessage(), location, e);
|
||||
|
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.jfinal.template.ext.directive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import com.jfinal.template.Directive;
|
||||
import com.jfinal.template.Env;
|
||||
import com.jfinal.template.TemplateException;
|
||||
import com.jfinal.template.expr.ast.Const;
|
||||
import com.jfinal.template.expr.ast.Expr;
|
||||
import com.jfinal.template.expr.ast.ExprList;
|
||||
import com.jfinal.template.io.Writer;
|
||||
import com.jfinal.template.stat.ParseException;
|
||||
import com.jfinal.template.stat.Scope;
|
||||
import com.jfinal.template.stat.ast.Define;
|
||||
|
||||
/**
|
||||
* CallDirective 动态调用模板函数
|
||||
*
|
||||
* 模板函数的名称与参数都可以动态指定,提升模板函数调用的灵活性
|
||||
*
|
||||
* 例如:
|
||||
* #call(funcName, p1, p2, ..., pn)
|
||||
* 其中 funcName,为函数名,p1、p2、pn 为被调用函数所使用的参数
|
||||
*
|
||||
*
|
||||
* 如果希望模板函数不存在时忽略其调用,添加常量值 true 在第一个参数位置即可
|
||||
* 例如:
|
||||
* #call(true, funcName, p1, p2, ..., pn)
|
||||
*
|
||||
*
|
||||
* TODO 后续优化看一下 ast.Call.java
|
||||
*/
|
||||
public class CallDirective extends Directive {
|
||||
|
||||
protected Expr funcNameExpr;
|
||||
protected ExprList paraExpr;
|
||||
|
||||
protected boolean nullSafe = false; // 是否支持函数名不存在时跳过
|
||||
|
||||
public void setExprList(ExprList exprList) {
|
||||
int len = exprList.length();
|
||||
if (len == 0) {
|
||||
throw new ParseException("模板函数名不能缺失", location);
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
Expr expr = exprList.getExpr(index);
|
||||
if (expr instanceof Const && ((Const)expr).isBoolean()) {
|
||||
if (len == 1) {
|
||||
throw new ParseException("模板函数名不能缺失", location);
|
||||
}
|
||||
|
||||
nullSafe = ((Const)expr).getBoolean();
|
||||
index++;
|
||||
}
|
||||
|
||||
funcNameExpr = exprList.getExpr(index++);
|
||||
|
||||
ArrayList<Expr> list = new ArrayList<Expr>();
|
||||
for (int i=index; i<len; i++) {
|
||||
list.add(exprList.getExpr(i));
|
||||
}
|
||||
paraExpr = new ExprList(list);
|
||||
}
|
||||
|
||||
public void exec(Env env, Scope scope, Writer writer) {
|
||||
Object funcNameValue = funcNameExpr.eval(scope);
|
||||
if (funcNameValue == null) {
|
||||
if (nullSafe) {
|
||||
return ;
|
||||
}
|
||||
throw new TemplateException("模板函数名为 null", location);
|
||||
}
|
||||
|
||||
if (!(funcNameValue instanceof String)) {
|
||||
throw new TemplateException("模板函数名必须是字符串", location);
|
||||
}
|
||||
|
||||
Define func = env.getFunction(funcNameValue.toString());
|
||||
|
||||
if (func == null) {
|
||||
if (nullSafe) {
|
||||
return ;
|
||||
}
|
||||
throw new TemplateException("模板函数未找到 : " + funcNameValue, location);
|
||||
}
|
||||
|
||||
func.call(env, scope, paraExpr, writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -46,15 +46,7 @@ public class ByteWriter extends Writer {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
if (out != null) {
|
||||
out.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
out = null;
|
||||
}
|
||||
out = null;
|
||||
}
|
||||
|
||||
public void write(String str, int offset, int len) throws IOException {
|
||||
|
@@ -40,15 +40,7 @@ public class CharWriter extends Writer {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
if (out != null) {
|
||||
out.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
out = null;
|
||||
}
|
||||
out = null;
|
||||
}
|
||||
|
||||
public void write(String str, int offset, int len) throws IOException {
|
||||
|
@@ -18,7 +18,6 @@ package com.jfinal.template.source;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
@@ -64,7 +63,7 @@ public class ClassPathSource implements ISource {
|
||||
this.classLoader = getClassLoader();
|
||||
this.url = classLoader.getResource(finalFileName);
|
||||
if (url == null) {
|
||||
throw new IllegalArgumentException("File not found : \"" + finalFileName + "\"");
|
||||
throw new IllegalArgumentException("File not found in CLASSPATH or JAR : \"" + finalFileName + "\"");
|
||||
}
|
||||
|
||||
processIsInJarAndlastModified();
|
||||
@@ -141,9 +140,8 @@ public class ClassPathSource implements ISource {
|
||||
|
||||
public static StringBuilder loadFile(InputStream inputStream, String encoding) {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
br = new BufferedReader(new InputStreamReader(inputStream, encoding));
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, encoding))) {
|
||||
// br = new BufferedReader(new FileReader(fileName));
|
||||
String line = br.readLine();
|
||||
if (line != null) {
|
||||
@@ -159,16 +157,6 @@ public class ClassPathSource implements ISource {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
// com.jfinal.kit.LogKit.error(e.getMessage(), e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@@ -19,7 +19,6 @@ package com.jfinal.template.source;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import com.jfinal.template.EngineConfig;
|
||||
|
||||
@@ -92,9 +91,8 @@ public class FileSource implements ISource {
|
||||
|
||||
public static StringBuilder loadFile(File file, String encoding) {
|
||||
StringBuilder ret = new StringBuilder((int)file.length() + 3);
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
br = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding))) {
|
||||
// br = new BufferedReader(new FileReader(fileName));
|
||||
String line = br.readLine();
|
||||
if (line != null) {
|
||||
@@ -110,16 +108,6 @@ public class FileSource implements ISource {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
// com.jfinal.kit.LogKit.error(e.getMessage(), e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@@ -24,22 +24,7 @@ import com.jfinal.template.expr.ExprParser;
|
||||
import com.jfinal.template.expr.ast.ExprList;
|
||||
import com.jfinal.template.expr.ast.ForCtrl;
|
||||
import com.jfinal.template.stat.Symbol;
|
||||
import com.jfinal.template.stat.ast.Break;
|
||||
import com.jfinal.template.stat.ast.Call;
|
||||
import com.jfinal.template.stat.ast.Continue;
|
||||
import com.jfinal.template.stat.ast.Define;
|
||||
import com.jfinal.template.stat.ast.Else;
|
||||
import com.jfinal.template.stat.ast.ElseIf;
|
||||
import com.jfinal.template.stat.ast.For;
|
||||
import com.jfinal.template.stat.ast.If;
|
||||
import com.jfinal.template.stat.ast.Include;
|
||||
import com.jfinal.template.stat.ast.Return;
|
||||
import com.jfinal.template.stat.ast.Set;
|
||||
import com.jfinal.template.stat.ast.SetGlobal;
|
||||
import com.jfinal.template.stat.ast.SetLocal;
|
||||
import com.jfinal.template.stat.ast.Stat;
|
||||
import com.jfinal.template.stat.ast.StatList;
|
||||
import com.jfinal.template.stat.ast.Text;
|
||||
import com.jfinal.template.stat.ast.*;
|
||||
|
||||
/**
|
||||
* DLRD (Double Layer Recursive Descent) Parser
|
||||
@@ -227,7 +212,41 @@ public class Parser {
|
||||
case ELSE:
|
||||
case END:
|
||||
case EOF:
|
||||
case CASE:
|
||||
case DEFAULT:
|
||||
return null;
|
||||
case SWITCH:
|
||||
move();
|
||||
para = matchPara(name);
|
||||
Switch _switch = new Switch(parseExprList(para), getLocation(name.row));
|
||||
|
||||
CaseSetter currentCaseSetter = _switch;
|
||||
for (Token currentToken=peek(); ; currentToken=peek()) {
|
||||
if (currentToken.symbol == Symbol.CASE) {
|
||||
move();
|
||||
para = matchPara(currentToken);
|
||||
statList = statList();
|
||||
Case nextCase = new Case(parseExprList(para), statList, getLocation(currentToken.row));
|
||||
currentCaseSetter.setNextCase(nextCase);
|
||||
currentCaseSetter = nextCase;
|
||||
} else if (currentToken.symbol == Symbol.DEFAULT) {
|
||||
move();
|
||||
statList = statList();
|
||||
Default _default = new Default(statList);
|
||||
_switch.setDefault(_default, getLocation(currentToken.row));
|
||||
} else if (currentToken.symbol == Symbol.TEXT) {
|
||||
TextToken tt = (TextToken)currentToken;
|
||||
if (tt.getContent().toString().trim().length() != 0) {
|
||||
throw new ParseException("Syntax error: expect #case or #default directive", getLocation(currentToken.row));
|
||||
}
|
||||
move();
|
||||
} else {
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
matchEnd(name);
|
||||
return _switch;
|
||||
default :
|
||||
throw new ParseException("Syntax error: can not match the token: " + name.value(), getLocation(name.row));
|
||||
}
|
||||
|
@@ -45,6 +45,10 @@ enum Symbol {
|
||||
BREAK("break", false),
|
||||
RETURN("return", false),
|
||||
|
||||
SWITCH("switch", true),
|
||||
CASE("case", true),
|
||||
DEFAULT("default", false),
|
||||
|
||||
ID("ID", false), // 标识符:下划线或字母开头 ^[A-Za-z_][A-Za-z0-9_]*$
|
||||
PARA("PARA", false),
|
||||
|
||||
@@ -68,6 +72,10 @@ enum Symbol {
|
||||
put(Symbol.CONTINUE.getName(), CONTINUE);
|
||||
put(Symbol.RETURN.getName(), RETURN);
|
||||
|
||||
put(Symbol.SWITCH.getName(), SWITCH);
|
||||
put(Symbol.CASE.getName(), CASE);
|
||||
put(Symbol.DEFAULT.getName(), DEFAULT);
|
||||
|
||||
put(Symbol.DEFINE.getName(), DEFINE);
|
||||
put(Symbol.SET.getName(), SET);
|
||||
put(Symbol.SET_LOCAL.getName(), SET_LOCAL);
|
||||
|
89
src/main/java/com/jfinal/template/stat/ast/Case.java
Normal file
89
src/main/java/com/jfinal/template/stat/ast/Case.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.jfinal.template.stat.ast;
|
||||
|
||||
import com.jfinal.template.Env;
|
||||
import com.jfinal.template.TemplateException;
|
||||
import com.jfinal.template.expr.ast.Expr;
|
||||
import com.jfinal.template.expr.ast.ExprList;
|
||||
import com.jfinal.template.io.Writer;
|
||||
import com.jfinal.template.stat.Location;
|
||||
import com.jfinal.template.stat.ParseException;
|
||||
import com.jfinal.template.stat.Scope;
|
||||
|
||||
/**
|
||||
* Case
|
||||
*/
|
||||
public class Case extends Stat implements CaseSetter {
|
||||
|
||||
private Expr[] exprArray;
|
||||
private Stat stat;
|
||||
private Case nextCase;
|
||||
|
||||
public Case(ExprList exprList, StatList statList, Location location) {
|
||||
if (exprList.length() == 0) {
|
||||
throw new ParseException("The parameter of #case directive can not be blank", location);
|
||||
}
|
||||
|
||||
this.exprArray = exprList.getExprArray();
|
||||
this.stat = statList.getActualStat();
|
||||
}
|
||||
|
||||
public void setNextCase(Case nextCase) {
|
||||
this.nextCase = nextCase;
|
||||
}
|
||||
|
||||
public void exec(Env env, Scope scope, Writer writer) {
|
||||
throw new TemplateException("#case 指令的 exec 不能被调用", location);
|
||||
}
|
||||
|
||||
boolean execIfMatch(Object switchValue, Env env, Scope scope, Writer writer) {
|
||||
if (exprArray.length == 1) {
|
||||
Object value = exprArray[0].eval(scope);
|
||||
|
||||
// 照顾 null == null 以及数值比较小的整型数据比较
|
||||
if (value == switchValue) {
|
||||
stat.exec(env, scope, writer);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value != null && value.equals(switchValue)) {
|
||||
stat.exec(env, scope, writer);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
for (Expr expr : exprArray) {
|
||||
Object value = expr.eval(scope);
|
||||
|
||||
// 照顾 null == null 以及数值比较小的整型数据比较
|
||||
if (value == switchValue) {
|
||||
stat.exec(env, scope, writer);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value != null && value.equals(switchValue)) {
|
||||
stat.exec(env, scope, writer);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nextCase != null ? nextCase.execIfMatch(switchValue, env, scope, writer) : false;
|
||||
}
|
||||
}
|
||||
|
||||
|
24
src/main/java/com/jfinal/template/stat/ast/CaseSetter.java
Normal file
24
src/main/java/com/jfinal/template/stat/ast/CaseSetter.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.jfinal.template.stat.ast;
|
||||
|
||||
/**
|
||||
* CaseSetter
|
||||
*/
|
||||
public interface CaseSetter {
|
||||
public void setNextCase(Case nextCase);
|
||||
}
|
39
src/main/java/com/jfinal/template/stat/ast/Default.java
Normal file
39
src/main/java/com/jfinal/template/stat/ast/Default.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.jfinal.template.stat.ast;
|
||||
|
||||
import com.jfinal.template.Env;
|
||||
import com.jfinal.template.io.Writer;
|
||||
import com.jfinal.template.stat.Scope;
|
||||
|
||||
/**
|
||||
* Default
|
||||
*
|
||||
* #switch 指令内部的 #default 指令
|
||||
*/
|
||||
public class Default extends Stat {
|
||||
|
||||
private Stat stat;
|
||||
|
||||
public Default(StatList statList) {
|
||||
this.stat = statList.getActualStat();
|
||||
}
|
||||
|
||||
public void exec(Env env, Scope scope, Writer writer) {
|
||||
stat.exec(env, scope, writer);
|
||||
}
|
||||
}
|
@@ -69,7 +69,7 @@ public class Include extends Stat {
|
||||
Expr expr = exprList.getExpr(0);
|
||||
if (expr instanceof Const && ((Const)expr).isStr()) {
|
||||
} else {
|
||||
throw new ParseException("The first parameter of #include directive must be String", location);
|
||||
throw new ParseException("The first parameter of #include directive must be String, or use the #render directive", location);
|
||||
}
|
||||
// 其它参数必须为赋值表达式
|
||||
if (len > 1) {
|
||||
|
@@ -71,9 +71,7 @@ public class Output extends Stat {
|
||||
} else if (value != null) {
|
||||
writer.write(value.toString());
|
||||
}
|
||||
} catch (TemplateException e) {
|
||||
throw e;
|
||||
} catch (ParseException e) {
|
||||
} catch(TemplateException | ParseException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new TemplateException(e.getMessage(), location, e);
|
||||
|
111
src/main/java/com/jfinal/template/stat/ast/Switch.java
Normal file
111
src/main/java/com/jfinal/template/stat/ast/Switch.java
Normal file
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2019, James Zhan 詹波 (jfinal@126.com).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.jfinal.template.stat.ast;
|
||||
|
||||
import com.jfinal.template.Env;
|
||||
import com.jfinal.template.expr.ast.Expr;
|
||||
import com.jfinal.template.expr.ast.ExprList;
|
||||
import com.jfinal.template.io.Writer;
|
||||
import com.jfinal.template.stat.Location;
|
||||
import com.jfinal.template.stat.ParseException;
|
||||
import com.jfinal.template.stat.Scope;
|
||||
|
||||
/**
|
||||
* Switch
|
||||
*
|
||||
* #switch 指令与 Java 12 switch 新特性的设计相似: http://openjdk.java.net/jeps/325
|
||||
*
|
||||
* 在与 java 老版本指令基本用法相同的基础上,主要变化与特性有:
|
||||
* 1: 移除 java 语法中的 fall-through semantics,即不需要 break 关键字进行断开
|
||||
* 2: 不引入 #break 指令,代码更少、更优雅
|
||||
* 3: #case 参数可使用多个用逗号分隔的表达式,每个表达式求值后与 #switch 参数求值后比较,
|
||||
* 从根本上消除了 #break 指令的必要性
|
||||
* 4: #case 支持任意类型数据与表达式(java 语言只支持少数常量类型)
|
||||
*
|
||||
* <pre>
|
||||
* 示例:
|
||||
* #switch (month)
|
||||
* #case (1, 3, 5, 7, 8, 10, 12)
|
||||
* #(month) 月有 31 天
|
||||
* #case (2)
|
||||
* #(month) 月平年有28天,闰年有29天
|
||||
* #default
|
||||
* 月份错误: #(month ?? "null")
|
||||
* #end
|
||||
*
|
||||
* 如上代码所示,如果 #case 指令参数有多个值,那么可以用逗号分隔,
|
||||
* 上述逗号表达式的值 1, 3, 5, 7, 8, 10, 12 之中只要有一个与
|
||||
* switch 指令参数 month 相等的话,该 case 分支就会被执行,
|
||||
* 该特性从根本上消灭了 #break 指令的必要性
|
||||
*
|
||||
*
|
||||
* 除了常量值以外 #case 参数还可以是任意表达式
|
||||
* 例如:
|
||||
* #case (a, b, c, x + y, obj.method(z))
|
||||
*
|
||||
* 上述代码中 #case 参数中的所有表达式先会被求值,然后逐一与 #switch
|
||||
* 参数进行对比,同样也是只要有一个对比相等,则该 case 分支就会被执行
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
public class Switch extends Stat implements CaseSetter {
|
||||
|
||||
private Expr expr;
|
||||
private Case nextCase;
|
||||
private Default _default;
|
||||
|
||||
public Switch(ExprList exprList, Location location) {
|
||||
if (exprList.length() == 0) {
|
||||
throw new ParseException("The parameter of #switch directive can not be blank", location);
|
||||
}
|
||||
this.expr = exprList.getActualExpr();
|
||||
}
|
||||
|
||||
public void setNextCase(Case nextCase) {
|
||||
this.nextCase = nextCase;
|
||||
}
|
||||
|
||||
public void setDefault(Default _default, Location location) {
|
||||
if (this._default != null) {
|
||||
throw new ParseException("The #default case of #switch is already defined", location);
|
||||
}
|
||||
this._default = _default;
|
||||
}
|
||||
|
||||
public void exec(Env env, Scope scope, Writer writer) {
|
||||
Object switchValue = expr.eval(scope);
|
||||
|
||||
if (nextCase != null && nextCase.execIfMatch(switchValue, env, scope, writer)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
if (_default != null) {
|
||||
_default.exec(env, scope, writer);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasEnd() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -28,7 +28,3 @@ public class SpringBootConfig {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user