Skip to content

Commit d92f4af

Browse files
authored
Merge pull request #1555 from ahoppen/ahoppen/no-deprecations
Remove deprecated methods from SwiftSyntaxMacros
2 parents c9e4d07 + 4c4ed1e commit d92f4af

File tree

8 files changed

+23
-126
lines changed

8 files changed

+23
-126
lines changed

Sources/SwiftCompilerPluginMessageHandling/PluginMacroExpansionContext.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class PluginMacroExpansionContext {
211211

212212
extension PluginMacroExpansionContext: MacroExpansionContext {
213213
/// Generate a unique name for use in the macro.
214-
public func createUniqueName(_ providedName: String) -> TokenSyntax {
214+
public func makeUniqueName(_ providedName: String) -> TokenSyntax {
215215
// If provided with an empty name, substitute in something.
216216
let name = providedName.isEmpty ? "__local" : providedName
217217

@@ -246,11 +246,10 @@ extension PluginMacroExpansionContext: MacroExpansionContext {
246246
of node: Node,
247247
at positionMode: PositionInSyntaxNode,
248248
filePathMode: SourceLocationFilePathMode
249-
) -> SourceLocation? {
250-
return sourceManger.location(
251-
of: Syntax(node),
252-
at: positionMode,
253-
filePathMode: filePathMode
254-
)
249+
) -> AbstractSourceLocation? {
250+
guard let location = sourceManger.location(of: Syntax(node), at: positionMode, filePathMode: filePathMode) else {
251+
return nil
252+
}
253+
return AbstractSourceLocation(location)
255254
}
256255
}

Sources/SwiftSyntaxMacros/AbstractSourceLocation.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import SwiftSyntax
14+
import SwiftSyntaxBuilder
1415

1516
/// Abstractly represents a source location in the macro.
1617
public struct AbstractSourceLocation {
@@ -22,4 +23,18 @@ public struct AbstractSourceLocation {
2223

2324
/// A primary expression that represents the column and is `ExpressibleByIntegerLiteral`.
2425
public let column: ExprSyntax
26+
27+
public init(file: ExprSyntax, line: ExprSyntax, column: ExprSyntax) {
28+
self.file = file
29+
self.line = line
30+
self.column = column
31+
}
32+
33+
public init(_ sourceLocation: SourceLocation) {
34+
self = AbstractSourceLocation(
35+
file: "\(literal: sourceLocation.file)",
36+
line: "\(literal: sourceLocation.line)",
37+
column: "\(literal: sourceLocation.column)"
38+
)
39+
}
2540
}

Sources/SwiftSyntaxMacros/BasicMacroExpansionContext.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ extension BasicMacroExpansionContext: MacroExpansionContext {
139139
of node: Node,
140140
at position: PositionInSyntaxNode,
141141
filePathMode: SourceLocationFilePathMode
142-
) -> SourceLocation? {
142+
) -> AbstractSourceLocation? {
143143
// Dig out the root source file and figure out how we need to adjust the
144144
// offset of the given syntax node to adjust for it.
145145
let rootSourceFile: SourceFileSyntax
@@ -188,6 +188,6 @@ extension BasicMacroExpansionContext: MacroExpansionContext {
188188

189189
// Do the location lookup.
190190
let converter = SourceLocationConverter(file: fileName, tree: rootSourceFile)
191-
return converter.location(for: rawPosition.advanced(by: offsetAdjustment))
191+
return AbstractSourceLocation(converter.location(for: rawPosition.advanced(by: offsetAdjustment)))
192192
}
193193
}

Sources/SwiftSyntaxMacros/MacroExpansionContext.swift

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@ import SwiftSyntaxBuilder
1717
/// Interface to extract information about the context in which a given
1818
/// macro is expanded.
1919
public protocol MacroExpansionContext: AnyObject {
20-
/// Generate a unique name for use in the macro.
21-
///
22-
/// - Parameters:
23-
/// - name: The name to use as a basis for the uniquely-generated name,
24-
/// which will appear in the unique name that's produced here.
25-
///
26-
/// - Returns: an identifier token containing a unique name that will not
27-
/// conflict with any other name in a well-formed program.
28-
@available(*, renamed: "makeUniqueName(_:)")
29-
func createUniqueName(_ name: String) -> TokenSyntax
30-
3120
/// Generate a unique name for use in the macro.
3221
///
3322
/// - Parameters:
@@ -53,26 +42,6 @@ public protocol MacroExpansionContext: AnyObject {
5342
/// - Returns: the source location within the given node, or `nil` if the
5443
/// given syntax node is not rooted in a source file that the macro
5544
/// expansion context knows about.
56-
@available(*, deprecated, message: "Please use AbstractSourceLocation version")
57-
func location<Node: SyntaxProtocol>(
58-
of node: Node,
59-
at position: PositionInSyntaxNode,
60-
filePathMode: SourceLocationFilePathMode
61-
) -> SourceLocation?
62-
63-
/// Retrieve a source location for the given syntax node.
64-
///
65-
/// - Parameters:
66-
/// - node: The syntax node whose source location to produce.
67-
/// - position: The position within the syntax node for the resulting
68-
/// location.
69-
/// - filePathMode: How the file name contained in the source location is
70-
/// formed.
71-
///
72-
/// - Returns: the source location within the given node, or `nil` if the
73-
/// given syntax node is not rooted in a source file that the macro
74-
/// expansion context knows about.
75-
@_disfavoredOverload
7645
func location<Node: SyntaxProtocol>(
7746
of node: Node,
7847
at position: PositionInSyntaxNode,
@@ -90,87 +59,13 @@ extension MacroExpansionContext {
9059
/// - Returns: the source location within the given node, or `nil` if the
9160
/// given syntax node is not rooted in a source file that the macro
9261
/// expansion context knows about.
93-
@available(*, deprecated, message: "Please use AbstractSourceLocation version")
94-
public func location<Node: SyntaxProtocol>(
95-
of node: Node
96-
) -> SourceLocation? {
97-
return location(of: node, at: .afterLeadingTrivia, filePathMode: .fileID)
98-
}
99-
100-
/// Retrieve a source location for the given syntax node's starting token
101-
/// (after leading trivia) using file naming according to `#fileID`.
102-
///
103-
/// - Parameters:
104-
/// - node: The syntax node whose source location to produce.
105-
///
106-
/// - Returns: the source location within the given node, or `nil` if the
107-
/// given syntax node is not rooted in a source file that the macro
108-
/// expansion context knows about.
109-
@_disfavoredOverload
11062
public func location<Node: SyntaxProtocol>(
11163
of node: Node
11264
) -> AbstractSourceLocation? {
11365
return location(of: node, at: .afterLeadingTrivia, filePathMode: .fileID)
11466
}
11567
}
11668

117-
extension MacroExpansionContext {
118-
/// Retrieve a source location for the given syntax node.
119-
///
120-
/// - Parameters:
121-
/// - node: The syntax node whose source location to produce.
122-
/// - position: The position within the syntax node for the resulting
123-
/// location.
124-
/// - filePathMode: How the file name contained in the source location is
125-
/// formed.
126-
///
127-
/// - Returns: the source location within the given node, or `nil` if the
128-
/// given syntax node is not rooted in a source file that the macro
129-
/// expansion context knows about.
130-
@_disfavoredOverload
131-
@available(*, deprecated, message: "Please use AbstractSourceLocation version")
132-
public func location<Node: SyntaxProtocol>(
133-
of node: Node,
134-
at position: PositionInSyntaxNode,
135-
filePathMode: SourceLocationFilePathMode
136-
) -> AbstractSourceLocation? {
137-
guard let sourceLoc: SourceLocation = location(of: node, at: position, filePathMode: filePathMode) else {
138-
return nil
139-
}
140-
141-
return AbstractSourceLocation(
142-
file: "\(literal: sourceLoc.file)",
143-
line: "\(literal: sourceLoc.line)",
144-
column: "\(literal: sourceLoc.column)"
145-
)
146-
}
147-
148-
/// Generate a unique name for use in the macro.
149-
///
150-
/// - Parameters:
151-
/// - name: The name to use as a basis for the uniquely-generated name,
152-
/// which will appear in the unique name that's produced here.
153-
///
154-
/// - Returns: an identifier token containing a unique name that will not
155-
/// conflict with any other name in a well-formed program.
156-
@available(*, renamed: "makeUniqueName(_:)")
157-
public func createUniqueName(_ name: String) -> TokenSyntax {
158-
makeUniqueName(name)
159-
}
160-
161-
/// Generate a unique name for use in the macro.
162-
///
163-
/// - Parameters:
164-
/// - name: The name to use as a basis for the uniquely-generated name,
165-
/// which will appear in the unique name that's produced here.
166-
///
167-
/// - Returns: an identifier token containing a unique name that will not
168-
/// conflict with any other name in a well-formed program.
169-
public func makeUniqueName(_ name: String) -> TokenSyntax {
170-
createUniqueName(name)
171-
}
172-
}
173-
17469
/// Diagnostic message used for thrown errors.
17570
private struct ThrownErrorDiagnostic: DiagnosticMessage {
17671
let message: String

Sources/SwiftSyntaxMacros/MacroProtocols/AccessorMacro.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,3 @@ public protocol AccessorMacro: AttachedMacro {
2323
in context: Context
2424
) throws -> [AccessorDeclSyntax]
2525
}
26-
27-
@available(*, deprecated, renamed: "AccessorMacro")
28-
public typealias AccessorDeclarationMacro = AccessorMacro

Sources/SwiftSyntaxMacros/MacroProtocols/DeclarationMacro.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,3 @@ public protocol DeclarationMacro: FreestandingMacro {
2121
in context: Context
2222
) throws -> [DeclSyntax]
2323
}
24-
25-
@available(*, deprecated, renamed: "DeclarationMacro")
26-
public typealias FreestandingDeclarationMacro = DeclarationMacro

Sources/SwiftSyntaxMacros/MacroProtocols/MemberMacro.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,3 @@ public protocol MemberMacro: AttachedMacro {
3232
in context: Context
3333
) throws -> [DeclSyntax]
3434
}
35-
36-
@available(*, deprecated, renamed: "MemberMacro")
37-
public typealias MemberDeclarationMacro = MemberMacro

Sources/SwiftSyntaxMacros/MacroProtocols/PeerMacro.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,3 @@ public protocol PeerMacro: AttachedMacro {
2525
in context: Context
2626
) throws -> [DeclSyntax]
2727
}
28-
29-
@available(*, deprecated, renamed: "PeerMacro")
30-
public typealias PeerDeclarationMacro = PeerMacro

0 commit comments

Comments
 (0)