Skip to content

Commit 62db3d5

Browse files
committed
[Macros] Fix SwiftSyntax deprecation warnings
1 parent 2890e29 commit 62db3d5

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

lib/Macros/Sources/ObservationMacros/Availability.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extension IfConfigClauseSyntax {
5151
}
5252

5353
var clonedAsIf: IfConfigClauseSyntax {
54-
detached.with(\.poundKeyword, .poundIfKeyword())
54+
detached.with(\.poundKeyword, .poundIfToken())
5555
}
5656
}
5757

lib/Macros/Sources/ObservationMacros/Extensions.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension VariableDeclSyntax {
4545
let patternBindings = bindings.compactMap { binding in
4646
binding.as(PatternBindingSyntax.self)
4747
}
48-
let accessors: [AccessorListSyntax.Element] = patternBindings.compactMap { patternBinding in
48+
let accessors: [AccessorDeclListSyntax.Element] = patternBindings.compactMap { patternBinding in
4949
switch patternBinding.accessorBlock?.accessors {
5050
case .accessors(let accessors):
5151
return accessors
@@ -217,7 +217,7 @@ extension DeclGroupSyntax {
217217
var memberFunctionStandins: [FunctionDeclSyntax.SignatureStandin] {
218218
var standins = [FunctionDeclSyntax.SignatureStandin]()
219219
for member in memberBlock.members {
220-
if let function = member.as(MemberDeclListItemSyntax.self)?.decl.as(FunctionDeclSyntax.self) {
220+
if let function = member.as(MemberBlockItemSyntax.self)?.decl.as(FunctionDeclSyntax.self) {
221221
standins.append(function.signatureStandin)
222222
}
223223
}
@@ -226,7 +226,7 @@ extension DeclGroupSyntax {
226226

227227
func hasMemberFunction(equvalentTo other: FunctionDeclSyntax) -> Bool {
228228
for member in memberBlock.members {
229-
if let function = member.as(MemberDeclListItemSyntax.self)?.decl.as(FunctionDeclSyntax.self) {
229+
if let function = member.as(MemberBlockItemSyntax.self)?.decl.as(FunctionDeclSyntax.self) {
230230
if function.isEquivalent(to: other) {
231231
return true
232232
}
@@ -237,7 +237,7 @@ extension DeclGroupSyntax {
237237

238238
func hasMemberProperty(equivalentTo other: VariableDeclSyntax) -> Bool {
239239
for member in memberBlock.members {
240-
if let variable = member.as(MemberDeclListItemSyntax.self)?.decl.as(VariableDeclSyntax.self) {
240+
if let variable = member.as(MemberBlockItemSyntax.self)?.decl.as(VariableDeclSyntax.self) {
241241
if variable.isEquivalent(to: other) {
242242
return true
243243
}
@@ -248,7 +248,7 @@ extension DeclGroupSyntax {
248248

249249
var definedVariables: [VariableDeclSyntax] {
250250
memberBlock.members.compactMap { member in
251-
if let variableDecl = member.as(MemberDeclListItemSyntax.self)?.decl.as(VariableDeclSyntax.self) {
251+
if let variableDecl = member.as(MemberBlockItemSyntax.self)?.decl.as(VariableDeclSyntax.self) {
252252
return variableDecl
253253
}
254254
return nil

lib/Macros/Sources/ObservationMacros/ObservableMacro.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public struct ObservableMacro {
7171
AttributeSyntax(
7272
leadingTrivia: .space,
7373
atSign: .atSignToken(),
74-
attributeName: SimpleTypeIdentifierSyntax(name: .identifier(ignoredMacroName)),
74+
attributeName: IdentifierTypeSyntax(name: .identifier(ignoredMacroName)),
7575
trailingTrivia: .space
7676
)
7777
}
@@ -108,10 +108,10 @@ extension DiagnosticsError {
108108
}
109109
}
110110

111-
extension ModifierListSyntax {
112-
func privatePrefixed(_ prefix: String) -> ModifierListSyntax {
111+
extension DeclModifierListSyntax {
112+
func privatePrefixed(_ prefix: String) -> DeclModifierListSyntax {
113113
let modifier: DeclModifierSyntax = DeclModifierSyntax(name: "private", trailingTrivia: .space)
114-
return ModifierListSyntax([modifier] + filter {
114+
return [modifier] + filter {
115115
switch $0.name.tokenKind {
116116
case .keyword(let keyword):
117117
switch keyword {
@@ -126,7 +126,7 @@ extension ModifierListSyntax {
126126
default:
127127
return true
128128
}
129-
})
129+
}
130130
}
131131

132132
init(keyword: Keyword) {
@@ -178,7 +178,7 @@ extension VariableDeclSyntax {
178178
return VariableDeclSyntax(
179179
leadingTrivia: leadingTrivia,
180180
attributes: newAttributes,
181-
modifiers: modifiers?.privatePrefixed(prefix) ?? ModifierListSyntax(keyword: .private),
181+
modifiers: modifiers?.privatePrefixed(prefix) ?? DeclModifierListSyntax(keyword: .private),
182182
bindingSpecifier: TokenSyntax(bindingSpecifier.tokenKind, leadingTrivia: .space, trailingTrivia: .space, presence: .present),
183183
bindings: bindings.privatePrefixed(prefix),
184184
trailingTrivia: trailingTrivia
@@ -252,7 +252,7 @@ extension ObservableMacro: MemberAttributeMacro {
252252

253253

254254
return [
255-
AttributeSyntax(attributeName: SimpleTypeIdentifierSyntax(name: .identifier(ObservableMacro.trackedMacroName)))
255+
AttributeSyntax(attributeName: IdentifierTypeSyntax(name: .identifier(ObservableMacro.trackedMacroName)))
256256
]
257257
}
258258
}

lib/Macros/Sources/SwiftMacros/OptionSetMacro.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private let optionsEnumNameArgumentLabel = "optionsName"
4747
/// eventually be overridable.
4848
private let defaultOptionsEnumName = "Options"
4949

50-
extension TupleExprElementListSyntax {
50+
extension LabeledExprListSyntax {
5151
/// Retrieve the first element with the given label.
5252
func first(labeled name: String) -> Element? {
5353
return first { element in
@@ -75,7 +75,7 @@ public struct OptionSetMacro {
7575
) -> (StructDeclSyntax, EnumDeclSyntax, TypeSyntax)? {
7676
// Determine the name of the options enum.
7777
let optionsEnumName: String
78-
if case let .argumentList(arguments) = attribute.argument,
78+
if case let .argumentList(arguments) = attribute.arguments,
7979
let optionEnumNameArg = arguments.first(labeled: optionsEnumNameArgumentLabel) {
8080
// We have a options name; make sure it is a string literal.
8181
guard let stringLiteral = optionEnumNameArg.expression.as(StringLiteralExprSyntax.self),
@@ -99,7 +99,7 @@ public struct OptionSetMacro {
9999
// Find the option enum within the struct.
100100
let optionsEnums: [EnumDeclSyntax] = decl.memberBlock.members.compactMap({ member in
101101
if let enumDecl = member.decl.as(EnumDeclSyntax.self),
102-
enumDecl.identifier.text == optionsEnumName {
102+
enumDecl.name.text == optionsEnumName {
103103
return enumDecl
104104
}
105105

@@ -112,8 +112,8 @@ public struct OptionSetMacro {
112112
}
113113

114114
// Retrieve the raw type from the attribute.
115-
guard let genericArgs = attribute.attributeName.as(SimpleTypeIdentifierSyntax.self)?.genericArgumentClause,
116-
let rawType = genericArgs.arguments.first?.argumentType else {
115+
guard let genericArgs = attribute.attributeName.as(IdentifierTypeSyntax.self)?.genericArgumentClause,
116+
let rawType = genericArgs.arguments.first?.argument else {
117117
context.diagnose(OptionSetMacroDiagnostic.requiresOptionsEnumRawType.diagnose(at: attribute))
118118
return nil
119119
}
@@ -138,8 +138,8 @@ extension OptionSetMacro: ConformanceMacro {
138138
}
139139

140140
// If there is an explicit conformance to OptionSet already, don't add one.
141-
if let inheritedTypes = structDecl.inheritanceClause?.inheritedTypeCollection,
142-
inheritedTypes.contains(where: { inherited in inherited.typeName.trimmedDescription == "OptionSet" }) {
141+
if let inheritedTypes = structDecl.inheritanceClause?.inheritedTypes,
142+
inheritedTypes.contains(where: { inherited in inherited.type.trimmedDescription == "OptionSet" }) {
143143
return []
144144
}
145145

@@ -174,8 +174,8 @@ extension OptionSetMacro: MemberMacro {
174174

175175
let staticVars = caseElements.map { (element) -> DeclSyntax in
176176
"""
177-
\(access) static let \(element.identifier): Self =
178-
Self(rawValue: 1 << \(optionsEnum.identifier).\(element.identifier).rawValue)
177+
\(access) static let \(element.name): Self =
178+
Self(rawValue: 1 << \(optionsEnum.name).\(element.name).rawValue)
179179
"""
180180
}
181181

0 commit comments

Comments
 (0)