初始化工程

This commit is contained in:
2025-07-15 15:33:35 +08:00
parent ead49da3e8
commit bbd78128d0
301 changed files with 23953 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
{{~if __namespace_with_top_module != ''~}}
package {{__namespace_with_top_module}};
{{~end~}}
import luban.*;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
{{~
parent_def_type = __this.parent_def_type
export_fields = __this.export_fields
hierarchy_export_fields = __this.hierarchy_export_fields
~}}
{{~if __this.comment != '' ~}}
/**
* {{escape_comment __this.comment}}
*/
{{~end~}}
public {{class_modifier __this}} class {{__name}} extends {{if parent_def_type}}{{__this.parent_def_type.full_name_with_top_module}}{{else}}AbstractBean{{end}} {
public {{__name}}(JsonObject _buf) {
{{~if parent_def_type~}}
super(_buf);
{{~end~}}
{{~ for field in export_fields ~}}
{{deserialize_field (format_field_name __code_style field.name) '_buf' field.name field.ctype}}
{{~end~}}
}
public static {{__name}} deserialize(JsonObject _buf) {
{{~if __this.is_abstract_type~}}
switch (_buf.get("$type").getAsString()) {
{{~for child in __this.hierarchy_not_abstract_children~}}
case "{{impl_data_type child __this}}": return new {{child.full_name_with_top_module}}(_buf);
{{~end~}}
default: throw new SerializationException();
}
{{~else~}}
return new {{__this.full_name_with_top_module}}(_buf);
{{~end~}}
}
{{~ for field in export_fields ~}}
{{~if field.comment != '' ~}}
/**
* {{escape_comment field.comment}}
*/
{{~end~}}
public final {{declaring_type_name field.ctype}} {{format_field_name __code_style field.name}};
{{~end~}}
{{~if !__this.is_abstract_type~}}
public static final int __ID__ = {{__this.id}};
@Override
public int getTypeId() { return __ID__; }
{{~end~}}
@Override
public String toString() {
return "{{full_name}}{ "
{{~for field in hierarchy_export_fields ~}}
+ "{{format_field_name __code_style field.name}}:" + {{format_field_name __code_style field.name}} + ","
{{~end~}}
+ "}";
}
}

View File

@@ -0,0 +1,82 @@
{{~if __namespace_with_top_module != ''~}}
package {{__namespace_with_top_module}};
{{~end~}}
import luban.*;
import com.google.gson.JsonElement;
{{~if __this.comment != '' ~}}
/**
* {{escape_comment __this.comment}}
*/
{{~end~}}
public final class {{__name}} {
{{~if __this.is_map_table
key_type = __this.key_ttype
~}}
private final java.util.HashMap<{{declaring_box_type_name key_type}}, {{declaring_box_type_name __value_type}}> _dataMap;
private final java.util.ArrayList<{{declaring_box_type_name __value_type}}> _dataList;
public {{__name}}(JsonElement _buf) {
_dataMap = new java.util.HashMap<{{declaring_box_type_name key_type}}, {{declaring_box_type_name __value_type}}>();
_dataList = new java.util.ArrayList<{{declaring_box_type_name __value_type}}>();
for (com.google.gson.JsonElement _e_ : _buf.getAsJsonArray()) {
{{declaring_box_type_name __value_type}} _v;
{{deserialize '_v' '_e_' __value_type}}
_dataList.add(_v);
_dataMap.put(_v.{{format_field_name __code_style __this.index_field.name}}, _v);
}
}
public java.util.HashMap<{{declaring_box_type_name key_type}}, {{declaring_box_type_name __value_type}}> getDataMap() { return _dataMap; }
public java.util.ArrayList<{{declaring_box_type_name __value_type}}> getDataList() { return _dataList; }
{{~if __value_type.is_dynamic~}}
@SuppressWarnings("unchecked")
public <T extends {{declaring_box_type_name __value_type}}> T getAs({{declaring_type_name key_type}} key) { return (T)_dataMap.get(key); }
{{~end~}}
public {{declaring_box_type_name __value_type}} get({{declaring_type_name key_type}} key) { return _dataMap.get(key); }
{{~else if __this.is_list_table ~}}
private final java.util.ArrayList<{{declaring_box_type_name __value_type}}> _dataList;
public {{__name}}(JsonElement _buf) {
_dataList = new java.util.ArrayList<{{declaring_box_type_name __value_type}}>();
for (com.google.gson.JsonElement _e_ : _buf.getAsJsonArray()) {
{{declaring_box_type_name __value_type}} _v;
{{deserialize '_v' '_e_' __value_type}}
_dataList.add(_v);
}
}
public java.util.ArrayList<{{declaring_box_type_name __value_type}}> getDataList() { return _dataList; }
public {{declaring_box_type_name __value_type}} get(int index) { return _dataList.get(index); }
{{~else~}}
private final {{declaring_type_name __value_type}} _data;
public final {{declaring_type_name __value_type}} data() { return _data; }
public {{__name}}(JsonElement _buf) {
int n = _buf.getAsJsonArray().size();
if (n != 1) throw new SerializationException("table mode=one, but size != 1");
{{deserialize '_data' '_buf.getAsJsonArray().get(0).getAsJsonObject()' __value_type}}
}
{{~ for field in __value_type.def_bean.hierarchy_export_fields ~}}
{{~if field.comment != '' ~}}
/**
* {{escape_comment field.comment}}
*/
{{~end~}}
public {{declaring_type_name field.ctype}} {{getter_name field.name}}() { return _data.{{format_field_name __code_style field.name}}; }
{{~end~}}
{{~end~}}
}

View File

@@ -0,0 +1,39 @@
{{~if __namespace != ''~}}
package {{__namespace}};
{{~end~}}
import luban.*;
import com.google.gson.JsonElement;
{{~
func get_table_inner_name
ret '_' + ($0 | string.downcase)
end
~}}
public final class {{__name}}
{
public interface IJsonLoader {
JsonElement load(String file) throws java.io.IOException;
}
{{~for table in __tables
inner_name = get_table_inner_name table.name
~}}
{{~if table.comment != '' ~}}
/**
* {{escape_comment table.comment}}
*/
{{~end~}}
private final {{table.full_name_with_top_module}} {{inner_name}};
public {{table.full_name_with_top_module}} get{{table.name}}() { return {{inner_name}}; }
{{~end~}}
public {{__name}}(IJsonLoader loader) throws java.io.IOException {
{{~for table in __tables
inner_name = get_table_inner_name table.name
~}}
{{inner_name}} = new {{table.full_name_with_top_module}}(loader.load("{{table.output_data_file}}"));
{{~end~}}
}
}