Skip to content

Commit 4cb11cd

Browse files
committed
modify
1 parent 638f2e0 commit 4cb11cd

File tree

6 files changed

+18
-33
lines changed

6 files changed

+18
-33
lines changed

Diff for: Sources/Implementation/Member/AssociatedValuesMacro.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import SwiftSyntax
22
import SwiftSyntaxBuilder
33
import SwiftSyntaxMacros
44

5-
public struct AssociatedValuesMacro: MemberMacro {
6-
public static func expansion(
5+
struct AssociatedValuesMacro: MemberMacro {
6+
static func expansion(
77
of node: AttributeSyntax,
88
providingMembersOf declaration: some DeclGroupSyntax,
99
in context: some MacroExpansionContext

Diff for: Sources/Implementation/Member/CaseDetectionMacro.swift

+7-15
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import SwiftSyntaxBuilder
1717
import SwiftSyntaxMacroExpansion
1818
import SwiftSyntaxMacros
1919

20-
public enum CaseDetectionMacro: MemberMacro {
21-
public static func expansion<D, C>(
20+
enum CaseDetectionMacro: MemberMacro {
21+
static func expansion<D, C>(
2222
of node: AttributeSyntax,
2323
providingMembersOf decl: D,
2424
in context: C
2525
) throws -> [SwiftSyntax.DeclSyntax]
26-
where D: DeclGroupSyntax, C: MacroExpansionContext {
26+
where D: DeclGroupSyntax, C: MacroExpansionContext
27+
{
2728
guard [SwiftSyntax.SyntaxKind.enumDecl].contains(decl.kind) else {
2829
throw MacroExpansionErrorMessage(
2930
"""
@@ -44,10 +45,7 @@ public enum CaseDetectionMacro: MemberMacro {
4445
.map { original, uppercased in
4546
"""
4647
\(raw: accessLevel) var is\(raw: uppercased): Bool {
47-
if case .\(raw: original) = self {
48-
return true
49-
}
50-
48+
if case .\(raw: original) = self { return true }
5149
return false
5250
}
5351
"""
@@ -60,14 +58,8 @@ public enum CaseDetectionMacro: MemberMacro {
6058
node.arguments?.as(LabeledExprListSyntax.self)?
6159
.lazy
6260
.compactMap { labeledExprSyntax -> AccessLevelModifier? in
63-
guard
64-
let identifier = labeledExprSyntax.expression.as(MemberAccessExprSyntax.self)?.declName,
65-
let accessLevel = AccessLevelModifier(rawValue: identifier.baseName.trimmedDescription)
66-
else {
67-
return nil
68-
}
69-
70-
return accessLevel
61+
(labeledExprSyntax.expression.as(MemberAccessExprSyntax.self)?.declName)
62+
.flatMap { AccessLevelModifier(rawValue: $0.baseName.trimmedDescription) }
7163
}
7264
.first
7365
}

Diff for: Sources/Implementation/Member/LoggingMacro.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import SwiftSyntaxBuilder
99
import SwiftSyntaxMacroExpansion
1010
import SwiftSyntaxMacros
1111

12-
public struct LoggingMacro: MemberMacro {
13-
public enum MacroError: Error {
12+
struct LoggingMacro: MemberMacro {
13+
enum MacroError: Error {
1414
case incorrectType
1515
}
1616

17-
public static func expansion(
17+
static func expansion(
1818
of node: AttributeSyntax,
1919
providingMembersOf declaration: some DeclGroupSyntax,
2020
in context: some MacroExpansionContext

Diff for: Tests/MacroKitTests/Member/AssociatedValuesMacroTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import Macros
21
import SwiftSyntaxMacros
32
import SwiftSyntaxMacrosTestSupport
43
import XCTest
54

5+
@testable import Macros
6+
67
private let testMacros: [String: Macro.Type] = [
78
"AssociatedValues": AssociatedValuesMacro.self,
89
]

Diff for: Tests/MacroKitTests/Member/CaseDetectionMacroTests.swift

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import SwiftSyntaxMacros
22
import SwiftSyntaxMacrosTestSupport
33
import XCTest
4-
import Macros
4+
5+
@testable import Macros
56

67
fileprivate let testMacros: [String: Macro.Type] = [
78
"CaseDetection": CaseDetectionMacro.self,
@@ -26,15 +27,13 @@ final class CaseDetectionMacroTests: XCTestCase {
2627
if case .dog = self {
2728
return true
2829
}
29-
3030
return false
3131
}
3232
3333
public var isCat: Bool {
3434
if case .cat = self {
3535
return true
3636
}
37-
3837
return false
3938
}
4039
}
@@ -61,15 +60,13 @@ final class CaseDetectionMacroTests: XCTestCase {
6160
if case .dog = self {
6261
return true
6362
}
64-
6563
return false
6664
}
6765
6866
internal var isCat: Bool {
6967
if case .cat = self {
7068
return true
7169
}
72-
7370
return false
7471
}
7572
}
@@ -96,15 +93,13 @@ final class CaseDetectionMacroTests: XCTestCase {
9693
if case .dog = self {
9794
return true
9895
}
99-
10096
return false
10197
}
10298
10399
fileprivate var isCat: Bool {
104100
if case .cat = self {
105101
return true
106102
}
107-
108103
return false
109104
}
110105
}
@@ -131,15 +126,13 @@ final class CaseDetectionMacroTests: XCTestCase {
131126
if case .dog = self {
132127
return true
133128
}
134-
135129
return false
136130
}
137131
138132
private var isCat: Bool {
139133
if case .cat = self {
140134
return true
141135
}
142-
143136
return false
144137
}
145138
}
@@ -166,15 +159,13 @@ final class CaseDetectionMacroTests: XCTestCase {
166159
if case .dog = self {
167160
return true
168161
}
169-
170162
return false
171163
}
172164
173165
internal var isCat: Bool {
174166
if case .cat = self {
175167
return true
176168
}
177-
178169
return false
179170
}
180171
}

Diff for: Tests/MacroKitTests/Member/LoggingTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import Macros
21
import SwiftSyntaxMacros
32
import SwiftSyntaxMacrosTestSupport
43
import XCTest
54

5+
@testable import Macros
6+
67
final class LoggingTests: XCTestCase {
78
func testLoggingMacroExpansion1() throws {
89
assertMacroExpansion(

0 commit comments

Comments
 (0)