Skip to content

Rename createUniqueName to makeUniqueName. #1367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ extension String {
}
extension BasicMacroExpansionContext: MacroExpansionContext {
/// Generate a unique name for use in the macro.
public func createUniqueName(_ providedName: String) -> TokenSyntax {
public func makeUniqueName(_ providedName: String) -> TokenSyntax {
// If provided with an empty name, substitute in something.
let name = providedName.isEmpty ? "__local" : providedName

Expand Down
36 changes: 36 additions & 0 deletions Sources/SwiftSyntaxMacros/MacroExpansionContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ public protocol MacroExpansionContext: AnyObject {
///
/// - Returns: an identifier token containing a unique name that will not
/// conflict with any other name in a well-formed program.
@available(*, renamed: "makeUniqueName(_:)")
func createUniqueName(_ name: String) -> TokenSyntax

/// Generate a unique name for use in the macro.
///
/// - Parameters:
/// - name: The name to use as a basis for the uniquely-generated name,
/// which will appear in the unique name that's produced here.
///
/// - Returns: an identifier token containing a unique name that will not
/// conflict with any other name in a well-formed program.
func makeUniqueName(_ name: String) -> TokenSyntax

/// Produce a diagnostic while expanding the macro.
func diagnose(_ diagnostic: Diagnostic)

Expand Down Expand Up @@ -137,6 +148,31 @@ extension MacroExpansionContext {
column: "\(literal: column)"
)
}

/// Generate a unique name for use in the macro.
///
/// - Parameters:
/// - name: The name to use as a basis for the uniquely-generated name,
/// which will appear in the unique name that's produced here.
///
/// - Returns: an identifier token containing a unique name that will not
/// conflict with any other name in a well-formed program.
@available(*, renamed: "makeUniqueName(_:)")
public func createUniqueName(_ name: String) -> TokenSyntax {
makeUniqueName(name)
}

/// Generate a unique name for use in the macro.
///
/// - Parameters:
/// - name: The name to use as a basis for the uniquely-generated name,
/// which will appear in the unique name that's produced here.
///
/// - Returns: an identifier token containing a unique name that will not
/// conflict with any other name in a well-formed program.
public func makeUniqueName(_ name: String) -> TokenSyntax {
createUniqueName(name)
}
}

/// Diagnostic message used for thrown errors.
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftSyntaxMacrosTest/MacroSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,8 @@ final class MacroSystemTests: XCTestCase {
func testContextUniqueLocalNames() {
let context = BasicMacroExpansionContext()

let t1 = context.createUniqueName("mine")
let t2 = context.createUniqueName("mine")
let t1 = context.makeUniqueName("mine")
let t2 = context.makeUniqueName("mine")
XCTAssertNotEqual(t1.description, t2.description)
XCTAssertEqual(t1.description, "__macro_local_4minefMu_")
XCTAssertEqual(t2.description, "__macro_local_4minefMu0_")
Expand Down