【特性】新增 cfg java_json 支持
【重构】Render不再从ThreadStatic里获得Template,改从CocurrentDictionary中获取 【优化】优化 cfg java_bin 代码,不再从AbstraceBean继承,并且美化代码。main
parent
d296c57f93
commit
216bdee29d
|
|
@ -52,6 +52,8 @@ namespace Luban.Job.Cfg.Defs
|
||||||
|
|
||||||
public string OutputDataFile => FullName;
|
public string OutputDataFile => FullName;
|
||||||
|
|
||||||
|
public string InnerName => "_" + this.Name;
|
||||||
|
|
||||||
public string OutputDataFileEscapeDot => FullName.Replace('.', '_');
|
public string OutputDataFileEscapeDot => FullName.Replace('.', '_');
|
||||||
|
|
||||||
public List<string> GetBranchInputFiles(string branchName)
|
public List<string> GetBranchInputFiles(string branchName)
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,18 @@ namespace Luban.Job.Cfg.Defs
|
||||||
return type.Apply(JavaDeserializeVisitor.Ins, bufName, fieldName);
|
return type.Apply(JavaDeserializeVisitor.Ins, bufName, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string JavaJsonDeserialize(string jsonName, string fieldName, string jsonFieldName, TType type)
|
||||||
|
{
|
||||||
|
if (type.IsNullable)
|
||||||
|
{
|
||||||
|
return $"{{ if ({jsonName}.has(\"{jsonFieldName}\") && !{jsonName}.get(\"{jsonFieldName}\").isJsonNull()) {{ {type.Apply(TypeVisitors.JavaJsonDeserialize.Ins, $"{jsonName}.get(\"{jsonFieldName}\")", fieldName)} }} else {{ {fieldName} = null; }} }}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return type.Apply(TypeVisitors.JavaJsonDeserialize.Ins, $"{jsonName}.get(\"{jsonFieldName}\")", fieldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static string JavaRecursiveResolve(DefField field, string tables)
|
public static string JavaRecursiveResolve(DefField field, string tables)
|
||||||
{
|
{
|
||||||
return field.CType.Apply(JavaRecursiveResolveVisitor.Ins, field.JavaStyleName, tables);
|
return field.CType.Apply(JavaRecursiveResolveVisitor.Ins, field.JavaStyleName, tables);
|
||||||
|
|
|
||||||
|
|
@ -24,29 +24,23 @@ namespace Luban.Job.Cfg.Generate
|
||||||
return $"{b.CppNamespaceBegin} class {b.Name}; {b.CppNamespaceEnd} ";
|
return $"{b.CppNamespaceBegin} class {b.Name}; {b.CppNamespaceEnd} ";
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cpp_bin/bean"));
|
var template = StringTemplateUtil.GetTemplate("config/cpp_bin/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cpp_bin/table"));
|
var template = StringTemplateUtil.GetTemplate("config/cpp_bin/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_serviceRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cpp_bin/tables"));
|
var template = StringTemplateUtil.GetTemplate("config/cpp_bin/tables");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
@ -55,11 +49,9 @@ namespace Luban.Job.Cfg.Generate
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_stubRender;
|
|
||||||
public string RenderStub(string topModule, List<DefTypeBase> types)
|
public string RenderStub(string topModule, List<DefTypeBase> types)
|
||||||
{
|
{
|
||||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cpp_bin/stub"));
|
var template = StringTemplateUtil.GetTemplate("config/cpp_bin/stub");
|
||||||
return template.RenderCode(new
|
return template.RenderCode(new
|
||||||
{
|
{
|
||||||
TopModule = topModule,
|
TopModule = topModule,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class EditorCppRender : CodeRenderBase
|
class CppEditorRender : CodeRenderBase
|
||||||
{
|
{
|
||||||
public override string Render(DefConst c)
|
public override string Render(DefConst c)
|
||||||
{
|
{
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class UE4BpCppRender : CodeRenderBase
|
class CppUE4BpRender : CodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_enumRender;
|
private static Template t_enumRender;
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class UE4EditorCppRender : CodeRenderBase
|
class CppUE4EditorRender : CodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
private static Template t_enumRender;
|
private static Template t_enumRender;
|
||||||
|
|
@ -8,30 +8,23 @@ namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class CsCodeBinRender : CsCodeRenderBase
|
class CsCodeBinRender : CsCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
|
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_bin/bean"));
|
var template = StringTemplateUtil.GetTemplate("config/cs_bin/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_bin/table"));
|
var template = StringTemplateUtil.GetTemplate("config/cs_bin/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_serviceRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_bin/tables"));
|
var template = StringTemplateUtil.GetTemplate("config/cs_bin/tables");
|
||||||
var result = template.RenderCode(new
|
var result = template.RenderCode(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -8,32 +8,25 @@ namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class CsCodeJsonRender : CsCodeRenderBase
|
class CsCodeJsonRender : CsCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_json/bean"));
|
var template = StringTemplateUtil.GetTemplate("config/cs_json/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_json/table"));
|
var template = StringTemplateUtil.GetTemplate("config/cs_json/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_serviceRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_json/tables"));
|
var template = StringTemplateUtil.GetTemplate("config/cs_json/tables");
|
||||||
var result = template.RenderCode(new
|
var result = template.RenderCode(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -8,31 +8,25 @@ namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class CsCodeUnityJsonRender : CsCodeRenderBase
|
class CsCodeUnityJsonRender : CsCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_unity_json/bean"));
|
var template = StringTemplateUtil.GetTemplate("config/cs_unity_json/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_unity_json/table"));
|
var template = StringTemplateUtil.GetTemplate("config/cs_unity_json/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_serviceRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_unity_json/tables"));
|
var template = StringTemplateUtil.GetTemplate("config/cs_unity_json/tables");
|
||||||
var result = template.RenderCode(new
|
var result = template.RenderCode(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -8,33 +8,27 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Generate
|
namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class EditorCsRender : CsCodeRenderBase
|
class CsEditorRender : CsCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_editor_json/bean"));
|
var template = StringTemplateUtil.GetTemplate("config/cs_editor_json/bean");
|
||||||
var result = template.Render(b);
|
var result = template.Render(b);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_editor_json/table"));
|
var template = StringTemplateUtil.GetTemplate("config/cs_editor_json/table");
|
||||||
var result = template.Render(p);
|
var result = template.Render(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_stubRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/cs_editor_json/tables"));
|
var template = StringTemplateUtil.GetTemplate("config/cs_editor_json/tables");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
@ -9,35 +9,29 @@ namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class GoCodeBinRender : GoCodeRenderBase
|
class GoCodeBinRender : GoCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
|
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/go_bin/bean"));
|
var template = StringTemplateUtil.GetTemplate("config/go_bin/bean");
|
||||||
var result = template.RenderCode(b, new Dictionary<string, object>() { ["package"] = package });
|
var result = template.RenderCode(b, new Dictionary<string, object>() { ["package"] = package });
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
// TODO 目前只有普通表支持多态. 单例表和双key表都不支持
|
// TODO 目前只有普通表支持多态. 单例表和双key表都不支持
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/go_bin/table"));
|
var template = StringTemplateUtil.GetTemplate("config/go_bin/table");
|
||||||
var result = template.RenderCode(p, new Dictionary<string, object>() { ["package"] = package });
|
var result = template.RenderCode(p, new Dictionary<string, object>() { ["package"] = package });
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_serviceRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
|
|
||||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/go_bin/tables"));
|
var template = StringTemplateUtil.GetTemplate("config/go_bin/tables");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -9,37 +9,31 @@ namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class GoCodeJsonRender : GoCodeRenderBase
|
class GoCodeJsonRender : GoCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
|
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/go_json/bean"));
|
var template = StringTemplateUtil.GetTemplate("config/go_json/bean");
|
||||||
var result = template.RenderCode(b, new Dictionary<string, object>() { ["package"] = package });
|
var result = template.RenderCode(b, new Dictionary<string, object>() { ["package"] = package });
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
// TODO 目前只有普通表支持多态. 单例表和双key表都不支持
|
// TODO 目前只有普通表支持多态. 单例表和双key表都不支持
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/go_json/table"));
|
var template = StringTemplateUtil.GetTemplate("config/go_json/table");
|
||||||
var result = template.RenderCode(p, new Dictionary<string, object>() { ["package"] = package });
|
var result = template.RenderCode(p, new Dictionary<string, object>() { ["package"] = package });
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_serviceRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
|
|
||||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/go_json/tables"));
|
var template = StringTemplateUtil.GetTemplate("config/go_json/tables");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -12,24 +12,18 @@ namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
abstract class GoCodeRenderBase : CodeRenderBase
|
abstract class GoCodeRenderBase : CodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_constRender;
|
|
||||||
|
|
||||||
public override string Render(DefConst c)
|
public override string Render(DefConst c)
|
||||||
{
|
{
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
var template = t_constRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/go/const"));
|
var template = StringTemplateUtil.GetTemplate("common/go/const");
|
||||||
var result = template.RenderCode(c, new Dictionary<string, object>() { ["package"] = package });
|
var result = template.RenderCode(c, new Dictionary<string, object>() { ["package"] = package });
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_enumRender;
|
|
||||||
|
|
||||||
public override string Render(DefEnum e)
|
public override string Render(DefEnum e)
|
||||||
{
|
{
|
||||||
string package = "cfg";
|
string package = "cfg";
|
||||||
var template = t_enumRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/go/enum"));
|
var template = StringTemplateUtil.GetTemplate("common/go/enum");
|
||||||
var result = template.RenderCode(e, new Dictionary<string, object>() { ["package"] = package });
|
var result = template.RenderCode(e, new Dictionary<string, object>() { ["package"] = package });
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,32 +9,25 @@ namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class JavaCodeBinRender : JavaCodeRenderBase
|
class JavaCodeBinRender : JavaCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
|
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/java_bin/bean"));
|
var template = StringTemplateUtil.GetTemplate("config/java_bin/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/java_bin/table"));
|
var template = StringTemplateUtil.GetTemplate("config/java_bin/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_serviceRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/java_bin/tables"));
|
var template = StringTemplateUtil.GetTemplate("config/java_bin/tables");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
using Luban.Job.Cfg.Defs;
|
||||||
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Utils;
|
||||||
|
using Scriban;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.Generate
|
||||||
|
{
|
||||||
|
class JavaCodeJsonRender : JavaCodeRenderBase
|
||||||
|
{
|
||||||
|
public override string Render(DefBean b)
|
||||||
|
{
|
||||||
|
var template = StringTemplateUtil.GetTemplate("config/java_json/bean");
|
||||||
|
var result = template.RenderCode(b);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Render(DefTable p)
|
||||||
|
{
|
||||||
|
var template = StringTemplateUtil.GetTemplate("config/java_json/table");
|
||||||
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
|
{
|
||||||
|
var template = StringTemplateUtil.GetTemplate("config/java_json/tables");
|
||||||
|
var result = template.Render(new
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
Package = module,
|
||||||
|
Tables = tables,
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,15 +10,15 @@ namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class LuaCodeBinRender : LuaCodeRenderBase
|
class LuaCodeBinRender : LuaCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_allRender;
|
|
||||||
public override string RenderAll(List<DefTypeBase> types)
|
public override string RenderAll(List<DefTypeBase> types)
|
||||||
{
|
{
|
||||||
var consts = types.Where(t => t is DefConst).ToList();
|
var consts = types.Where(t => t is DefConst).ToList();
|
||||||
var enums = types.Where(t => t is DefEnum).ToList();
|
var enums = types.Where(t => t is DefEnum).ToList();
|
||||||
var beans = types.Where(t => t is DefBean).ToList();
|
var beans = types.Where(t => t is DefBean).ToList();
|
||||||
var tables = types.Where(t => t is DefTable).ToList();
|
var tables = types.Where(t => t is DefTable).ToList();
|
||||||
var template = t_allRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/lua/base") + StringTemplateUtil.GetTemplateString("config/lua_bin/all"));
|
var template = StringTemplateUtil.GetOrAddTemplate("common/lua/base_all", fn =>
|
||||||
|
Template.Parse(StringTemplateUtil.GetTemplateString("common/lua/base")
|
||||||
|
+ StringTemplateUtil.GetTemplateString("config/lua_bin/all")));
|
||||||
return template.RenderCode(new { Consts = consts, Enums = enums, Beans = beans, Tables = tables });
|
return template.RenderCode(new { Consts = consts, Enums = enums, Beans = beans, Tables = tables });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,21 +7,17 @@ namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class Python3CodeJsonRender : PythonCodeRenderBase
|
class Python3CodeJsonRender : PythonCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/python_json/bean"));
|
var template = StringTemplateUtil.GetTemplate("config/python_json/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/python_json/table"));
|
var template = StringTemplateUtil.GetTemplate("config/python_json/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,9 @@ namespace Luban.Job.Cfg.Generate
|
||||||
return RenderUtil.RenderPythonEnumClass(e);
|
return RenderUtil.RenderPythonEnumClass(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_serviceRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/python_json/tables"));
|
var template = StringTemplateUtil.GetTemplate("config/python_json/tables");
|
||||||
var result = template.RenderCode(new
|
var result = template.RenderCode(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -9,31 +9,25 @@ namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class TypescriptCodeBinRender : TypescriptCodeRenderBase
|
class TypescriptCodeBinRender : TypescriptCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/typescript_bin/bean"));
|
var template = StringTemplateUtil.GetTemplate("config/typescript_bin/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/typescript_bin/table"));
|
var template = StringTemplateUtil.GetTemplate("config/typescript_bin/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_serviceRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/typescript_bin/tables"));
|
var template = StringTemplateUtil.GetTemplate("config/typescript_bin/tables");
|
||||||
var result = template.RenderCode(new
|
var result = template.RenderCode(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -9,31 +9,25 @@ namespace Luban.Job.Cfg.Generate
|
||||||
{
|
{
|
||||||
class TypescriptCodeJsonRender : TypescriptCodeRenderBase
|
class TypescriptCodeJsonRender : TypescriptCodeRenderBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
public override string Render(DefBean b)
|
public override string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/typescript_json/bean"));
|
var template = StringTemplateUtil.GetTemplate("config/typescript_json/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public override string Render(DefTable p)
|
public override string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/typescript_json/table"));
|
var template = StringTemplateUtil.GetTemplate("config/typescript_json/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_serviceRender;
|
|
||||||
public override string RenderService(string name, string module, List<DefTable> tables)
|
public override string RenderService(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_serviceRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("config/typescript_json/tables"));
|
var template = StringTemplateUtil.GetTemplate("config/typescript_json/tables");
|
||||||
var result = template.RenderCode(new
|
var result = template.RenderCode(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Luban.Job.Cfg
|
||||||
[Option("output_data_json_monolithic_file", Required = false, HelpText = "output monolithic json file")]
|
[Option("output_data_json_monolithic_file", Required = false, HelpText = "output monolithic json file")]
|
||||||
public string OutputDataJsonMonolithicFile { get; set; }
|
public string OutputDataJsonMonolithicFile { get; set; }
|
||||||
|
|
||||||
[Option("gen_types", Required = true, HelpText = "code_cs_bin,code_cs_json,code_cs_unity_json,code_lua_bin,code_java_bin,code_go_bin,code_go_json,code_cpp_bin,code_python3_json,code_typescript_bin,code_typescript_json,data_bin,data_lua,data_json,data_json2,data_json_monolithic,data_resources . can be multi")]
|
[Option("gen_types", Required = true, HelpText = "code_cs_bin,code_cs_json,code_cs_unity_json,code_lua_bin,code_java_bin,code_java_json,code_go_bin,code_go_json,code_cpp_bin,code_python3_json,code_typescript_bin,code_typescript_json,data_bin,data_lua,data_json,data_json2,data_json_monolithic,data_resources . can be multi")]
|
||||||
public string GenType { get; set; }
|
public string GenType { get; set; }
|
||||||
|
|
||||||
[Option('s', "service", Required = true, HelpText = "service")]
|
[Option('s', "service", Required = true, HelpText = "service")]
|
||||||
|
|
@ -82,6 +82,7 @@ namespace Luban.Job.Cfg
|
||||||
case "code_cs_json": return new CsCodeJsonRender();
|
case "code_cs_json": return new CsCodeJsonRender();
|
||||||
case "code_cs_unity_json": return new CsCodeUnityJsonRender();
|
case "code_cs_unity_json": return new CsCodeUnityJsonRender();
|
||||||
case "code_java_bin": return new JavaCodeBinRender();
|
case "code_java_bin": return new JavaCodeBinRender();
|
||||||
|
case "code_java_json": return new JavaCodeJsonRender();
|
||||||
case "code_go_bin": return new GoCodeBinRender();
|
case "code_go_bin": return new GoCodeBinRender();
|
||||||
case "code_go_json": return new GoCodeJsonRender();
|
case "code_go_json": return new GoCodeJsonRender();
|
||||||
case "code_cpp_bin": return new CppCodeBinRender();
|
case "code_cpp_bin": return new CppCodeBinRender();
|
||||||
|
|
@ -90,9 +91,9 @@ namespace Luban.Job.Cfg
|
||||||
case "code_python3_json": return new Python3CodeJsonRender();
|
case "code_python3_json": return new Python3CodeJsonRender();
|
||||||
case "code_typescript_bin": return new TypescriptCodeBinRender();
|
case "code_typescript_bin": return new TypescriptCodeBinRender();
|
||||||
case "code_typescript_json": return new TypescriptCodeJsonRender();
|
case "code_typescript_json": return new TypescriptCodeJsonRender();
|
||||||
case "code_cpp_ue_editor": return new UE4EditorCppRender();
|
case "code_cpp_ue_editor": return new CppUE4EditorRender();
|
||||||
case "code_cpp_ue_bp": return new UE4BpCppRender();
|
case "code_cpp_ue_bp": return new CppUE4BpRender();
|
||||||
case "code_cs_unity_editor": return new EditorCsRender();
|
case "code_cs_unity_editor": return new CsEditorRender();
|
||||||
default: throw new ArgumentException($"not support gen type:{genType}");
|
default: throw new ArgumentException($"not support gen type:{genType}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -103,9 +104,9 @@ namespace Luban.Job.Cfg
|
||||||
{
|
{
|
||||||
case "code_cs_bin":
|
case "code_cs_bin":
|
||||||
case "code_cs_json":
|
case "code_cs_json":
|
||||||
case "code_cs_unity_json":
|
case "code_cs_unity_json": return ELanguage.CS;
|
||||||
return ELanguage.CS;
|
case "code_java_bin":
|
||||||
case "code_java_bin": return ELanguage.JAVA;
|
case "code_java_json": return ELanguage.JAVA;
|
||||||
case "code_go_bin":
|
case "code_go_bin":
|
||||||
case "code_go_json": return ELanguage.GO;
|
case "code_go_json": return ELanguage.GO;
|
||||||
case "code_cpp_bin": return ELanguage.CPP;
|
case "code_cpp_bin": return ELanguage.CPP;
|
||||||
|
|
@ -339,6 +340,7 @@ namespace Luban.Job.Cfg
|
||||||
case "code_cs_json":
|
case "code_cs_json":
|
||||||
case "code_cs_unity_json":
|
case "code_cs_unity_json":
|
||||||
case "code_java_bin":
|
case "code_java_bin":
|
||||||
|
case "code_java_json":
|
||||||
case "code_go_bin":
|
case "code_go_bin":
|
||||||
case "code_go_json":
|
case "code_go_json":
|
||||||
{
|
{
|
||||||
|
|
@ -406,8 +408,7 @@ namespace Luban.Job.Cfg
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
s_logger.Error("unknown gentype:{gentype}", genType);
|
throw new Exception($"unknown gentype:{genType}");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -693,7 +694,7 @@ namespace {ctx.TopModule}
|
||||||
|
|
||||||
private void GenCppUeEditor(GenContext ctx)
|
private void GenCppUeEditor(GenContext ctx)
|
||||||
{
|
{
|
||||||
var render = new UE4EditorCppRender();
|
var render = new CppUE4EditorRender();
|
||||||
|
|
||||||
var renderTypes = ctx.Assembly.Types.Values.Where(c => c is DefEnum || c is DefBean).ToList();
|
var renderTypes = ctx.Assembly.Types.Values.Where(c => c is DefEnum || c is DefBean).ToList();
|
||||||
|
|
||||||
|
|
@ -728,7 +729,7 @@ namespace {ctx.TopModule}
|
||||||
|
|
||||||
private void GenCsUnityEditor(GenContext ctx)
|
private void GenCsUnityEditor(GenContext ctx)
|
||||||
{
|
{
|
||||||
var render = new EditorCsRender();
|
var render = new CsEditorRender();
|
||||||
foreach (var c in ctx.Assembly.Types.Values)
|
foreach (var c in ctx.Assembly.Types.Values)
|
||||||
{
|
{
|
||||||
ctx.Tasks.Add(Task.Run(() =>
|
ctx.Tasks.Add(Task.Run(() =>
|
||||||
|
|
@ -743,7 +744,7 @@ namespace {ctx.TopModule}
|
||||||
|
|
||||||
private void GenCppUeBp(GenContext ctx)
|
private void GenCppUeBp(GenContext ctx)
|
||||||
{
|
{
|
||||||
var render = new UE4BpCppRender();
|
var render = new CppUE4BpRender();
|
||||||
foreach (var c in ctx.ExportTypes)
|
foreach (var c in ctx.ExportTypes)
|
||||||
{
|
{
|
||||||
if (!(c is DefEnum || c is DefBean))
|
if (!(c is DefEnum || c is DefBean))
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,133 @@
|
||||||
|
using Luban.Job.Common.Types;
|
||||||
|
using Luban.Job.Common.TypeVisitors;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
{
|
||||||
|
class JavaJsonDeserialize : ITypeFuncVisitor<string, string, string>
|
||||||
|
{
|
||||||
|
public static JavaJsonDeserialize Ins { get; } = new();
|
||||||
|
|
||||||
|
public string Accept(TBool type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsBoolean();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TByte type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsByte();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TShort type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsShort();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TFshort type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsShort();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TInt type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsInt();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TFint type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsInt();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TLong type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsLong();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TFlong type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsLong();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TFloat type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsFloat();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TDouble type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsDouble();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TEnum type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {type.DefineEnum.FullNameWithTopModule}.valueOf({json}.getAsInt());";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TString type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsString();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TBytes type, string json, string x)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TText type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsString();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TBean type, string json, string x)
|
||||||
|
{
|
||||||
|
if (type.IsDynamic)
|
||||||
|
{
|
||||||
|
return $"{x} = {type.Bean.FullNameWithTopModule}.deserialize{type.Bean.Name}({json}.getAsJsonObject());";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $"{x} = new {type.Bean.FullNameWithTopModule}({json}.getAsJsonObject());";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TArray type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{{ var _json0_ = {json}.getAsJsonArray(); int _n = _json0_.size(); {x} = new {type.ElementType.Apply(JavaDefineTypeName.Ins)}[_n]; int _index=0; for(JsonElement __e : _json0_) {{ {type.ElementType.Apply(JavaDefineTypeName.Ins)} __v; {type.ElementType.Apply(this, "__e", "__v")} {x}[_index++] = __v; }} }}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TList type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{{ var _json0_ = {json}.getAsJsonArray(); {x} = new {type.Apply(JavaDefineTypeName.Ins)}(_json0_.size()); for(JsonElement __e : _json0_) {{ {type.ElementType.Apply(JavaDefineTypeName.Ins)} __v; {type.ElementType.Apply(this, "__e", "__v")} {x}.add(__v); }} }}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TSet type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{{ var _json0_ = {json}.getAsJsonArray(); {x} = new {type.Apply(JavaDefineTypeName.Ins)}(_json0_.size()); for(JsonElement __e : _json0_) {{ {type.ElementType.Apply(JavaDefineTypeName.Ins)} __v; {type.ElementType.Apply(this, "__e", "__v")} {x}.add(__v); }} }}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TMap type, string json, string x)
|
||||||
|
{
|
||||||
|
return @$"{{ var _json0_ = {json}.getAsJsonArray(); {x} = new {type.Apply(JavaDefineTypeName.Ins)}(_json0_.size()); for(JsonElement __e : _json0_) {{ {type.KeyType.Apply(JavaDefineTypeName.Ins)} __k; {type.KeyType.Apply(this, "__e.getAsJsonArray().get(0)", "__k")} {type.ValueType.Apply(JavaDefineTypeName.Ins)} __v; {type.ValueType.Apply(this, "__e.getAsJsonArray().get(1)", "__v")} {x}.put(__k, __v); }} }}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TVector2 type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{{ var _json0_ = {json}.getAsJsonObject(); float __x; {TFloat.Ins.Apply(this, "_json0_.get(\"x\")", "__x") } float __y; {TFloat.Ins.Apply(this, "_json0_.get(\"y\")", "__y") } {x} = new {type.Apply(JavaDefineTypeName.Ins)}(__x, __y); }}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TVector3 type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{{ var _json0_ = {json}.getAsJsonObject(); float __x; {TFloat.Ins.Apply(this, "_json0_.get(\"x\")", "__x") } float __y; {TFloat.Ins.Apply(this, "_json0_.get(\"y\")", "__y") } float __z; {TFloat.Ins.Apply(this, "_json0_.get(\"z\")", "__z") } {x} = new {type.Apply(JavaDefineTypeName.Ins)}(__x, __y,__z); }}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TVector4 type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{{ var _json0_ = {json}.getAsJsonObject(); float __x; {TFloat.Ins.Apply(this, "_json0_.get(\"x\")", "__x") } float __y; {TFloat.Ins.Apply(this, "_json0_.get(\"y\")", "__y") } float __z; {TFloat.Ins.Apply(this, "_json0_.get(\"z\")", "__z") } float __w; {TFloat.Ins.Apply(this, "_json0_.get(\"w\")", "__w") } {x} = new {type.Apply(JavaDefineTypeName.Ins)}(__x, __y, __z, __w); }}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Accept(TDateTime type, string json, string x)
|
||||||
|
{
|
||||||
|
return $"{x} = {json}.getAsInt();";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -79,7 +79,14 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
|
||||||
public string Accept(TBean type, string bufName, string fieldName)
|
public string Accept(TBean type, string bufName, string fieldName)
|
||||||
{
|
{
|
||||||
return $"{fieldName} = {type.Bean.FullNameWithTopModule}.deserialize{type.Bean.Name}({bufName});";
|
if (type.IsDynamic)
|
||||||
|
{
|
||||||
|
return $"{fieldName} = {type.Bean.FullNameWithTopModule}.deserialize{type.Bean.Name}({bufName});";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $"{fieldName} = new {type.Bean.FullNameWithTopModule}({bufName});";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Accept(TArray type, string bufName, string fieldName)
|
public string Accept(TArray type, string bufName, string fieldName)
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ namespace Luban.Job.Common.Utils
|
||||||
{
|
{
|
||||||
public static class RenderUtil
|
public static class RenderUtil
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_constRender;
|
|
||||||
public static string RenderCsConstClass(DefConst c)
|
public static string RenderCsConstClass(DefConst c)
|
||||||
{
|
{
|
||||||
var ctx = new TemplateContext();
|
var ctx = new TemplateContext();
|
||||||
|
|
@ -17,24 +15,20 @@ namespace Luban.Job.Common.Utils
|
||||||
};
|
};
|
||||||
ctx.PushGlobal(env);
|
ctx.PushGlobal(env);
|
||||||
|
|
||||||
var template = t_constRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/cs/const"));
|
var template = StringTemplateUtil.GetTemplate("common/cs/const");
|
||||||
var result = template.Render(ctx);
|
var result = template.Render(ctx);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_enumRender;
|
|
||||||
public static string RenderCsEnumClass(DefEnum e)
|
public static string RenderCsEnumClass(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = t_enumRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/cs/enum"));
|
var template = StringTemplateUtil.GetTemplate("common/cs/enum");
|
||||||
var result = template.Render(e);
|
var result = template.Render(e);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_javaConstRender;
|
|
||||||
public static string RenderJavaConstClass(DefConst c)
|
public static string RenderJavaConstClass(DefConst c)
|
||||||
{
|
{
|
||||||
var ctx = new TemplateContext();
|
var ctx = new TemplateContext();
|
||||||
|
|
@ -45,24 +39,20 @@ namespace Luban.Job.Common.Utils
|
||||||
ctx.PushGlobal(env);
|
ctx.PushGlobal(env);
|
||||||
|
|
||||||
|
|
||||||
var template = t_javaConstRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/java/const"));
|
var template = StringTemplateUtil.GetTemplate("common/java/const");
|
||||||
var result = template.Render(ctx);
|
var result = template.Render(ctx);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_javaEnumRender;
|
|
||||||
public static string RenderJavaEnumClass(DefEnum e)
|
public static string RenderJavaEnumClass(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = t_javaEnumRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/java/enum"));
|
var template = StringTemplateUtil.GetTemplate("common/java/enum");
|
||||||
var result = template.Render(e);
|
var result = template.Render(e);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_cppConstRender;
|
|
||||||
public static string RenderCppConstClass(DefConst c)
|
public static string RenderCppConstClass(DefConst c)
|
||||||
{
|
{
|
||||||
var ctx = new TemplateContext();
|
var ctx = new TemplateContext();
|
||||||
|
|
@ -73,22 +63,18 @@ namespace Luban.Job.Common.Utils
|
||||||
ctx.PushGlobal(env);
|
ctx.PushGlobal(env);
|
||||||
|
|
||||||
|
|
||||||
var template = t_cppConstRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/cpp/const"));
|
var template = StringTemplateUtil.GetTemplate("common/cpp/const");
|
||||||
var result = template.Render(ctx);
|
var result = template.Render(ctx);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_cppEnumRender;
|
|
||||||
public static string RenderCppEnumClass(DefEnum e)
|
public static string RenderCppEnumClass(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = t_cppEnumRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/cpp/enum"));
|
var template = StringTemplateUtil.GetTemplate("common/cpp/enum");
|
||||||
var result = template.Render(e);
|
var result = template.Render(e);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_pythonConstRender;
|
|
||||||
public static string RenderPythonConstClass(DefConst c)
|
public static string RenderPythonConstClass(DefConst c)
|
||||||
{
|
{
|
||||||
var ctx = new TemplateContext();
|
var ctx = new TemplateContext();
|
||||||
|
|
@ -99,24 +85,20 @@ namespace Luban.Job.Common.Utils
|
||||||
ctx.PushGlobal(env);
|
ctx.PushGlobal(env);
|
||||||
|
|
||||||
|
|
||||||
var template = t_pythonConstRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/python/const"));
|
var template = StringTemplateUtil.GetTemplate("common/python/const");
|
||||||
var result = template.Render(ctx);
|
var result = template.Render(ctx);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_pythonEnumRender;
|
|
||||||
public static string RenderPythonEnumClass(DefEnum e)
|
public static string RenderPythonEnumClass(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = t_pythonEnumRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/python/enum"));
|
var template = StringTemplateUtil.GetTemplate("common/python/enum");
|
||||||
var result = template.Render(e);
|
var result = template.Render(e);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tsConstRender;
|
|
||||||
public static string RenderTypescriptConstClass(DefConst c)
|
public static string RenderTypescriptConstClass(DefConst c)
|
||||||
{
|
{
|
||||||
var ctx = new TemplateContext();
|
var ctx = new TemplateContext();
|
||||||
|
|
@ -127,17 +109,15 @@ namespace Luban.Job.Common.Utils
|
||||||
ctx.PushGlobal(env);
|
ctx.PushGlobal(env);
|
||||||
|
|
||||||
|
|
||||||
var template = t_tsConstRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/typescript/const"));
|
var template = StringTemplateUtil.GetTemplate("common/typescript/const");
|
||||||
var result = template.Render(ctx);
|
var result = template.Render(ctx);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tsEnumRender;
|
|
||||||
public static string RenderTypescriptEnumClass(DefEnum e)
|
public static string RenderTypescriptEnumClass(DefEnum e)
|
||||||
{
|
{
|
||||||
var template = t_tsEnumRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("common/typescript/enum"));
|
var template = StringTemplateUtil.GetTemplate("common/typescript/enum");
|
||||||
var result = template.Render(e);
|
var result = template.Render(e);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
using System;
|
using Scriban;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -15,5 +17,17 @@ namespace Luban.Job.Common.Utils
|
||||||
{
|
{
|
||||||
return File.ReadAllText($"{TemplateDir}/{templateName}.tpl", Encoding.UTF8);
|
return File.ReadAllText($"{TemplateDir}/{templateName}.tpl", Encoding.UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly ConcurrentDictionary<string, Template> s_templates = new();
|
||||||
|
|
||||||
|
public static Template GetTemplate(string templateName)
|
||||||
|
{
|
||||||
|
return s_templates.GetOrAdd(templateName, tn => Template.Parse(GetTemplateString(tn)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Template GetOrAddTemplate(string templateName, Func<string, Template> creator)
|
||||||
|
{
|
||||||
|
return s_templates.GetOrAdd(templateName, creator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,30 +31,24 @@ namespace Luban.Job.Db.Generate
|
||||||
return RenderUtil.RenderCsEnumClass(e);
|
return RenderUtil.RenderCsEnumClass(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
public string Render(DefBean b)
|
public string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/cs_async/bean"));
|
var template = StringTemplateUtil.GetTemplate("db/cs_async/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public string Render(DefTable p)
|
public string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/cs_async/table"));
|
var template = StringTemplateUtil.GetTemplate("db/cs_async/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_stubRender;
|
|
||||||
public string RenderTables(string name, string module, List<DefTable> tables)
|
public string RenderTables(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/cs_async/tables"));
|
var template = StringTemplateUtil.GetTemplate("db/cs_async/tables");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -31,30 +31,24 @@ namespace Luban.Job.Db.Generate
|
||||||
return RenderUtil.RenderCsEnumClass(e);
|
return RenderUtil.RenderCsEnumClass(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
public string Render(DefBean b)
|
public string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/cs_sync/bean"));
|
var template = StringTemplateUtil.GetTemplate("db/cs_sync/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public string Render(DefTable p)
|
public string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/cs_sync/table"));
|
var template = StringTemplateUtil.GetTemplate("db/cs_sync/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_stubRender;
|
|
||||||
public string RenderTables(string name, string module, List<DefTable> tables)
|
public string RenderTables(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/cs_sync/tables"));
|
var template = StringTemplateUtil.GetTemplate("db/cs_sync/tables");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -33,30 +33,25 @@ namespace Luban.Job.Db.Generate
|
||||||
{
|
{
|
||||||
return RenderUtil.RenderTypescriptEnumClass(e);
|
return RenderUtil.RenderTypescriptEnumClass(e);
|
||||||
}
|
}
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
public string Render(DefBean b)
|
public string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/typescript/bean"));
|
var template = StringTemplateUtil.GetTemplate("db/typescript/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_tableRender;
|
|
||||||
public string Render(DefTable p)
|
public string Render(DefTable p)
|
||||||
{
|
{
|
||||||
var template = t_tableRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/typescript/table"));
|
var template = StringTemplateUtil.GetTemplate("db/typescript/table");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_stubRender;
|
|
||||||
public string RenderTables(string name, string module, List<DefTable> tables)
|
public string RenderTables(string name, string module, List<DefTable> tables)
|
||||||
{
|
{
|
||||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("db/typescript/tables"));
|
var template = StringTemplateUtil.GetTemplate("db/typescript/tables");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -33,41 +33,33 @@ namespace Luban.Job.Proto.Generate
|
||||||
return RenderUtil.RenderCsEnumClass(e);
|
return RenderUtil.RenderCsEnumClass(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
private string Render(DefBean b)
|
private string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/cs/bean"));
|
var template = StringTemplateUtil.GetTemplate("proto/cs/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_protoRender;
|
|
||||||
private string Render(DefProto p)
|
private string Render(DefProto p)
|
||||||
{
|
{
|
||||||
var template = t_protoRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/cs/proto"));
|
var template = StringTemplateUtil.GetTemplate("proto/cs/proto");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_rpcRender;
|
|
||||||
private string Render(DefRpc r)
|
private string Render(DefRpc r)
|
||||||
{
|
{
|
||||||
var template = t_rpcRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/cs/rpc"));
|
var template = StringTemplateUtil.GetTemplate("proto/cs/rpc");
|
||||||
var result = template.RenderCode(r);
|
var result = template.RenderCode(r);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_stubRender;
|
|
||||||
public string RenderStubs(string name, string module, List<DefTypeBase> protos, List<DefTypeBase> rpcs)
|
public string RenderStubs(string name, string module, List<DefTypeBase> protos, List<DefTypeBase> rpcs)
|
||||||
{
|
{
|
||||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/cs/stub"));
|
var template = StringTemplateUtil.GetTemplate("proto/cs/stub");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,6 @@ namespace Luban.Job.Proto.Generate
|
||||||
{
|
{
|
||||||
class LuaRender
|
class LuaRender
|
||||||
{
|
{
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_allRender;
|
|
||||||
public string RenderTypes(List<DefTypeBase> types)
|
public string RenderTypes(List<DefTypeBase> types)
|
||||||
{
|
{
|
||||||
var consts = types.Where(t => t is DefConst).ToList();
|
var consts = types.Where(t => t is DefConst).ToList();
|
||||||
|
|
@ -20,7 +17,7 @@ namespace Luban.Job.Proto.Generate
|
||||||
var beans = types.Where(t => t is DefBean).ToList();
|
var beans = types.Where(t => t is DefBean).ToList();
|
||||||
var protos = types.Where(t => t is DefProto).ToList();
|
var protos = types.Where(t => t is DefProto).ToList();
|
||||||
var rpcs = types.Where(t => t is DefRpc).ToList();
|
var rpcs = types.Where(t => t is DefRpc).ToList();
|
||||||
var template = t_allRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/lua/all"));
|
var template = StringTemplateUtil.GetTemplate("proto/lua/all");
|
||||||
return template.RenderCode(new { Consts = consts, Enums = enums, Beans = beans, Protos = protos, Rpcs = rpcs });
|
return template.RenderCode(new { Consts = consts, Enums = enums, Beans = beans, Protos = protos, Rpcs = rpcs });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,41 +36,33 @@ namespace Luban.Job.Proto.Generate
|
||||||
return RenderUtil.RenderTypescriptEnumClass(e);
|
return RenderUtil.RenderTypescriptEnumClass(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_beanRender;
|
|
||||||
private string Render(DefBean b)
|
private string Render(DefBean b)
|
||||||
{
|
{
|
||||||
var template = t_beanRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/typescript/bean"));
|
var template = StringTemplateUtil.GetTemplate("proto/typescript/bean");
|
||||||
var result = template.RenderCode(b);
|
var result = template.RenderCode(b);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_protoRender;
|
|
||||||
private string Render(DefProto p)
|
private string Render(DefProto p)
|
||||||
{
|
{
|
||||||
var template = t_protoRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/typescript/proto"));
|
var template = StringTemplateUtil.GetTemplate("proto/typescript/proto");
|
||||||
var result = template.RenderCode(p);
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_rpcRender;
|
|
||||||
private string Render(DefRpc r)
|
private string Render(DefRpc r)
|
||||||
{
|
{
|
||||||
var template = t_rpcRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/typescript/rpc"));
|
var template = StringTemplateUtil.GetTemplate("proto/typescript/rpc");
|
||||||
var result = template.RenderCode(r);
|
var result = template.RenderCode(r);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
|
||||||
private static Template t_stubRender;
|
|
||||||
public string RenderStubs(string name, string module, List<DefTypeBase> protos, List<DefTypeBase> rpcs)
|
public string RenderStubs(string name, string module, List<DefTypeBase> protos, List<DefTypeBase> rpcs)
|
||||||
{
|
{
|
||||||
var template = t_stubRender ??= Template.Parse(StringTemplateUtil.GetTemplateString("proto/typescript/stub"));
|
var template = StringTemplateUtil.GetTemplate("proto/typescript/stub");
|
||||||
var result = template.Render(new
|
var result = template.Render(new
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,15 @@
|
||||||
<None Update="Templates\config\java_bin\tables.tpl">
|
<None Update="Templates\config\java_bin\tables.tpl">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="Templates\config\java_json\bean.tpl">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Templates\config\java_json\table.tpl">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Templates\config\java_json\tables.tpl">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Update="Templates\config\lua_bin\all.tpl">
|
<None Update="Templates\config\lua_bin\all.tpl">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@ package {{x.namespace_with_top_module}};
|
||||||
* {{x.comment}}
|
* {{x.comment}}
|
||||||
*/
|
*/
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
public final class {{x.name}}
|
public final class {{x.name}} {
|
||||||
{
|
|
||||||
{{~ for item in x.items ~}}
|
{{~ for item in x.items ~}}
|
||||||
{{~if item.comment != '' ~}}
|
{{~if item.comment != '' ~}}
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ package {{namespace_with_top_module}};
|
||||||
* {{comment}}
|
* {{comment}}
|
||||||
*/
|
*/
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
public enum {{name}}
|
public enum {{name}} {
|
||||||
{
|
|
||||||
{{~ for item in items ~}}
|
{{~ for item in items ~}}
|
||||||
{{~if item.comment != '' ~}}
|
{{~if item.comment != '' ~}}
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,54 +14,45 @@ import bright.serialization.*;
|
||||||
* {{x.comment}}
|
* {{x.comment}}
|
||||||
*/
|
*/
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
public {{x.java_class_modifier}} class {{name}} extends {{if parent_def_type}} {{x.parent_def_type.full_name_with_top_module}} {{else}} bright.serialization.AbstractBean {{end}}
|
public {{x.java_class_modifier}} class {{name}}{{if parent_def_type}} extends {{x.parent_def_type.full_name_with_top_module}}{{end}} {
|
||||||
{
|
public {{name}}(ByteBuf _buf) {
|
||||||
public {{name}}(ByteBuf _buf)
|
|
||||||
{
|
|
||||||
{{~if parent_def_type~}}
|
{{~if parent_def_type~}}
|
||||||
super(_buf);
|
super(_buf);
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
{{~ for field in export_fields ~}}
|
{{~ for field in export_fields ~}}
|
||||||
{{java_deserialize '_buf' field.java_style_name field.ctype}}
|
{{java_deserialize '_buf' field.java_style_name field.ctype}}
|
||||||
{{~if field.index_field~}}
|
{{~if field.index_field~}}
|
||||||
for({{java_box_define_type field.ctype.element_type}} _v : {{field.java_style_name}})
|
for({{java_box_define_type field.ctype.element_type}} _v : {{field.java_style_name}}) {
|
||||||
{
|
|
||||||
{{field.java_style_name}}_Index.put(_v.{{field.index_field.java_style_name}}, _v);
|
{{field.java_style_name}}_Index.put(_v.{{field.index_field.java_style_name}}, _v);
|
||||||
}
|
}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
}
|
}
|
||||||
|
|
||||||
public {{name}}({{- for field in hierarchy_export_fields }}{{java_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}})
|
public {{name}}({{- for field in hierarchy_export_fields }}{{java_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}}) {
|
||||||
{
|
|
||||||
{{~if parent_def_type~}}
|
{{~if parent_def_type~}}
|
||||||
super({{ for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}}, {{end}}{{end}});
|
super({{ for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}}, {{end}}{{end}});
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
{{~ for field in export_fields ~}}
|
{{~ for field in export_fields ~}}
|
||||||
this.{{field.java_style_name}} = {{field.name}};
|
this.{{field.java_style_name}} = {{field.name}};
|
||||||
{{~if field.index_field~}}
|
{{~if field.index_field~}}
|
||||||
for({{java_box_define_type field.ctype.element_type}} _v : {{field.java_style_name}})
|
for({{java_box_define_type field.ctype.element_type}} _v : {{field.java_style_name}}) {
|
||||||
{
|
|
||||||
{{field.java_style_name}}_Index.put(_v.{{field.index_field.java_style_name}}, _v);
|
{{field.java_style_name}}_Index.put(_v.{{field.index_field.java_style_name}}, _v);
|
||||||
}
|
}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static {{name}} deserialize{{name}}(ByteBuf _buf)
|
|
||||||
{
|
|
||||||
{{~if x.is_abstract_type~}}
|
{{~if x.is_abstract_type~}}
|
||||||
switch (_buf.readInt())
|
public static {{name}} deserialize{{name}}(ByteBuf _buf) {
|
||||||
{
|
switch (_buf.readInt()) {
|
||||||
{{~for child in x.hierarchy_not_abstract_children~}}
|
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||||
case {{child.full_name_with_top_module}}.ID: return new {{child.full_name_with_top_module}}(_buf);
|
case {{child.full_name_with_top_module}}.ID: return new {{child.full_name_with_top_module}}(_buf);
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
default: throw new SerializationException();
|
default: throw new SerializationException();
|
||||||
}
|
}
|
||||||
{{~else~}}
|
|
||||||
return new {{name}}(_buf);
|
|
||||||
{{~end~}}
|
|
||||||
}
|
}
|
||||||
|
{{~end~}}
|
||||||
|
|
||||||
{{~ for field in export_fields ~}}
|
{{~ for field in export_fields ~}}
|
||||||
{{~if field.comment != '' ~}}
|
{{~if field.comment != '' ~}}
|
||||||
|
|
@ -78,42 +69,33 @@ public {{x.java_class_modifier}} class {{name}} extends {{if parent_def_type}} {
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
{{~if !x.is_abstract_type~}}
|
{{~if !x.is_abstract_type && x.parent_def_type~}}
|
||||||
public static final int ID = {{x.id}};
|
public static final int ID = {{x.id}};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTypeId() { return ID; }
|
public int getTypeId() { return ID; }
|
||||||
|
{{~else if x.is_abstract_type && !x.parent_def_type~}}
|
||||||
|
public abstract int getTypeId();
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
|
{{~if parent_def_type~}}
|
||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf os)
|
{{~end~}}
|
||||||
{
|
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deserialize(ByteBuf os)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void resolve(java.util.HashMap<String, Object> _tables)
|
|
||||||
{
|
|
||||||
{{~if parent_def_type~}}
|
{{~if parent_def_type~}}
|
||||||
super.resolve(_tables);
|
super.resolve(_tables);
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
{{~ for field in export_fields ~}}
|
{{~ for field in export_fields ~}}
|
||||||
{{~if field.gen_ref~}}
|
{{~if field.gen_ref~}}
|
||||||
{{java_ref_validator_resolve field}}
|
{{java_ref_validator_resolve field}}
|
||||||
{{~else if field.has_recursive_ref~}}
|
{{~else if field.has_recursive_ref~}}
|
||||||
{{java_recursive_resolve field '_tables'}}
|
{{java_recursive_resolve field '_tables'}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
return "{{full_name}}{ "
|
return "{{full_name}}{ "
|
||||||
{{~for field in hierarchy_export_fields ~}}
|
{{~for field in hierarchy_export_fields ~}}
|
||||||
+ "{{field.java_style_name}}:" + {{java_to_string field.java_style_name field.ctype}} + ","
|
+ "{{field.java_style_name}}:" + {{java_to_string field.java_style_name field.ctype}} + ","
|
||||||
|
|
|
||||||
|
|
@ -15,19 +15,16 @@ import bright.serialization.*;
|
||||||
* {{x.comment}}
|
* {{x.comment}}
|
||||||
*/
|
*/
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
public final class {{name}}
|
public final class {{name}} {
|
||||||
{
|
|
||||||
{{~if x.is_map_table ~}}
|
{{~if x.is_map_table ~}}
|
||||||
private final java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}> _dataMap;
|
private final java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}> _dataMap;
|
||||||
private final java.util.ArrayList<{{java_box_define_type value_type}}> _dataList;
|
private final java.util.ArrayList<{{java_box_define_type value_type}}> _dataList;
|
||||||
|
|
||||||
public {{name}}(ByteBuf _buf)
|
public {{name}}(ByteBuf _buf) {
|
||||||
{
|
|
||||||
_dataMap = new java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}>();
|
_dataMap = new java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}>();
|
||||||
_dataList = new java.util.ArrayList<{{java_box_define_type value_type}}>();
|
_dataList = new java.util.ArrayList<{{java_box_define_type value_type}}>();
|
||||||
|
|
||||||
for(int n = _buf.readSize() ; n > 0 ; --n)
|
for(int n = _buf.readSize() ; n > 0 ; --n) {
|
||||||
{
|
|
||||||
{{java_box_define_type value_type}} _v;
|
{{java_box_define_type value_type}} _v;
|
||||||
{{java_deserialize '_buf' '_v' value_type}}
|
{{java_deserialize '_buf' '_v' value_type}}
|
||||||
_dataList.add(_v);
|
_dataList.add(_v);
|
||||||
|
|
@ -44,10 +41,8 @@ public final class {{name}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
public {{java_box_define_type value_type}} get({{java_define_type key_type}} key) { return _dataMap.get(key); }
|
public {{java_box_define_type value_type}} get({{java_define_type key_type}} key) { return _dataMap.get(key); }
|
||||||
|
|
||||||
public void resolve(java.util.HashMap<String, Object> _tables)
|
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||||
{
|
for({{java_box_define_type value_type}} v : _dataList) {
|
||||||
for({{java_box_define_type value_type}} v : _dataList)
|
|
||||||
{
|
|
||||||
v.resolve(_tables);
|
v.resolve(_tables);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -57,8 +52,7 @@ public final class {{name}}
|
||||||
|
|
||||||
public final {{java_define_type value_type}} data() { return _data; }
|
public final {{java_define_type value_type}} data() { return _data; }
|
||||||
|
|
||||||
public {{name}}(ByteBuf _buf)
|
public {{name}}(ByteBuf _buf) {
|
||||||
{
|
|
||||||
int n = _buf.readSize();
|
int n = _buf.readSize();
|
||||||
if (n != 1) throw new SerializationException("table mode=one, but size != 1");
|
if (n != 1) throw new SerializationException("table mode=one, but size != 1");
|
||||||
{{java_deserialize '_buf' '_data' value_type}}
|
{{java_deserialize '_buf' '_data' value_type}}
|
||||||
|
|
@ -74,10 +68,8 @@ public final class {{name}}
|
||||||
public {{java_define_type field.ctype}} {{field.java_getter_name}}() { return _data.{{field.java_style_name}}; }
|
public {{java_define_type field.ctype}} {{field.java_getter_name}}() { return _data.{{field.java_style_name}}; }
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
public void resolve(java.util.HashMap<String, Object> _tables)
|
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||||
{
|
|
||||||
_data.resolve(_tables);
|
_data.resolve(_tables);
|
||||||
}
|
}
|
||||||
|
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
}
|
}
|
||||||
|
|
@ -14,18 +14,19 @@ public final class {{name}}
|
||||||
* {{table.comment}}
|
* {{table.comment}}
|
||||||
*/
|
*/
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
public final {{table.full_name_with_top_module}} {{table.name}};
|
private final {{table.full_name_with_top_module}} {{table.inner_name}};
|
||||||
|
public {{table.full_name_with_top_module}} get{{table.name}}() { return {{table.inner_name}}; }
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
public {{name}}(IByteBufLoader loader) throws java.io.IOException {
|
public {{name}}(IByteBufLoader loader) throws java.io.IOException {
|
||||||
var tables = new java.util.HashMap<String, Object>();
|
var tables = new java.util.HashMap<String, Object>();
|
||||||
{{~for table in tables ~}}
|
{{~for table in tables ~}}
|
||||||
{{table.name}} = new {{table.full_name_with_top_module}}(loader.load("{{table.output_data_file}}"));
|
{{table.inner_name}} = new {{table.full_name_with_top_module}}(loader.load("{{table.output_data_file}}"));
|
||||||
tables.put("{{table.full_name}}", {{table.name}});
|
tables.put("{{table.full_name}}", {{table.inner_name}});
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
{{~ for table in tables ~}}
|
{{~ for table in tables ~}}
|
||||||
{{table.name}}.resolve(tables);
|
{{table.inner_name}}.resolve(tables);
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
package {{x.namespace_with_top_module}};
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
{{
|
||||||
|
name = x.name
|
||||||
|
parent_def_type = x.parent_def_type
|
||||||
|
export_fields = x.export_fields
|
||||||
|
hierarchy_export_fields = x.hierarchy_export_fields
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{~if x.comment != '' ~}}
|
||||||
|
/**
|
||||||
|
* {{x.comment}}
|
||||||
|
*/
|
||||||
|
{{~end~}}
|
||||||
|
public {{x.java_class_modifier}} class {{name}}{{if parent_def_type}} extends {{x.parent_def_type.full_name_with_top_module}}{{end}} {
|
||||||
|
public {{name}}(JsonObject __json__) {
|
||||||
|
{{~if parent_def_type~}}
|
||||||
|
super(__json__);
|
||||||
|
{{~end~}}
|
||||||
|
{{~ for field in export_fields ~}}
|
||||||
|
{{java_json_deserialize '__json__' field.java_style_name field.name field.ctype}}
|
||||||
|
{{~if field.index_field~}}
|
||||||
|
for({{java_box_define_type field.ctype.element_type}} _v : {{field.java_style_name}}) {
|
||||||
|
{{field.java_style_name}}_Index.put(_v.{{field.index_field.java_style_name}}, _v);
|
||||||
|
}
|
||||||
|
{{~end~}}
|
||||||
|
{{~end~}}
|
||||||
|
}
|
||||||
|
|
||||||
|
public {{name}}({{- for field in hierarchy_export_fields }}{{java_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}}) {
|
||||||
|
{{~if parent_def_type~}}
|
||||||
|
super({{ for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}}, {{end}}{{end}});
|
||||||
|
{{~end~}}
|
||||||
|
{{~ for field in export_fields ~}}
|
||||||
|
this.{{field.java_style_name}} = {{field.name}};
|
||||||
|
{{~if field.index_field~}}
|
||||||
|
for({{java_box_define_type field.ctype.element_type}} _v : {{field.java_style_name}}) {
|
||||||
|
{{field.java_style_name}}_Index.put(_v.{{field.index_field.java_style_name}}, _v);
|
||||||
|
}
|
||||||
|
{{~end~}}
|
||||||
|
{{~end~}}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static {{name}} deserialize{{name}}(JsonObject __json__) {
|
||||||
|
{{~if x.is_abstract_type~}}
|
||||||
|
switch (__json__.get("__type__").getAsString()) {
|
||||||
|
{{~for child in x.hierarchy_not_abstract_children~}}
|
||||||
|
case "{{child.name}}": return new {{child.full_name_with_top_module}}(__json__);
|
||||||
|
{{~end~}}
|
||||||
|
default: throw new bright.serialization.SerializationException();
|
||||||
|
}
|
||||||
|
{{~else~}}
|
||||||
|
return new {{name}}(__json__);
|
||||||
|
{{~end~}}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{~ for field in export_fields ~}}
|
||||||
|
{{~if field.comment != '' ~}}
|
||||||
|
/**
|
||||||
|
* {{field.comment}}
|
||||||
|
*/
|
||||||
|
{{~end~}}
|
||||||
|
public final {{java_define_type field.ctype}} {{field.java_style_name}};
|
||||||
|
{{~if field.index_field~}}
|
||||||
|
public final java.util.HashMap<{{java_box_define_type field.index_field.ctype}}, {{java_box_define_type field.ctype.element_type}}> {{field.java_style_name}}_Index = new java.util.HashMap<>();
|
||||||
|
{{~end~}}
|
||||||
|
{{~if field.gen_ref~}}
|
||||||
|
public {{field.java_ref_validator_define}}
|
||||||
|
{{~end~}}
|
||||||
|
{{~end~}}
|
||||||
|
|
||||||
|
{{~if !x.is_abstract_type && x.parent_def_type~}}
|
||||||
|
public static final int ID = {{x.id}};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTypeId() { return ID; }
|
||||||
|
{{~else if x.is_abstract_type && !x.parent_def_type~}}
|
||||||
|
public abstract int getTypeId();
|
||||||
|
{{~end~}}
|
||||||
|
|
||||||
|
{{~if parent_def_type~}}
|
||||||
|
@Override
|
||||||
|
{{~end~}}
|
||||||
|
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||||
|
{{~if parent_def_type~}}
|
||||||
|
super.resolve(_tables);
|
||||||
|
{{~end~}}
|
||||||
|
{{~ for field in export_fields ~}}
|
||||||
|
{{~if field.gen_ref~}}
|
||||||
|
{{java_ref_validator_resolve field}}
|
||||||
|
{{~else if field.has_recursive_ref~}}
|
||||||
|
{{java_recursive_resolve field '_tables'}}
|
||||||
|
{{~end~}}
|
||||||
|
{{~end~}}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{{full_name}}{ "
|
||||||
|
{{~for field in hierarchy_export_fields ~}}
|
||||||
|
+ "{{field.java_style_name}}:" + {{java_to_string field.java_style_name field.ctype}} + ","
|
||||||
|
{{~end~}}
|
||||||
|
+ "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
package {{x.namespace_with_top_module}};
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
|
||||||
|
{{~
|
||||||
|
name = x.name
|
||||||
|
key_type = x.key_ttype
|
||||||
|
key_type1 = x.key_ttype1
|
||||||
|
key_type2 = x.key_ttype2
|
||||||
|
value_type = x.value_ttype
|
||||||
|
~}}
|
||||||
|
|
||||||
|
{{~if x.comment != '' ~}}
|
||||||
|
/**
|
||||||
|
* {{x.comment}}
|
||||||
|
*/
|
||||||
|
{{~end~}}
|
||||||
|
public final class {{name}} {
|
||||||
|
{{~if x.is_map_table ~}}
|
||||||
|
private final java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}> _dataMap;
|
||||||
|
private final java.util.ArrayList<{{java_box_define_type value_type}}> _dataList;
|
||||||
|
|
||||||
|
public {{name}}(JsonElement __json__) {
|
||||||
|
_dataMap = new java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}>();
|
||||||
|
_dataList = new java.util.ArrayList<{{java_box_define_type value_type}}>();
|
||||||
|
|
||||||
|
for(var _e_ : __json__.getAsJsonArray()) {
|
||||||
|
{{java_box_define_type value_type}} _v;
|
||||||
|
{{java_deserialize '_e_.getAsJsonObject()' '_v' value_type}}
|
||||||
|
_dataList.add(_v);
|
||||||
|
_dataMap.put(_v.{{x.index_field.java_style_name}}, _v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public java.util.HashMap<{{java_box_define_type key_type}}, {{java_box_define_type value_type}}> getDataMap() { return _dataMap; }
|
||||||
|
public java.util.ArrayList<{{java_box_define_type value_type}}> getDataList() { return _dataList; }
|
||||||
|
|
||||||
|
{{~if value_type.is_dynamic~}}
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T extends {{java_box_define_type value_type}}> T getAs({{java_define_type key_type}} key) { return (T)_dataMap.get(key); }
|
||||||
|
{{~end~}}
|
||||||
|
public {{java_box_define_type value_type}} get({{java_define_type key_type}} key) { return _dataMap.get(key); }
|
||||||
|
|
||||||
|
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||||
|
for({{java_box_define_type value_type}} v : _dataList) {
|
||||||
|
v.resolve(_tables);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{~else~}}
|
||||||
|
private final {{java_define_type value_type}} _data;
|
||||||
|
|
||||||
|
public final {{java_define_type value_type}} data() { return _data; }
|
||||||
|
|
||||||
|
public {{name}}(JsonElement __json__) {
|
||||||
|
int n = __json__.getAsJsonArray().size();
|
||||||
|
if (n != 1) throw new bright.serialization.SerializationException("table mode=one, but size != 1");
|
||||||
|
{{java_deserialize '__json__.getAsJsonArray().get(0).getAsJsonObject()' '_data' value_type}}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||||
|
{{~if field.comment != '' ~}}
|
||||||
|
/**
|
||||||
|
* {{field.comment}}
|
||||||
|
*/
|
||||||
|
{{~end~}}
|
||||||
|
public {{java_define_type field.ctype}} {{field.java_getter_name}}() { return _data.{{field.java_style_name}}; }
|
||||||
|
{{~end~}}
|
||||||
|
|
||||||
|
public void resolve(java.util.HashMap<String, Object> _tables) {
|
||||||
|
_data.resolve(_tables);
|
||||||
|
}
|
||||||
|
|
||||||
|
{{~end~}}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package {{package}};
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
|
||||||
|
public final class {{name}}
|
||||||
|
{
|
||||||
|
public interface IJsonLoader {
|
||||||
|
JsonElement load(String file) throws java.io.IOException;
|
||||||
|
}
|
||||||
|
|
||||||
|
{{~for table in tables ~}}
|
||||||
|
{{~if table.comment != '' ~}}
|
||||||
|
/**
|
||||||
|
* {{table.comment}}
|
||||||
|
*/
|
||||||
|
{{~end~}}
|
||||||
|
private final {{table.full_name_with_top_module}} {{table.inner_name}};
|
||||||
|
public {{table.full_name_with_top_module}} get{{table.name}}() { return {{table.inner_name}}; }
|
||||||
|
{{~end~}}
|
||||||
|
|
||||||
|
public {{name}}(IJsonLoader loader) throws java.io.IOException {
|
||||||
|
var tables = new java.util.HashMap<String, Object>();
|
||||||
|
{{~for table in tables ~}}
|
||||||
|
{{table.inner_name}} = new {{table.full_name_with_top_module}}(loader.load("{{table.output_data_file}}"));
|
||||||
|
tables.put("{{table.full_name}}", {{table.inner_name}});
|
||||||
|
{{~end~}}
|
||||||
|
|
||||||
|
{{~ for table in tables ~}}
|
||||||
|
{{table.inner_name}}.resolve(tables);
|
||||||
|
{{~end~}}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue