-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from p-x9/feature/enum-case-alias
Enum case alias
- Loading branch information
Showing
6 changed files
with
336 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,6 @@ extension AttributeListSyntax { | |
} | ||
return true | ||
} | ||
return .init(attributes) | ||
return attributes | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
Sources/AliasSupport/Extesnsion/EnumCaseParameterListSyntax+.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// EnumCaseParameterListSyntax+.swift | ||
// | ||
// | ||
// Created by p-x9 on 2023/11/07. | ||
// | ||
// | ||
|
||
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
|
||
extension EnumCaseParameterListSyntax { | ||
package var functionParameterListSyntax: FunctionParameterListSyntax { | ||
let parameters: [FunctionParameterSyntax] = self.enumerated() | ||
.map { | ||
if let firstName = $1.firstName, $1.secondName == nil { | ||
return "\(firstName.trimmed): \($1.type)" | ||
} else if let firstName = $1.firstName, let secondName = $1.secondName { | ||
return "\(firstName.trimmed) \(secondName.trimmed): \($1.type)" | ||
} else { | ||
return "_ arg\(raw: $0): \($1.type.trimmed)" | ||
} | ||
} | ||
return .init(parameters) | ||
} | ||
|
||
package var labeledExprListSyntax: LabeledExprListSyntax { | ||
let arguments: [LabeledExprSyntax] = self.enumerated() | ||
.map { | ||
if let firstName = $1.firstName, $1.secondName == nil { | ||
return .init(label: "\(firstName.trimmed)", | ||
expression: ExprSyntax("\(firstName.trimmed)")) | ||
} else if let firstName = $1.firstName, let secondName = $1.secondName { | ||
return .init(label: "\(firstName.trimmed)", | ||
expression: ExprSyntax("\(secondName.trimmed)")) | ||
} else { | ||
return .init(expression: ExprSyntax("arg\(raw: $0)")) | ||
} | ||
} | ||
return .init(arguments) | ||
} | ||
} |
Oops, something went wrong.