Skip to content

Commit 183aa3e

Browse files
authored
Merge pull request #1367 from rxwei/rename-createuniquename
Rename `createUniqueName` to `makeUniqueName`.
2 parents 4ea85ba + f73e3f2 commit 183aa3e

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

Sources/SwiftSyntaxMacros/BasicMacroExpansionContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ extension String {
104104
}
105105
extension BasicMacroExpansionContext: MacroExpansionContext {
106106
/// Generate a unique name for use in the macro.
107-
public func createUniqueName(_ providedName: String) -> TokenSyntax {
107+
public func makeUniqueName(_ providedName: String) -> TokenSyntax {
108108
// If provided with an empty name, substitute in something.
109109
let name = providedName.isEmpty ? "__local" : providedName
110110

Sources/SwiftSyntaxMacros/MacroExpansionContext.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,19 @@ public protocol MacroExpansionContext: AnyObject {
2525
///
2626
/// - Returns: an identifier token containing a unique name that will not
2727
/// conflict with any other name in a well-formed program.
28+
@available(*, renamed: "makeUniqueName(_:)")
2829
func createUniqueName(_ name: String) -> TokenSyntax
2930

31+
/// Generate a unique name for use in the macro.
32+
///
33+
/// - Parameters:
34+
/// - name: The name to use as a basis for the uniquely-generated name,
35+
/// which will appear in the unique name that's produced here.
36+
///
37+
/// - Returns: an identifier token containing a unique name that will not
38+
/// conflict with any other name in a well-formed program.
39+
func makeUniqueName(_ name: String) -> TokenSyntax
40+
3041
/// Produce a diagnostic while expanding the macro.
3142
func diagnose(_ diagnostic: Diagnostic)
3243

@@ -137,6 +148,31 @@ extension MacroExpansionContext {
137148
column: "\(literal: column)"
138149
)
139150
}
151+
152+
/// Generate a unique name for use in the macro.
153+
///
154+
/// - Parameters:
155+
/// - name: The name to use as a basis for the uniquely-generated name,
156+
/// which will appear in the unique name that's produced here.
157+
///
158+
/// - Returns: an identifier token containing a unique name that will not
159+
/// conflict with any other name in a well-formed program.
160+
@available(*, renamed: "makeUniqueName(_:)")
161+
public func createUniqueName(_ name: String) -> TokenSyntax {
162+
makeUniqueName(name)
163+
}
164+
165+
/// Generate a unique name for use in the macro.
166+
///
167+
/// - Parameters:
168+
/// - name: The name to use as a basis for the uniquely-generated name,
169+
/// which will appear in the unique name that's produced here.
170+
///
171+
/// - Returns: an identifier token containing a unique name that will not
172+
/// conflict with any other name in a well-formed program.
173+
public func makeUniqueName(_ name: String) -> TokenSyntax {
174+
createUniqueName(name)
175+
}
140176
}
141177

142178
/// Diagnostic message used for thrown errors.

Tests/SwiftSyntaxMacrosTest/MacroSystemTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,8 @@ final class MacroSystemTests: XCTestCase {
739739
func testContextUniqueLocalNames() {
740740
let context = BasicMacroExpansionContext()
741741

742-
let t1 = context.createUniqueName("mine")
743-
let t2 = context.createUniqueName("mine")
742+
let t1 = context.makeUniqueName("mine")
743+
let t2 = context.makeUniqueName("mine")
744744
XCTAssertNotEqual(t1.description, t2.description)
745745
XCTAssertEqual(t1.description, "__macro_local_4minefMu_")
746746
XCTAssertEqual(t2.description, "__macro_local_4minefMu0_")

0 commit comments

Comments
 (0)