Skip to content

Commit

Permalink
实现java中的类型映射功能 (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinMaple authored Feb 19, 2024
1 parent 9cecf65 commit 4c42cd2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Luban.Types;
using Luban.TypeVisitors;
using Luban.Utils;

namespace Luban.Java.TypeVisitors;

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/Luban.Java/TypeVisitors/JavaDeclaringTypeNameVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Luban.Types;
using Luban.TypeVisitors;
using Luban.Utils;

namespace Luban.Java.TypeVisitors;

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 4c42cd2

Please sign in to comment.