|
|
@@ -56,8 +56,17 @@ public struct AutoCodableMacro: MemberMacro {
|
|
|
}
|
|
|
|
|
|
// 过滤计算属性
|
|
|
- guard binding.accessorBlock == nil else {
|
|
|
- return nil
|
|
|
+ if let accessorBlock = binding.accessorBlock {
|
|
|
+ // 判断 accessor 类型
|
|
|
+ switch accessorBlock.accessors {
|
|
|
+ case .accessors(let accessors):
|
|
|
+ let hasGet = accessors.contains { $0.accessorSpecifier.tokenKind == .keyword(.get) }
|
|
|
+ if hasGet {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ case .getter:
|
|
|
+ return nil
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 3. 提取属性名称
|
|
|
@@ -133,6 +142,7 @@ enum AutoCodableMacroError: DiagnosticMessage {
|
|
|
case onlyClassesAndStructs
|
|
|
case noStoredProperties
|
|
|
case protocolError
|
|
|
+ case customError(String)
|
|
|
|
|
|
var message: String {
|
|
|
switch self {
|
|
|
@@ -142,6 +152,8 @@ enum AutoCodableMacroError: DiagnosticMessage {
|
|
|
"Type has no stored properties; Codable implementation will be empty"
|
|
|
case .protocolError:
|
|
|
"类型必须遵循 Codable、Decodable 或 Encodable"
|
|
|
+ case .customError(let err):
|
|
|
+ err
|
|
|
}
|
|
|
}
|
|
|
|