Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 864505a
Author: Cal Stephens <cal@calstephens.tech>
Date:   Thu Mar 7 23:10:56 2024 -0800

    Update SwiftSyntax dependency to 510.0.0 (#1294)

    * Update to SwiftSyntax for Swift 5.10

    * Patch build
  • Loading branch information
art-divin committed Mar 9, 2024
1 parent 581b086 commit ebe455a
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 152 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "2c49d66d34dfd6f8130afdba889de77504b58ec0",
"version" : "508.0.1"
"revision" : "08a2f0a9a30e0f705f79c9cfaca1f68b71bdc775",
"version" : "510.0.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/kylef/PathKit.git", exact: "1.0.1"),
.package(url: "https://github.com/art-divin/StencilSwiftKit.git", exact: "2.10.4"),
.package(url: "https://github.com/tuist/XcodeProj.git", exact: "8.16.0"),
.package(url: "https://github.com/apple/swift-syntax.git", from: "508.0.0"),
.package(url: "https://github.com/apple/swift-syntax.git", from: "510.0.0"),
.package(url: "https://github.com/Quick/Quick.git", from: "3.0.0"),
.package(url: "https://github.com/Quick/Nimble.git", from: "9.0.0"),
.package(url: "https://github.com/art-divin/swift-package-manager.git", from: "1.0.3"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import SwiftSyntax
extension AccessLevel {
init?(_ modifier: Modifier) {
switch modifier.tokenKind {
case .publicKeyword:
case .keyword(.public):
self = .public
case .privateKeyword:
case .keyword(.package):
self = .package
case .keyword(.private):
self = .private
case .fileprivateKeyword:
case .keyword(.fileprivate):
self = .fileprivate
case .internalKeyword:
case .keyword(.internal):
self = .internal
case .contextualKeyword("open"), .identifier("open"):
case .keyword(.open), .identifier("open"):
self = .open
default:
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwiftSyntax

extension Actor {
convenience init(_ node: ActorDeclSyntax, parent: Type?, annotationsParser: AnnotationsParser) {
let modifiers = node.modifiers?.map(Modifier.init) ?? []
let modifiers = node.modifiers.map(Modifier.init) ?? []

self.init(
name: node.identifier.text.trimmingCharacters(in: .whitespaces),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,14 @@ extension Attribute {
}
}

self.init(name: attribute.attributeName.text.trimmed, arguments: arguments, description: attribute.withoutTrivia().description.trimmed)
}

convenience init(_ attribute: CustomAttributeSyntax) {
let nameText = attribute.tokens(viewMode: .fixedUp)
.first(where: \.tokenKind.isIdentifier)?
.text
.trimmed ?? ""

let arguments = attribute.argumentList?
.enumerated()
.reduce(into: [String: NSObject]()) { arguments, indexAndSyntax in
let (index, syntax) = indexAndSyntax
let (key, value) = syntax.keyAndValue
arguments[key ?? "\(index)"] = value as NSString
} ?? [:]

self.init(name: nameText, arguments: arguments, description: attribute.withoutTrivia().description.trimmed)
self.init(name: attribute.attributeName.description.trimmed, arguments: arguments, description: attribute.withoutTrivia().description.trimmed)
}

static func from(_ attributes: AttributeListSyntax?) -> AttributeList {
let array = attributes?
.compactMap { syntax -> Attribute? in
if let syntax = syntax.as(AttributeSyntax.self) {
return Attribute(syntax)
} else if let syntax = syntax.as(CustomAttributeSyntax.self) {
return Attribute(syntax)
} else {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwiftSyntax

extension Class {
convenience init(_ node: ClassDeclSyntax, parent: Type?, annotationsParser: AnnotationsParser) {
let modifiers = node.modifiers?.map(Modifier.init) ?? []
let modifiers = node.modifiers.map(Modifier.init)

let genericRequirements: [GenericRequirement] = node.genericWhereClause?.requirementList.compactMap { requirement in
if let sameType = requirement.body.as(SameTypeRequirementSyntax.self) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwiftSyntax

extension Enum {
convenience init(_ node: EnumDeclSyntax, parent: Type?, annotationsParser: AnnotationsParser) {
let modifiers = node.modifiers?.map(Modifier.init) ?? []
let modifiers = node.modifiers.map(Modifier.init)

//let rawTypeName: String? = node.inheritanceClause?.inheritedTypeCollection.first?.typeName.description.trimmed ?? nil
self.init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,30 @@ extension EnumCase {
externalName = name ?? "\(idx)"
}

var collectedAnnotations = Annotations()
if let typeSyntax = param.type {
collectedAnnotations = annotationsParser.annotations(fromToken: typeSyntax)
}
let collectedAnnotations = annotationsParser.annotations(fromToken: param.type)

return AssociatedValue(localName: name,
externalName: externalName,
typeName: param.type.map { TypeName($0) } ?? TypeName.unknown(description: parent.description.trimmed),
typeName: TypeName(param.type) ?? TypeName.unknown(description: parent.description.trimmed),
type: nil,
defaultValue: defaultValue,
annotations: collectedAnnotations
)
}
}

let rawValue: String? = {
var value = node.rawValue?.withEqual(nil).withTrailingTrivia(.zero).description.trimmed
let rawValue: String? = { () -> String? in
var value = node.rawValue?.value.withoutTrivia().description.trimmed
if let unwrapped = value, unwrapped.hasPrefix("\""), unwrapped.hasSuffix("\""), unwrapped.count > 2 {
let substring = unwrapped[unwrapped.index(after: unwrapped.startIndex) ..< unwrapped.index(before: unwrapped.endIndex)]
value = String(substring)
}
return value
}()

let modifiers = parent.modifiers?.map(Modifier.init) ?? []
let modifiers = parent.modifiers.map(Modifier.init)
let indirect = modifiers.contains(where: {
$0.tokenKind == TokenKind.contextualKeyword("indirect")
$0.tokenKind == .keyword(.indirect)
})

self.init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension SourceryMethod {
parameters: signature.input.parameterList,
output: nil,
asyncKeyword: nil,
throwsOrRethrowsKeyword: signature.throwsOrRethrowsKeyword?.description.trimmed,
throwsOrRethrowsKeyword: signature.effectSpecifiers?.throwsSpecifier?.description.trimmed,
annotationsParser: annotationsParser
),
modifiers: node.modifiers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import SourceryRuntime

extension MethodParameter {
convenience init(_ node: FunctionParameterSyntax, annotationsParser: AnnotationsParser) {
let firstName = node.firstName?.text.trimmed.nilIfNotValidParameterName
let firstName = node.firstName.text.trimmed.nilIfNotValidParameterName

let typeName = node.type.map { TypeName($0) } ?? TypeName.unknown(description: node.description.trimmed)
let typeName = TypeName(node.type)
let specifiers = TypeName.specifiers(from: node.type)

if specifiers.isInOut {
Expand All @@ -21,7 +21,7 @@ extension MethodParameter {
defaultValue: node.defaultArgument?.value.description.trimmed,
annotations: node.firstToken.map { annotationsParser.annotations(fromToken: $0) } ?? [:],
isInout: specifiers.isInOut,
isVariadic: node.type?.as(PackExpansionTypeSyntax.self)?.ellipsis != nil
isVariadic: node.ellipsis != nil
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ extension Array where Element == Modifier {
var isClass: Bool = false

forEach { modifier in
if modifier.tokenKind == .staticKeyword {
if modifier.tokenKind == .keyword(.static) {
isStatic = true
} else if modifier.tokenKind == .classKeyword {
} else if modifier.tokenKind == .keyword(.class) {
isClass = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwiftSyntax

extension SourceryProtocol {
convenience init(_ node: ProtocolDeclSyntax, parent: Type?, annotationsParser: AnnotationsParser) {
let modifiers = node.modifiers?.map(Modifier.init) ?? []
let modifiers = node.modifiers.map(Modifier.init) ?? []

let genericRequirements: [GenericRequirement] = node.genericWhereClause?.requirementList.compactMap { requirement in
if let sameType = requirement.body.as(SameTypeRequirementSyntax.self) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public struct Signature {
public init(_ node: FunctionSignatureSyntax, annotationsParser: AnnotationsParser) {
self.init(parameters: node.input.parameterList,
output: node.output.map { TypeName($0.returnType) },
asyncKeyword: node.asyncOrReasyncKeyword?.text,
throwsOrRethrowsKeyword: node.throwsOrRethrowsKeyword?.description.trimmed,
asyncKeyword: node.effectSpecifiers?.asyncSpecifier?.text,
throwsOrRethrowsKeyword: node.effectSpecifiers?.throwsSpecifier?.description.trimmed,
annotationsParser: annotationsParser
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwiftSyntax

extension Struct {
convenience init(_ node: StructDeclSyntax, parent: Type?, annotationsParser: AnnotationsParser) {
let modifiers = node.modifiers?.map(Modifier.init) ?? []
let modifiers = node.modifiers.map(Modifier.init)

let genericRequirements: [GenericRequirement] = node.genericWhereClause?.requirementList.compactMap { requirement in
if let sameType = requirement.body.as(SameTypeRequirementSyntax.self) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SourceryRuntime

extension Subscript {
convenience init(_ node: SubscriptDeclSyntax, parent: Type, annotationsParser: AnnotationsParser) {
let modifiers = node.modifiers?.map(Modifier.init) ?? []
let modifiers = node.modifiers.map(Modifier.init)
let baseModifiers = modifiers.baseModifiers(parent: parent)
let parentAccess = AccessLevel(rawValue: parent.accessLevel) ?? .internal

Expand All @@ -23,18 +23,25 @@ extension Subscript {
case set
}

let computeAccessors = Set(block.accessors.compactMap { accessor -> Kind? in
let kindRaw = accessor.accessorKind.text.trimmed
if kindRaw == "get" {
return Kind.get(isAsync: accessor.fixedAsyncKeyword != nil, throws: accessor.fixedThrowsKeyword != nil)
}
let computeAccessors: Set<Kind>
switch block.accessors {
case .getter:
computeAccessors = [.get(isAsync: false, throws: false)]

if kindRaw == "set" {
return Kind.set
}
case .accessors(let accessors):
computeAccessors = Set(accessors.compactMap { accessor -> Kind? in
let kindRaw = accessor.accessorKind.text.trimmed
if kindRaw == "get" {
return Kind.get(isAsync: accessor.effectSpecifiers?.asyncSpecifier != nil, throws: accessor.effectSpecifiers?.throwsSpecifier != nil)
}

return nil
})
if kindRaw == "set" {
return Kind.set
}

return nil
})
}

if !computeAccessors.isEmpty {
if !computeAccessors.contains(Kind.set) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ extension TypeName {
name: node.secondName?.text.trimmed ?? firstName,
typeName: typeName,
isInout: specifiers.isInOut,
isVariadic: node.type.as(PackExpansionTypeSyntax.self)?.ellipsis != nil
isVariadic: node.ellipsis != nil
)
}
let returnTypeName = TypeName(typeIdentifier.returnType)
let asyncKeyword = typeIdentifier.fixedAsyncKeyword.map { $0.text.trimmed }
let throwsOrRethrows = typeIdentifier.fixedThrowsOrRethrowsKeyword.map { $0.text.trimmed }
let returnTypeName = TypeName(typeIdentifier.returnClause.type)
let asyncKeyword = typeIdentifier.effectSpecifiers?.asyncSpecifier.map { $0.text.trimmed }
let throwsOrRethrows = typeIdentifier.effectSpecifiers?.throwsSpecifier.map { $0.text.trimmed }
let name = "\(elements.asSource)\(asyncKeyword != nil ? " \(asyncKeyword!)" : "")\(throwsOrRethrows != nil ? " \(throwsOrRethrows!)" : "") -> \(returnTypeName.asSource)"
self.init(
name: name,
Expand Down Expand Up @@ -199,7 +199,7 @@ extension TypeName {

var isInOut = false
if let typeIdentifier = type.as(AttributedTypeSyntax.self), let specifier = typeIdentifier.specifier {
if specifier.tokenKind == .inoutKeyword {
if specifier.tokenKind == .keyword(.inout) {
isInOut = true
} else {
assertionFailure("Unhandled specifier")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,25 @@ extension Variable {
case set
}

let computeAccessors = Set(block.accessors.compactMap { accessor -> Kind? in
let kindRaw = accessor.accessorKind.text.trimmed
if kindRaw == "get" {
return Kind.get(isAsync: accessor.fixedAsyncKeyword != nil, throws: accessor.fixedThrowsKeyword != nil)
}

if kindRaw == "set" {
return Kind.set
}

return nil
})
let computeAccessors: Set<Kind>
switch block.accessors {
case .getter:
computeAccessors = [.get(isAsync: false, throws: false)]

case .accessors(let accessors):
computeAccessors = Set(accessors.compactMap { accessor -> Kind? in
let kindRaw = accessor.accessorKind.text.trimmed
if kindRaw == "get" {
return Kind.get(isAsync: accessor.effectSpecifiers?.asyncSpecifier != nil, throws: accessor.effectSpecifiers?.throwsSpecifier != nil)
}

if kindRaw == "set" {
return Kind.set
}

return nil
})
}

if !computeAccessors.isEmpty {
if !computeAccessors.contains(Kind.set) {
Expand All @@ -64,7 +71,7 @@ extension Variable {
let isComputed = node.initializer == nil && hadGetter && !isVisitingTypeSourceryProtocol
let isAsync = hadAsync
let `throws` = hadThrowable
let isWritable = variableNode.letOrVarKeyword.tokens(viewMode: .fixedUp).contains { $0.tokenKind == .varKeyword } && (!isComputed || hadSetter)
let isWritable = variableNode.bindingSpecifier.tokens(viewMode: .fixedUp).contains { $0.tokenKind == .keyword(.var) } && (!isComputed || hadSetter)

var typeName: TypeName? = node.typeAnnotation.map { TypeName($0.type) } ??
node.initializer.flatMap { Self.inferType($0.value.description.trimmed) }
Expand All @@ -91,16 +98,16 @@ extension Variable {
defaultValue: node.initializer?.value.description.trimmingCharacters(in: .whitespacesAndNewlines),
attributes: Attribute.from(variableNode.attributes),
modifiers: modifiers.map(SourceryModifier.init),
annotations: annotationParser.annotations(fromToken: variableNode.letOrVarKeyword),
documentation: annotationParser.documentation(fromToken: variableNode.letOrVarKeyword),
annotations: annotationParser.annotations(fromToken: variableNode.bindingSpecifier),
documentation: annotationParser.documentation(fromToken: variableNode.bindingSpecifier),
definedInTypeName: visitingType.map { TypeName($0.name) }
)
}

static func from(_ variableNode: VariableDeclSyntax, visitingType: Type?,
annotationParser: AnnotationsParser) -> [Variable] {

let modifiers = variableNode.modifiers?.map(Modifier.init) ?? []
let modifiers = variableNode.modifiers.map(Modifier.init)
let baseModifiers = modifiers.baseModifiers(parent: visitingType)

return variableNode.bindings.map { (node: PatternBindingSyntax) -> Variable in
Expand Down
Loading

0 comments on commit ebe455a

Please sign in to comment.