From 4c42cd2318a6b4c1a67a7a79f671cb9dfc153b23 Mon Sep 17 00:00:00 2001 From: DustinMaple Date: Mon, 19 Feb 2024 14:57:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0java=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=98=A0=E5=B0=84=E5=8A=9F=E8=83=BD=20(#113)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TypeVisitors/JavaBinUnderlyingDeserializeVisitor.cs | 9 +++++++-- .../TypeVisitors/JavaDeclaringTypeNameVisitor.cs | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Luban.Java/TypeVisitors/JavaBinUnderlyingDeserializeVisitor.cs b/src/Luban.Java/TypeVisitors/JavaBinUnderlyingDeserializeVisitor.cs index 3b2b5779..dabf18c4 100644 --- a/src/Luban.Java/TypeVisitors/JavaBinUnderlyingDeserializeVisitor.cs +++ b/src/Luban.Java/TypeVisitors/JavaBinUnderlyingDeserializeVisitor.cs @@ -1,5 +1,6 @@ using Luban.Types; using Luban.TypeVisitors; +using Luban.Utils; namespace Luban.Java.TypeVisitors; @@ -44,7 +45,9 @@ public string Accept(TDouble type, string bufName, string fieldName) public string Accept(TEnum type, string bufName, string fieldName) { - return $"{fieldName} = {bufName}.readInt();"; + string src = $"{bufName}.readInt()"; + string constructor = type.DefEnum.TypeConstructorWithTypeMapper(); + return $"{fieldName} = {(string.IsNullOrEmpty(constructor) ? src : $"{constructor}({src})")};"; } public string Accept(TString type, string bufName, string fieldName) @@ -54,7 +57,9 @@ public string Accept(TString type, string bufName, string fieldName) public string Accept(TBean type, string bufName, string fieldName) { - return $"{fieldName} = {type.DefBean.FullNameWithTopModule}.deserialize({bufName});"; + string src = $"{type.DefBean.FullNameWithTopModule}.deserialize({bufName})"; + string constructor = type.DefBean.TypeConstructorWithTypeMapper(); + return $"{fieldName} = {(string.IsNullOrEmpty(constructor) ? src : $"{constructor}({src})")};"; } public string Accept(TArray type, string bufName, string fieldName) diff --git a/src/Luban.Java/TypeVisitors/JavaDeclaringTypeNameVisitor.cs b/src/Luban.Java/TypeVisitors/JavaDeclaringTypeNameVisitor.cs index 506eb0bf..e1f39524 100644 --- a/src/Luban.Java/TypeVisitors/JavaDeclaringTypeNameVisitor.cs +++ b/src/Luban.Java/TypeVisitors/JavaDeclaringTypeNameVisitor.cs @@ -1,5 +1,6 @@ using Luban.Types; using Luban.TypeVisitors; +using Luban.Utils; namespace Luban.Java.TypeVisitors; @@ -44,8 +45,8 @@ public virtual string Accept(TDouble type) public virtual string Accept(TEnum type) { - //return type.DefineEnum.FullNameWithTopModule; - return type.IsNullable ? "Integer" : "int"; + string src = type.IsNullable ? "Integer" : "int"; + return type.DefEnum.TypeNameWithTypeMapper() ?? src; } public string Accept(TString type) @@ -60,7 +61,7 @@ public virtual string Accept(TDateTime type) public string Accept(TBean type) { - return type.DefBean.FullNameWithTopModule; + return type.DefBean.TypeNameWithTypeMapper() ?? type.DefBean.FullNameWithTopModule; } public string Accept(TArray type)