This commit is contained in:
@@ -70,7 +70,7 @@ public class ApiDocs extends HttpBaseServlet {
|
|||||||
actionmap.put("comment", action.comment());
|
actionmap.put("comment", action.comment());
|
||||||
List<Map> paramsList = new ArrayList<>();
|
List<Map> paramsList = new ArrayList<>();
|
||||||
actionmap.put("params", paramsList);
|
actionmap.put("params", paramsList);
|
||||||
for (WebParam param : action.params()) {
|
for (WebParam param : method.getAnnotationsByType(WebParam.class)) {
|
||||||
final Map<String, Object> parammap = new LinkedHashMap<>();
|
final Map<String, Object> parammap = new LinkedHashMap<>();
|
||||||
final boolean isarray = param.type().isArray();
|
final boolean isarray = param.type().isArray();
|
||||||
final Class ptype = isarray ? param.type().getComponentType() : param.type();
|
final Class ptype = isarray ? param.type().getComponentType() : param.type();
|
||||||
|
|||||||
@@ -74,9 +74,10 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
|||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.PARAMETER})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Documented
|
@Documented
|
||||||
|
@Target({METHOD})
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
@Repeatable(WebParams.class)
|
||||||
protected @interface WebParam {
|
protected @interface WebParam {
|
||||||
|
|
||||||
String name(); //参数名
|
String name(); //参数名
|
||||||
@@ -90,6 +91,14 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
|||||||
int radix() default 10; //转换数字byte/short/int/long时所用的进制数, 默认10进制
|
int radix() default 10; //转换数字byte/short/int/long时所用的进制数, 默认10进制
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Documented
|
||||||
|
@Target({METHOD})
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
protected @interface WebParams {
|
||||||
|
|
||||||
|
WebParam[] value();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配合 HttpBaseServlet 使用。
|
* 配合 HttpBaseServlet 使用。
|
||||||
* 用于对@WebServlet对应的url进行细分。 其url必须是包含WebServlet中定义的前缀, 且不能是正则表达式
|
* 用于对@WebServlet对应的url进行细分。 其url必须是包含WebServlet中定义的前缀, 且不能是正则表达式
|
||||||
@@ -99,9 +108,9 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
|||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
@Target({ElementType.METHOD})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Documented
|
@Documented
|
||||||
|
@Target({METHOD})
|
||||||
|
@Retention(RUNTIME)
|
||||||
protected @interface WebAction {
|
protected @interface WebAction {
|
||||||
|
|
||||||
int actionid() default 0;
|
int actionid() default 0;
|
||||||
@@ -112,8 +121,6 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
|||||||
|
|
||||||
String comment() default ""; //备注描述
|
String comment() default ""; //备注描述
|
||||||
|
|
||||||
WebParam[] params() default {};
|
|
||||||
|
|
||||||
String result() default "Object"; //输出结果的数据类型
|
String result() default "Object"; //输出结果的数据类型
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -128,9 +135,9 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
|||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
@Target({ElementType.METHOD})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Documented
|
@Documented
|
||||||
|
@Target({METHOD})
|
||||||
|
@Retention(RUNTIME)
|
||||||
protected @interface HttpCacheable {
|
protected @interface HttpCacheable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ public final class Rest {
|
|||||||
final String cacheDesc = Type.getDescriptor(HttpBaseServlet.HttpCacheable.class);
|
final String cacheDesc = Type.getDescriptor(HttpBaseServlet.HttpCacheable.class);
|
||||||
final String actionDesc = Type.getDescriptor(HttpBaseServlet.WebAction.class);
|
final String actionDesc = Type.getDescriptor(HttpBaseServlet.WebAction.class);
|
||||||
final String webparamDesc = Type.getDescriptor(HttpBaseServlet.WebParam.class);
|
final String webparamDesc = Type.getDescriptor(HttpBaseServlet.WebParam.class);
|
||||||
|
final String webparamsDesc = Type.getDescriptor(HttpBaseServlet.WebParams.class);
|
||||||
final String sourcetypeDesc = Type.getDescriptor(HttpBaseServlet.ParamSourceType.class);
|
final String sourcetypeDesc = Type.getDescriptor(HttpBaseServlet.ParamSourceType.class);
|
||||||
|
|
||||||
final String reqInternalName = Type.getInternalName(HttpRequest.class);
|
final String reqInternalName = Type.getInternalName(HttpRequest.class);
|
||||||
@@ -333,23 +334,6 @@ public final class Rest {
|
|||||||
}
|
}
|
||||||
av1.visitEnd();
|
av1.visitEnd();
|
||||||
|
|
||||||
{
|
|
||||||
AnnotationVisitor av3 = av0.visitArray("params");
|
|
||||||
for (Object[] ps : paramlist) { //{param, n, ptype, radix, comment, annpara, annsid, annaddr, annhead, anncookie}
|
|
||||||
final boolean ishead = ((RestHeader) ps[8]) != null; //是否取getHeader 而不是 getParameter
|
|
||||||
final boolean iscookie = ((RestCookie) ps[9]) != null; //是否取getCookie
|
|
||||||
|
|
||||||
AnnotationVisitor av2 = av3.visitAnnotation(null, webparamDesc);
|
|
||||||
av2.visit("name", (String) ps[1]);
|
|
||||||
av2.visit("type", Type.getType(Type.getDescriptor((Class) ps[2])));
|
|
||||||
av2.visit("radix", (Integer) ps[3]);
|
|
||||||
av2.visitEnum("src", sourcetypeDesc, ishead ? HttpBaseServlet.ParamSourceType.HEADER.name()
|
|
||||||
: (iscookie ? HttpBaseServlet.ParamSourceType.COOKIE.name() : HttpBaseServlet.ParamSourceType.PARAMETER.name()));
|
|
||||||
av2.visit("comment", (String) ps[4]);
|
|
||||||
av2.visitEnd();
|
|
||||||
}
|
|
||||||
av3.visitEnd();
|
|
||||||
}
|
|
||||||
java.lang.reflect.Type grt = method.getGenericReturnType();
|
java.lang.reflect.Type grt = method.getGenericReturnType();
|
||||||
av0.visit("result", grt == returnType ? returnType.getName() : String.valueOf(grt));
|
av0.visit("result", grt == returnType ? returnType.getName() : String.valueOf(grt));
|
||||||
|
|
||||||
@@ -363,6 +347,26 @@ public final class Rest {
|
|||||||
actionMap.put("result", grt == returnType ? returnType.getName() : String.valueOf(grt));
|
actionMap.put("result", grt == returnType ? returnType.getName() : String.valueOf(grt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
av0 = mv.visitAnnotation(webparamsDesc, true);
|
||||||
|
AnnotationVisitor av1 = av0.visitArray("value");
|
||||||
|
//设置 WebParam
|
||||||
|
for (Object[] ps : paramlist) { //{param, n, ptype, radix, comment, annpara, annsid, annaddr, annhead, anncookie}
|
||||||
|
final boolean ishead = ((RestHeader) ps[8]) != null; //是否取getHeader 而不是 getParameter
|
||||||
|
final boolean iscookie = ((RestCookie) ps[9]) != null; //是否取getCookie
|
||||||
|
|
||||||
|
AnnotationVisitor av2 = av1.visitAnnotation(null, webparamDesc);
|
||||||
|
av2.visit("name", (String) ps[1]);
|
||||||
|
av2.visit("type", Type.getType(Type.getDescriptor((Class) ps[2])));
|
||||||
|
av2.visit("radix", (Integer) ps[3]);
|
||||||
|
av2.visitEnum("src", sourcetypeDesc, ishead ? HttpBaseServlet.ParamSourceType.HEADER.name()
|
||||||
|
: (iscookie ? HttpBaseServlet.ParamSourceType.COOKIE.name() : HttpBaseServlet.ParamSourceType.PARAMETER.name()));
|
||||||
|
av2.visit("comment", (String) ps[4]);
|
||||||
|
av2.visitEnd();
|
||||||
|
}
|
||||||
|
av1.visitEnd();
|
||||||
|
av0.visitEnd();
|
||||||
|
}
|
||||||
List<Map<String, Object>> paramMaps = new ArrayList<>();
|
List<Map<String, Object>> paramMaps = new ArrayList<>();
|
||||||
for (Object[] ps : paramlist) {
|
for (Object[] ps : paramlist) {
|
||||||
Map<String, Object> paramMap = new LinkedHashMap<>();
|
Map<String, Object> paramMap = new LinkedHashMap<>();
|
||||||
|
|||||||
@@ -72,6 +72,12 @@ public class AsmMethodVisitor {
|
|||||||
return av;
|
return av;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) {
|
||||||
|
AnnotationVisitor av = visitor.visitTypeAnnotation(typeRef, typePath, desc, visible);
|
||||||
|
if (debug) System.out.println("mv.visitTypeAnnotation(" + typeRef + ", " + typePath + ", \"" + desc + "\", " + visible + ");");
|
||||||
|
return av;
|
||||||
|
}
|
||||||
|
|
||||||
public void visitParameter(String name, int access) {
|
public void visitParameter(String name, int access) {
|
||||||
visitor.visitParameter(name, access);
|
visitor.visitParameter(name, access);
|
||||||
if (debug) System.out.println("mv.visitParameter(" + name + ", " + access + ");");
|
if (debug) System.out.println("mv.visitParameter(" + name + ", " + access + ");");
|
||||||
|
|||||||
Reference in New Issue
Block a user