Files
swift-mirror/test/refactoring/AddCodableImplementation/Outputs/enum/encodable.swift.expected
Louis D'hauwe 5d36507a2f [Refactoring] Add Codable refactoring action
Inserts the synthesized implementation.
As part of this, fix some ASTPrinter bugs.

rdar://87904700
2022-02-02 14:14:23 -08:00

46 lines
1.1 KiB
Plaintext

enum Payload: Codable {
case plain(String)
case pair(key: String, value: String)
}
enum Payload_D: Decodable {
case plain(String)
case pair(key: String, value: String)
}
enum Payload_E: Encodable {
case plain(String)
case pair(key: String, value: String)
enum CodingKeys: CodingKey {
case plain
case pair
}
enum PlainCodingKeys: CodingKey {
case _0
}
enum PairCodingKeys: CodingKey {
case key
case value
}
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: Payload_E.CodingKeys.self)
switch self {
case .plain(let a0):
var nestedContainer = container.nestedContainer(keyedBy: Payload_E.PlainCodingKeys.self, forKey: Payload_E.CodingKeys.plain)
try nestedContainer.encode(a0, forKey: Payload_E.PlainCodingKeys._0)
case .pair(let key, let value):
var nestedContainer = container.nestedContainer(keyedBy: Payload_E.PairCodingKeys.self, forKey: Payload_E.CodingKeys.pair)
try nestedContainer.encode(key, forKey: Payload_E.PairCodingKeys.key)
try nestedContainer.encode(value, forKey: Payload_E.PairCodingKeys.value)
}
}
}