11// Derived from
2- // https://github.com/pointfreeco/swift-composable-architecture/blob/1.12.1 /Sources/ComposableArchitectureMacros/Extensions.swift
2+ // https://github.com/pointfreeco/swift-composable-architecture/blob/1.22.3 /Sources/ComposableArchitectureMacros/Extensions.swift
33
44//===----------------------------------------------------------------------===//
55//
@@ -43,53 +43,40 @@ extension VariableDeclSyntax {
4343 }
4444
4545 func accessorsMatching( _ predicate: ( TokenKind ) -> Bool ) -> [ AccessorDeclSyntax ] {
46- let patternBindings = bindings. compactMap { binding in
47- binding. as ( PatternBindingSyntax . self)
48- }
49- let accessors : [ AccessorDeclListSyntax . Element ] = patternBindings. compactMap { patternBinding in
46+ let accessors : [ AccessorDeclListSyntax . Element ] = bindings. compactMap { patternBinding in
5047 switch patternBinding. accessorBlock? . accessors {
51- case . accessors( let accessors) :
52- accessors
48+ case let . accessors( accessors) :
49+ return accessors
5350 default :
54- nil
55- }
56- } . flatMap { $0 }
57- return accessors. compactMap { accessor in
58- guard let decl = accessor. as ( AccessorDeclSyntax . self) else {
59- return nil
60- }
61- if predicate ( decl. accessorSpecifier. tokenKind) {
62- return decl
63- } else {
6451 return nil
6552 }
66- }
53+ } . flatMap { $0 }
54+ return accessors. compactMap { predicate ( $0. accessorSpecifier. tokenKind) ? $0 : nil }
6755 }
6856
6957 var willSetAccessors : [ AccessorDeclSyntax ] {
7058 accessorsMatching { $0 == . keyword( . willSet) }
7159 }
72-
7360 var didSetAccessors : [ AccessorDeclSyntax ] {
7461 accessorsMatching { $0 == . keyword( . didSet) }
7562 }
7663
7764 var isComputed : Bool {
7865 if accessorsMatching ( { $0 == . keyword( . get) } ) . count > 0 {
79- true
66+ return true
8067 } else {
81- bindings. contains { binding in
68+ return bindings. contains { binding in
8269 if case . getter = binding. accessorBlock? . accessors {
83- true
70+ return true
8471 } else {
85- false
72+ return false
8673 }
8774 }
8875 }
8976 }
9077
9178 var isImmutable : Bool {
92- bindingSpecifier. tokenKind == . keyword( . let)
79+ return bindingSpecifier. tokenKind == . keyword( . let)
9380 }
9481
9582 func isEquivalent( to other: VariableDeclSyntax ) -> Bool {
@@ -107,7 +94,7 @@ extension VariableDeclSyntax {
10794 for attribute in attributes {
10895 switch attribute {
10996 case . attribute( let attr) :
110- if attr. attributeName. tokens ( viewMode: . all) . map ( \ . tokenKind) == [ . identifier( name) ] {
97+ if attr. attributeName. tokens ( viewMode: . all) . map ( { $0 . tokenKind } ) == [ . identifier( name) ] {
11198 return true
11299 }
113100 default :
@@ -121,7 +108,7 @@ extension VariableDeclSyntax {
121108 for attribute in attributes {
122109 switch attribute {
123110 case . attribute( let attr) :
124- if attr. attributeName. tokens ( viewMode: . all) . map ( \ . tokenKind) == [ . identifier( name) ] {
111+ if attr. attributeName. tokens ( viewMode: . all) . map ( { $0 . tokenKind } ) == [ . identifier( name) ] {
125112 return attr
126113 }
127114 default :
@@ -152,7 +139,7 @@ extension TypeSyntax {
152139 genericParameters [ parameter. name. text] = parameter. inheritedType
153140 }
154141 }
155- var iterator = asProtocol ( TypeSyntaxProtocol . self) . tokens ( viewMode: . sourceAccurate)
142+ var iterator = self . asProtocol ( ( any TypeSyntaxProtocol ) . self) . tokens ( viewMode: . sourceAccurate)
156143 . makeIterator ( )
157144 guard let base = iterator. next ( ) else {
158145 return nil
@@ -181,6 +168,7 @@ extension TypeSyntax {
181168 return nil
182169 }
183170 substituted += substituedType
171+ break
184172 default :
185173 // ignore?
186174 break
@@ -215,25 +203,24 @@ extension FunctionDeclSyntax {
215203 for parameter in signature. parameterClause. parameters {
216204 parameters. append (
217205 parameter. firstName. text + " : "
218- + ( parameter. type. genericSubstitution ( genericParameterClause? . parameters) ?? " " ) )
206+ + ( parameter. type. genericSubstitution ( genericParameterClause? . parameters) ?? " " ) )
219207 }
220208 let returnType =
221- signature. returnClause? . type. genericSubstitution ( genericParameterClause? . parameters) ?? " Void "
209+ signature. returnClause? . type. genericSubstitution ( genericParameterClause? . parameters) ?? " Void "
222210 return SignatureStandin (
223- isInstance: isInstance, identifier: name. text, parameters: parameters, returnType: returnType
224- )
211+ isInstance: isInstance, identifier: name. text, parameters: parameters, returnType: returnType)
225212 }
226213
227214 func isEquivalent( to other: FunctionDeclSyntax ) -> Bool {
228- signatureStandin == other. signatureStandin
215+ return signatureStandin == other. signatureStandin
229216 }
230217}
231218
232219extension DeclGroupSyntax {
233220 var memberFunctionStandins : [ FunctionDeclSyntax . SignatureStandin ] {
234221 var standins = [ FunctionDeclSyntax . SignatureStandin] ( )
235222 for member in memberBlock. members {
236- if let function = member. as ( MemberBlockItemSyntax . self ) ? . decl. as ( FunctionDeclSyntax . self) {
223+ if let function = member. decl. as ( FunctionDeclSyntax . self) {
237224 standins. append ( function. signatureStandin)
238225 }
239226 }
@@ -242,7 +229,7 @@ extension DeclGroupSyntax {
242229
243230 func hasMemberFunction( equvalentTo other: FunctionDeclSyntax ) -> Bool {
244231 for member in memberBlock. members {
245- if let function = member. as ( MemberBlockItemSyntax . self ) ? . decl. as ( FunctionDeclSyntax . self) {
232+ if let function = member. decl. as ( FunctionDeclSyntax . self) {
246233 if function. isEquivalent ( to: other) {
247234 return true
248235 }
@@ -253,7 +240,7 @@ extension DeclGroupSyntax {
253240
254241 func hasMemberProperty( equivalentTo other: VariableDeclSyntax ) -> Bool {
255242 for member in memberBlock. members {
256- if let variable = member. as ( MemberBlockItemSyntax . self ) ? . decl. as ( VariableDeclSyntax . self) {
243+ if let variable = member. decl. as ( VariableDeclSyntax . self) {
257244 if variable. isEquivalent ( to: other) {
258245 return true
259246 }
@@ -264,7 +251,7 @@ extension DeclGroupSyntax {
264251
265252 var definedVariables : [ VariableDeclSyntax ] {
266253 memberBlock. members. compactMap { member in
267- if let variableDecl = member. as ( MemberBlockItemSyntax . self ) ? . decl. as ( VariableDeclSyntax . self) {
254+ if let variableDecl = member. decl. as ( VariableDeclSyntax . self) {
268255 return variableDecl
269256 }
270257 return nil
@@ -285,18 +272,30 @@ extension DeclGroupSyntax {
285272 }
286273
287274 var isClass : Bool {
288- self . is ( ClassDeclSyntax . self)
275+ return self . is ( ClassDeclSyntax . self)
289276 }
290277
291278 var isActor : Bool {
292- self . is ( ActorDeclSyntax . self)
279+ return self . is ( ActorDeclSyntax . self)
293280 }
294281
295282 var isEnum : Bool {
296- self . is ( EnumDeclSyntax . self)
283+ return self . is ( EnumDeclSyntax . self)
297284 }
298285
299286 var isStruct : Bool {
300- self . is ( StructDeclSyntax . self)
287+ return self . is ( StructDeclSyntax . self)
288+ }
289+ }
290+
291+ extension AttributedTypeSyntax {
292+ var isInout : Bool {
293+ #if canImport(SwiftSyntax600)
294+ self . specifiers. contains (
295+ where: { $0. as ( SimpleTypeSpecifierSyntax . self) ? . specifier. tokenKind == . keyword( . inout) }
296+ ) == true
297+ #else
298+ self . specifier? . tokenKind == . keyword( . inout)
299+ #endif
301300 }
302301}
0 commit comments