浏览代码

jfinal 4.2

James 6 年之前
父节点
当前提交
156757f769

+ 1 - 1
src/main/java/com/jfinal/core/Const.java

@@ -23,7 +23,7 @@ import com.jfinal.render.ViewType;
  */
 public interface Const {
 	
-	String JFINAL_VERSION = "4.1";
+	String JFINAL_VERSION = "4.2";
 	
 	ViewType DEFAULT_VIEW_TYPE = ViewType.JFINAL_TEMPLATE;
 	

+ 1 - 1
src/main/java/com/jfinal/proxy/Callback.java

@@ -21,7 +21,7 @@ package com.jfinal.proxy;
  */
 @FunctionalInterface
 public interface Callback {
-	public Object call(Object[] args);
+	public Object call(Object[] args) throws Exception;
 }
 
 

+ 25 - 0
src/main/java/com/jfinal/proxy/ProxyGenerator.java

@@ -90,6 +90,7 @@ public class ProxyGenerator {
 			method.set("methodTypeVars", getTypeVars(m.getTypeParameters()));
 			method.set("returnType", getReturnType(m));
 			method.set("name", m.getName());
+			method.set("throws", getThrows(m));
 			
 			Parameter[] paras = m.getParameters();
 			List<String> paraTypes = Arrays.asList(paras).stream().map(
@@ -180,6 +181,9 @@ public class ProxyGenerator {
 		return method.getGenericReturnType().getTypeName();
 	}
 	
+	/**
+	 * 获取子类泛型变量,也可用于获取方法泛型变量
+	 */
 	@SuppressWarnings("rawtypes")
 	protected String getTypeVars(TypeVariable[] typeVars) {
 		if (typeVars == null|| typeVars.length == 0) {
@@ -220,6 +224,8 @@ public class ProxyGenerator {
 	}
 	
 	/**
+	 * 获取父类泛型变量
+	 * 
 	 * 相对于 getTypeVars(...) 取消了 TypeVariable.getBounds() 内容的生成,否则编译错误
 	 */
 	@SuppressWarnings("rawtypes")
@@ -241,6 +247,25 @@ public class ProxyGenerator {
 	}
 	
 	/**
+	 * 获取方法抛出的异常
+	 */
+	protected String getThrows(Method method) {
+		Class<?>[] throwTypes = method.getExceptionTypes();
+		if (throwTypes == null || throwTypes.length == 0) {
+			return null;
+		}
+		
+		StringBuilder ret = new StringBuilder().append("throws ");
+		for (int i=0; i<throwTypes.length; i++) {
+			if (i > 0) {
+				ret.append(", ");
+			}
+			ret.append(throwTypes[i].getName());
+		}
+		return ret.append(' ').toString();
+	}
+	
+	/**
 	 * 跳过不能代理的方法
 	 * 1:非 public
 	 * 2:final、static、abstract

+ 1 - 1
src/main/java/com/jfinal/proxy/proxy_class_template.jf

@@ -27,7 +27,7 @@ import com.jfinal.aop.Invocation;
 public class #(name)#(classTypeVars) extends #(targetName)#(targetTypeVars) {
 #for(x : methodList)
 	
-	public #(x.methodTypeVars) #(x.returnType) #(x.name)(#for(y : x.paraTypes)#(y) p#(for.index)#(for.last ? "" : ", ")#end) {
+	public #(x.methodTypeVars) #(x.returnType) #(x.name)(#for(y : x.paraTypes)#(y) p#(for.index)#(for.last ? "" : ", ")#end) #(x.throws){
 		#if(x.onlyVarArgs)
 		#@newInvocationForOnlyVarArgs()
 		#else