【调整】调整java_bin和java_json的生成代码,移除var关键字,兼容java 1.8的语法。
parent
28c6ee75a0
commit
afbfaa1c55
|
|
@ -93,37 +93,37 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
|
||||||
public string Accept(TArray type, string json, string x)
|
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; }} }}";
|
return $"{{ com.google.gson.JsonArray _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)
|
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); }} }}";
|
return $"{{ com.google.gson.JsonArray _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)
|
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); }} }}";
|
return $"{{ com.google.gson.JsonArray _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)
|
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); }} }}";
|
return @$"{{ com.google.gson.JsonArray _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)
|
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); }}";
|
return $"{{ com.google.gson.JsonObject _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)
|
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); }}";
|
return $"{{ com.google.gson.JsonObject _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)
|
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); }}";
|
return $"{{ com.google.gson.JsonObject _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)
|
public string Accept(TDateTime type, string json, string x)
|
||||||
|
|
|
||||||
|
|
@ -91,22 +91,22 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
|
||||||
public string Accept(TArray type, string bufName, string fieldName)
|
public string Accept(TArray type, string bufName, string fieldName)
|
||||||
{
|
{
|
||||||
return $"{{int n = Math.min({bufName}.readSize(), {bufName}.size());{fieldName} = new {type.ElementType.Apply(JavaDefineTypeName.Ins)}[n];for(var i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(JavaDefineTypeName.Ins)} _e;{type.ElementType.Apply(this, bufName, "_e")} {fieldName}[i] = _e;}}}}";
|
return $"{{int n = Math.min({bufName}.readSize(), {bufName}.size());{fieldName} = new {type.ElementType.Apply(JavaDefineTypeName.Ins)}[n];for(int i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(JavaDefineTypeName.Ins)} _e;{type.ElementType.Apply(this, bufName, "_e")} {fieldName}[i] = _e;}}}}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Accept(TList type, string bufName, string fieldName)
|
public string Accept(TList type, string bufName, string fieldName)
|
||||||
{
|
{
|
||||||
return $"{{int n = Math.min({bufName}.readSize(), {bufName}.size());{fieldName} = new {type.Apply(JavaDefineTypeName.Ins)}(n);for(var i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(JavaBoxDefineTypeName.Ins)} _e; {type.ElementType.Apply(this, bufName, "_e")} {fieldName}.add(_e);}}}}";
|
return $"{{int n = Math.min({bufName}.readSize(), {bufName}.size());{fieldName} = new {type.Apply(JavaDefineTypeName.Ins)}(n);for(int i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(JavaBoxDefineTypeName.Ins)} _e; {type.ElementType.Apply(this, bufName, "_e")} {fieldName}.add(_e);}}}}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Accept(TSet type, string bufName, string fieldName)
|
public string Accept(TSet type, string bufName, string fieldName)
|
||||||
{
|
{
|
||||||
return $"{{int n = Math.min({bufName}.readSize(), {bufName}.size());{fieldName} = new {type.Apply(JavaDefineTypeName.Ins)}(n * 3 / 2);for(var i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(JavaBoxDefineTypeName.Ins)} _e; {type.ElementType.Apply(this, bufName, "_e")} {fieldName}.add(_e);}}}}";
|
return $"{{int n = Math.min({bufName}.readSize(), {bufName}.size());{fieldName} = new {type.Apply(JavaDefineTypeName.Ins)}(n * 3 / 2);for(int i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(JavaBoxDefineTypeName.Ins)} _e; {type.ElementType.Apply(this, bufName, "_e")} {fieldName}.add(_e);}}}}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Accept(TMap type, string bufName, string fieldName)
|
public string Accept(TMap type, string bufName, string fieldName)
|
||||||
{
|
{
|
||||||
return $"{{int n = Math.min({bufName}.readSize(), {bufName}.size());{fieldName} = new {type.Apply(JavaDefineTypeName.Ins)}(n * 3 / 2);for(var i = 0 ; i < n ; i++) {{ {type.KeyType.Apply(JavaBoxDefineTypeName.Ins)} _k; {type.KeyType.Apply(this, bufName, "_k")} {type.ValueType.Apply(JavaBoxDefineTypeName.Ins)} _v; {type.ValueType.Apply(this, bufName, "_v")} {fieldName}.put(_k, _v);}}}}";
|
return $"{{int n = Math.min({bufName}.readSize(), {bufName}.size());{fieldName} = new {type.Apply(JavaDefineTypeName.Ins)}(n * 3 / 2);for(int i = 0 ; i < n ; i++) {{ {type.KeyType.Apply(JavaBoxDefineTypeName.Ins)} _k; {type.KeyType.Apply(this, bufName, "_k")} {type.ValueType.Apply(JavaBoxDefineTypeName.Ins)} _v; {type.ValueType.Apply(this, bufName, "_v")} {fieldName}.put(_k, _v);}}}}";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public final class {{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>();
|
java.util.HashMap<String, Object> tables = new java.util.HashMap<>();
|
||||||
{{~for table in tables ~}}
|
{{~for table in tables ~}}
|
||||||
{{table.inner_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.inner_name}});
|
tables.put("{{table.full_name}}", {{table.inner_name}});
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ public final class {{name}} {
|
||||||
_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(var _e_ : __json__.getAsJsonArray()) {
|
for(com.google.gson.JsonElement _e_ : __json__.getAsJsonArray()) {
|
||||||
{{java_box_define_type value_type}} _v;
|
{{java_box_define_type value_type}} _v;
|
||||||
{{java_deserialize '_e_.getAsJsonObject()' '_v' value_type}}
|
{{java_deserialize '_e_.getAsJsonObject()' '_v' value_type}}
|
||||||
_dataList.add(_v);
|
_dataList.add(_v);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public final class {{name}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
|
|
||||||
public {{name}}(IJsonLoader loader) throws java.io.IOException {
|
public {{name}}(IJsonLoader loader) throws java.io.IOException {
|
||||||
var tables = new java.util.HashMap<String, Object>();
|
java.util.HashMap<String, Object> tables = new java.util.HashMap<>();
|
||||||
{{~for table in tables ~}}
|
{{~for table in tables ~}}
|
||||||
{{table.inner_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.inner_name}});
|
tables.put("{{table.full_name}}", {{table.inner_name}});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue