-
-
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.
fix: fixed empty
CodingKeys
enum generated instead of being skipped
- Loading branch information
1 parent
97a6057
commit a28bb9c
Showing
40 changed files
with
1,111 additions
and
1,144 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
65 changes: 65 additions & 0 deletions
65
Sources/CodableMacroPlugin/Attributes/KeyPath/ContentAt.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,65 @@ | ||
@_implementationOnly import SwiftDiagnostics | ||
@_implementationOnly import SwiftSyntax | ||
@_implementationOnly import SwiftSyntaxMacros | ||
|
||
/// Attribute type for `ContentAt` macro-attribute. | ||
/// | ||
/// This type can validate`ContentAt` macro-attribute | ||
/// usage and extract data for `Codable` macro to | ||
/// generate implementation. | ||
struct ContentAt: PropertyAttribute { | ||
/// The node syntax provided | ||
/// during initialization. | ||
let node: AttributeSyntax | ||
|
||
/// Creates a new instance with the provided node. | ||
/// | ||
/// The initializer fails to create new instance if the name | ||
/// of the provided node is different than this attribute. | ||
/// | ||
/// - Parameter node: The attribute syntax to create with. | ||
/// - Returns: Newly created attribute instance. | ||
init?(from node: AttributeSyntax) { | ||
guard | ||
node.attributeName.as(IdentifierTypeSyntax.self)! | ||
.name.text == Self.name | ||
else { return nil } | ||
self.node = node | ||
} | ||
|
||
/// Builds diagnoser that can validate this macro | ||
/// attached declaration. | ||
/// | ||
/// The following conditions are checked by the | ||
/// built diagnoser: | ||
/// * Attached declaration is an enum declaration. | ||
/// * Macro should be used in presence of `Codable`. | ||
/// * Macro usage is not duplicated for the same | ||
/// declaration. | ||
/// | ||
/// - Returns: The built diagnoser instance. | ||
func diagnoser() -> DiagnosticProducer { | ||
return AggregatedDiagnosticProducer { | ||
expect(syntaxes: EnumDeclSyntax.self) | ||
mustBeCombined(with: Codable.self) | ||
mustBeCombined(with: CodedAt.self) | ||
cantDuplicate() | ||
} | ||
} | ||
} | ||
|
||
extension ContentAt: KeyPathProvider { | ||
/// Indicates whether `CodingKey` path | ||
/// data is provided to this instance. | ||
/// | ||
/// Always `true` for this type. | ||
var provided: Bool { true } | ||
|
||
/// Updates `CodingKey` path using the provided path. | ||
/// | ||
/// The `CodingKey` path overrides current `CodingKey` path data. | ||
/// | ||
/// - Parameter path: Current `CodingKey` path. | ||
/// - Returns: Updated `CodingKey` path. | ||
func keyPath(withExisting path: [String]) -> [String] { providedPath } | ||
} |
110 changes: 0 additions & 110 deletions
110
Sources/CodableMacroPlugin/Attributes/KeyPath/TaggedAt.swift
This file was deleted.
Oops, something went wrong.
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.