refactor: @SerializerParent 宏放宽——支持任意字段名(不要求 _ 前缀)
- isSerializableField 去掉 _ 前缀校验,任意 var/let 字段(有类型注解)均可导出/导入 - 配合 simapi-cj DTO 去下划线(code/message/data 等无 _ 前缀字段)
This commit is contained in:
@@ -85,7 +85,7 @@ public macro SerializerParent(input: Tokens): Tokens {
|
|||||||
throw ASTException("@SerializerParent 只能标注在 class 声明上(不支持 struct/interface/enum)")
|
throw ASTException("@SerializerParent 只能标注在 class 声明上(不支持 struct/interface/enum)")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 收集类体内的可序列化字段(_ 前缀 + 类型注解;跳过 @SerializerIgnore;@SerializerPropertyName 用注解名)
|
/// 收集类体内的可序列化字段(任意 var/let 字段 + 类型注解;跳过 @SerializerIgnore;@SerializerPropertyName 用注解名)
|
||||||
private func collectFields(cd: ClassDecl): ArrayList<FieldInfo> {
|
private func collectFields(cd: ClassDecl): ArrayList<FieldInfo> {
|
||||||
var result = ArrayList<FieldInfo>()
|
var result = ArrayList<FieldInfo>()
|
||||||
for (d in cd.body.decls) {
|
for (d in cd.body.decls) {
|
||||||
@@ -118,9 +118,9 @@ private func collectFields(cd: ClassDecl): ArrayList<FieldInfo> {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 普通字段是否可序列化:_ 前缀 + 有类型注解
|
/// 普通字段是否可序列化:有类型注解(不要求 _ 前缀)
|
||||||
private func isSerializableField(vd: VarDecl): Bool {
|
private func isSerializableField(vd: VarDecl): Bool {
|
||||||
vd.identifier.value.startsWith("_") && !vd.colon.value.isEmpty()
|
!vd.colon.value.isEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 从 MacroExpandDecl 提取内部 VarDecl(带注解的字段声明)
|
/// 从 MacroExpandDecl 提取内部 VarDecl(带注解的字段声明)
|
||||||
|
|||||||
Reference in New Issue
Block a user