-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a22e9d1
commit 97a6057
Showing
13 changed files
with
270 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Sources/CodableMacroPlugin/Variables/Type/ActorVariable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
@_implementationOnly import SwiftSyntax | ||
@_implementationOnly import SwiftSyntaxMacros | ||
|
||
/// A `TypeVariable` that provides `Codable` conformance | ||
/// for an `actor` type. | ||
/// | ||
/// This type can be used for `actor`s for `Decodable` conformance and | ||
/// `Encodable` implementation without conformance. | ||
struct ActorVariable: TypeVariable, DeclaredVariable, ComposedVariable, | ||
InitializableVariable | ||
{ | ||
/// The initialization type of this variable. | ||
/// | ||
/// Initialization type is the same as underlying member group variable. | ||
typealias Initialization = MemberGroup<ActorDeclSyntax>.Initialization | ||
/// The member group used to generate conformance implementations. | ||
let base: MemberGroup<ActorDeclSyntax> | ||
|
||
/// Creates a new variable from declaration and expansion context. | ||
/// | ||
/// Uses the actor declaration with member group to generate conformances. | ||
/// | ||
/// - Parameters: | ||
/// - decl: The declaration to read from. | ||
/// - context: The context in which the macro expansion performed. | ||
init(from decl: ActorDeclSyntax, in context: some MacroExpansionContext) { | ||
self.base = .init(from: decl, in: context) | ||
} | ||
|
||
/// Provides the syntax for encoding at the provided location. | ||
/// | ||
/// Uses member group to generate syntax, the implementation is added | ||
/// while not conforming to `Encodable` protocol. | ||
/// | ||
/// - Parameters: | ||
/// - context: The context in which to perform the macro expansion. | ||
/// - location: The encoding location. | ||
/// | ||
/// - Returns: The generated encoding syntax. | ||
func encoding( | ||
in context: some MacroExpansionContext, | ||
to location: TypeCodingLocation | ||
) -> TypeGenerated? { | ||
guard | ||
let generated = base.encoding(in: context, to: location) | ||
else { return nil } | ||
return .init( | ||
code: generated.code, modifiers: generated.modifiers, | ||
whereClause: generated.whereClause, | ||
inheritanceClause: nil | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.