proxy_class_template.jf 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #--
  2. 生成的源代码格式如下:
  3. package com.xxx;
  4. import com.jfinal.aop.Invocation;
  5. public class Target$$EnhancerByJFinal extends Target {
  6. public String test(String p0, int p1) {
  7. Invocation inv = new Invocation(this, 123L,
  8. args -> {
  9. return super.test(
  10. (String)args[0],
  11. (int)args[1]
  12. );
  13. },
  14. p0, p1);
  15. inv.invoke();
  16. return inv.getReturnValue();
  17. }
  18. }
  19. --#
  20. package #(pkg);
  21. import com.jfinal.aop.Invocation;
  22. public class #(name)#(classTypeVars) extends #(targetName)#(targetTypeVars) {
  23. #for(x : methodList)
  24. public #(x.methodTypeVars) #(x.returnType) #(x.name)(#for(y : x.paraTypes)#(y) p#(for.index)#(for.last ? "" : ", ")#end) #(x.throws){
  25. #if(x.singleArrayPara)
  26. #@newInvocationForSingleArrayPara()
  27. #else
  28. #@newInvocationForCommon()
  29. #end
  30. inv.invoke();
  31. #if (x.returnType != "void")
  32. return inv.getReturnValue();
  33. #end
  34. }
  35. #end
  36. }
  37. #--
  38. 一般参数情况
  39. --#
  40. #define newInvocationForCommon()
  41. Invocation inv = new Invocation(this, #(x.proxyMethodKey)L,
  42. args -> {
  43. #(x.frontReturn) #(name).super.#(x.name)(
  44. #for(y : x.paraTypes)
  45. (#(y.replace("...", "[]")))args[#(for.index)]#(for.last ? "" : ",")
  46. #end
  47. );
  48. #(x.backReturn)
  49. }
  50. #for(y : x.paraTypes), p#(for.index)#end);
  51. #end
  52. #--
  53. 只有一个参数,且该参数是数组或者可变参数
  54. --#
  55. #define newInvocationForSingleArrayPara()
  56. Invocation inv = new Invocation(this, #(x.proxyMethodKey)L,
  57. args -> {
  58. #(x.frontReturn) #(name).super.#(x.name)(
  59. p0
  60. );
  61. #(x.backReturn)
  62. }
  63. , p0);
  64. #end