Skip to content

Commit fcb9202

Browse files
committed
Syntax improvement
1 parent dc0db4c commit fcb9202

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Sources/Macros/Access.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ public struct Access: AccessorMacro {
88
Declaration: DeclSyntaxProtocol>(of node: AttributeSyntax,
99
providingAccessorsOf declaration: Declaration,
1010
in context: Context) throws -> [AccessorDeclSyntax] {
11-
guard let firstArg = node.argument?.as(TupleExprElementListSyntax.self)?.first,
11+
guard let firstArg = node.arguments?.as(LabeledExprListSyntax.self)?.first,
1212
let type = firstArg.type else {
1313
throw MacroDiagnostics.errorMacroUsage(message: "Must specify a content type")
1414
}
1515
if type == "userDefaults",
16-
let dataType = node.attributeName.as(SimpleTypeIdentifierSyntax.self)?.type {
16+
let dataType = node.attributeName.as(IdentifierTypeSyntax.self)?.type {
1717
return processUserDefaults(for: declaration,
1818
userDefaults: firstArg.userDefaults,
1919
type: "\(dataType)")
2020
} else if ["nsCache", "nsMapTable"].contains(type),
2121
let object = firstArg.object,
22-
let dataType = node.attributeName.as(SimpleTypeIdentifierSyntax.self)?.type {
23-
let isOptionalType = node.attributeName.as(SimpleTypeIdentifierSyntax.self)?.genericArgumentClause?.arguments
24-
.first?.as(GenericArgumentSyntax.self)?.argumentType.is(OptionalTypeSyntax.self) ?? false
22+
let dataType = node.attributeName.as(IdentifierTypeSyntax.self)?.type {
23+
let isOptionalType = node.attributeName.as(IdentifierTypeSyntax.self)?.genericArgumentClause?.arguments
24+
.first?.as(GenericArgumentSyntax.self)?.argument.is(OptionalTypeSyntax.self) ?? false
2525
return processNSCacheAndNSMapTable(for: declaration,
2626
object: object,
2727
type: "\(dataType)",
@@ -36,7 +36,7 @@ public struct Access: AccessorMacro {
3636
private static func processKeychain(for declaration: DeclSyntaxProtocol) -> [AccessorDeclSyntax] {
3737
guard let binding = declaration.as(VariableDeclSyntax.self)?.bindings.first,
3838
let identifier = binding.pattern.as(IdentifierPatternSyntax.self)?.identifier.text,
39-
binding.accessor == nil else { return [] }
39+
binding.accessorBlock == nil else { return [] }
4040
let getAccessor: AccessorDeclSyntax =
4141
"""
4242
get {
@@ -63,7 +63,7 @@ public struct Access: AccessorMacro {
6363
type: String) -> [AccessorDeclSyntax] {
6464
guard let binding = declaration.as(VariableDeclSyntax.self)?.bindings.first,
6565
let identifier = binding.pattern.as(IdentifierPatternSyntax.self)?.identifier.text,
66-
binding.accessor == nil else { return [] }
66+
binding.accessorBlock == nil else { return [] }
6767
var defaultValue = ""
6868
if let value = binding.initializer?.value {
6969
defaultValue = " ?? \(value)"
@@ -90,7 +90,7 @@ public struct Access: AccessorMacro {
9090
isOptionalType: Bool) -> [AccessorDeclSyntax] {
9191
guard let binding = declaration.as(VariableDeclSyntax.self)?.bindings.first,
9292
let identifier = binding.pattern.as(IdentifierPatternSyntax.self)?.identifier.text,
93-
binding.accessor == nil else { return [] }
93+
binding.accessorBlock == nil else { return [] }
9494
var defaultValue = ""
9595
if let value = binding.initializer?.value {
9696
defaultValue = " ?? \(value)"

Tests/MacroTests/ConformToHashableTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ final class ConformToHashableTests: XCTestCase {
3535
extension AClass: Hashable {
3636
func hash(into hasher: inout Hasher) {
3737
hasher.combine(a)
38+
hasher.combine(b)
3839
}
3940
}
4041
""",

0 commit comments

Comments
 (0)