diff --git a/Package.resolved b/Package.resolved index 54b681c4c..2ef2d8910 100644 --- a/Package.resolved +++ b/Package.resolved @@ -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" } }, { diff --git a/Package.swift b/Package.swift index b596a71eb..af2376e1b 100644 --- a/Package.swift +++ b/Package.swift @@ -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"), diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/AccessLevel+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/AccessLevel+SwiftSyntax.swift index 170372173..7c0c4e2b0 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/AccessLevel+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/AccessLevel+SwiftSyntax.swift @@ -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 diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Actor+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Actor+SwiftSyntax.swift index abe868ca8..1a125d04f 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Actor+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Actor+SwiftSyntax.swift @@ -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), diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Attribute+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Attribute+SwiftSyntax.swift index ae246ad54..1f18fe9ac 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Attribute+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Attribute+SwiftSyntax.swift @@ -21,24 +21,7 @@ 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 { @@ -46,8 +29,6 @@ extension Attribute { .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 } diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Class+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Class+SwiftSyntax.swift index 9e8026e2c..1044ec8a1 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Class+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Class+SwiftSyntax.swift @@ -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) { diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Enum+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Enum+SwiftSyntax.swift index d1df87099..07fafb600 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Enum+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Enum+SwiftSyntax.swift @@ -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( diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/EnumCase+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/EnumCase+SwiftSyntax.swift index 3db126061..c819a9a4d 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/EnumCase+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/EnumCase+SwiftSyntax.swift @@ -20,14 +20,11 @@ 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 @@ -35,8 +32,8 @@ extension EnumCase { } } - 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) @@ -44,9 +41,9 @@ extension EnumCase { 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( diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Method+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Method+SwiftSyntax.swift index 11f9c404e..12fa08a53 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Method+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Method+SwiftSyntax.swift @@ -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, diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/MethodParameter+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/MethodParameter+SwiftSyntax.swift index 5e8f674e9..0ef580ac3 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/MethodParameter+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/MethodParameter+SwiftSyntax.swift @@ -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 { @@ -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 ) } } diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Modifier+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Modifier+SwiftSyntax.swift index 584408aaa..8c45aeab9 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Modifier+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Modifier+SwiftSyntax.swift @@ -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 } diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Protocol+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Protocol+SwiftSyntax.swift index d1b1f9eb6..f184619fb 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Protocol+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Protocol+SwiftSyntax.swift @@ -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) { diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Signature.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Signature.swift index b4a5ade96..2e0f3dd90 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Signature.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Signature.swift @@ -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 ) } diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Struct+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Struct+SwiftSyntax.swift index 5ab357256..929c40766 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Struct+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Struct+SwiftSyntax.swift @@ -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) { diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Subscript+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Subscript+SwiftSyntax.swift index c72dd9667..0a091fd41 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Subscript+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Subscript+SwiftSyntax.swift @@ -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 @@ -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 + 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) { diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/TypeName+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/TypeName+SwiftSyntax.swift index 2e7bb5641..8436561af 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/TypeName+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/TypeName+SwiftSyntax.swift @@ -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, @@ -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") diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Variable+SwiftSyntax.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Variable+SwiftSyntax.swift index 9146ecf46..fc168ada2 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Variable+SwiftSyntax.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/AST/Variable+SwiftSyntax.swift @@ -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 + 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) { @@ -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) } @@ -91,8 +98,8 @@ 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) } ) } @@ -100,7 +107,7 @@ extension Variable { 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 diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/Syntax+Extensions.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/Syntax+Extensions.swift index 75330a60f..98ffb636c 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/Syntax+Extensions.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/Syntax+Extensions.swift @@ -12,7 +12,8 @@ public extension TriviaPiece { .carriageReturns, .carriageReturnLineFeeds, .unexpectedText, - .shebang: + .backslashes, + .pounds: return nil case .lineComment(let comment), .blockComment(let comment), @@ -23,62 +24,6 @@ public extension TriviaPiece { } } -// seems to be bug in SwiftSyntax -public protocol AsyncThrowsFixup { - var asyncKeyword: TokenSyntax? { get } - var throwsKeyword: TokenSyntax? { get } - - var fixedAsyncKeyword: TokenSyntax? { get } - var fixedThrowsKeyword: TokenSyntax? { get } -} - -public protocol AsyncReThrowsFixup { - var asyncKeyword: TokenSyntax? { get } - var throwsOrRethrowsKeyword: TokenSyntax? { get } - - var fixedAsyncKeyword: TokenSyntax? { get } - var fixedThrowsOrRethrowsKeyword: TokenSyntax? { get } -} - - -public extension AsyncThrowsFixup { - var fixedAsyncKeyword: TokenSyntax? { - if asyncKeyword?.tokenKind == .throwsKeyword { - return nil - } - - return asyncKeyword - } - - var fixedThrowsKeyword: TokenSyntax? { - if asyncKeyword?.tokenKind == .throwsKeyword && throwsKeyword == nil { - return asyncKeyword - } else { - return throwsKeyword - } - } -} - -public extension AsyncReThrowsFixup { - var fixedAsyncKeyword: TokenSyntax? { - if asyncKeyword?.tokenKind == .throwsKeyword { - return nil - } - - return asyncKeyword - } - - var fixedThrowsOrRethrowsKeyword: TokenSyntax? { - if asyncKeyword?.tokenKind == .throwsKeyword && throwsOrRethrowsKeyword == nil { - return asyncKeyword - } else { - return throwsOrRethrowsKeyword - } - } -} -extension AccessorListSyntax.Element: AsyncThrowsFixup {} -extension FunctionTypeSyntax: AsyncReThrowsFixup {} - protocol IdentifierSyntax: SyntaxProtocol { var identifier: TokenSyntax { get } } @@ -100,3 +45,10 @@ extension TypealiasDeclSyntax: IdentifierSyntax {} extension OperatorDeclSyntax: IdentifierSyntax {} extension EnumCaseElementSyntax: IdentifierSyntax {} + +extension SyntaxProtocol { + func withoutTrivia() -> Self { + with(\.leadingTrivia, []) + .with(\.trailingTrivia, []) + } +} diff --git a/SourceryFramework/Sources/Parsing/SwiftSyntax/SyntaxTreeCollector.swift b/SourceryFramework/Sources/Parsing/SwiftSyntax/SyntaxTreeCollector.swift index cb7758425..dde22baac 100644 --- a/SourceryFramework/Sources/Parsing/SwiftSyntax/SyntaxTreeCollector.swift +++ b/SourceryFramework/Sources/Parsing/SwiftSyntax/SyntaxTreeCollector.swift @@ -123,7 +123,7 @@ class SyntaxTreeCollector: SyntaxVisitor { public override func visit(_ node: ExtensionDeclSyntax) -> SyntaxVisitorContinueKind { startVisitingType(node) { parent in - let modifiers = node.modifiers?.map(Modifier.init) ?? [] + let modifiers = node.modifiers.map(Modifier.init) let base = modifiers.baseModifiers(parent: nil) return Type( @@ -204,7 +204,7 @@ class SyntaxTreeCollector: SyntaxVisitor { public override func visit(_ node: TypealiasDeclSyntax) -> SyntaxVisitorContinueKind { let localName = node.identifier.text.trimmed let typeName = TypeName(node.initializer.value) - let modifiers = node.modifiers?.map(Modifier.init) ?? [] + let modifiers = node.modifiers.map(Modifier.init) let baseModifiers = modifiers.baseModifiers(parent: visitingType) let annotations = annotationsParser.annotations(from: node) let documentation = annotationsParser.documentation(from: node) diff --git a/SourceryFramework/Sources/Parsing/Utils/AnnotationsParser.swift b/SourceryFramework/Sources/Parsing/Utils/AnnotationsParser.swift index 81415adb4..bf5ddf426 100644 --- a/SourceryFramework/Sources/Parsing/Utils/AnnotationsParser.swift +++ b/SourceryFramework/Sources/Parsing/Utils/AnnotationsParser.swift @@ -99,15 +99,11 @@ public struct AnnotationsParser { } private func from(location: SwiftSyntax.SourceLocation) -> Annotations { - guard let lineNumber = location.line, let column = location.column else { - return [:] - } - var stop = false - var annotations = inlineFrom(line: (lineNumber, column), stop: &stop) + var annotations = inlineFrom(line: (location.line, location.column), stop: &stop) guard !stop else { return annotations } - let reversedArray = lines[0.. Documentation { - guard parseDocumentation, - let lineNumber = location.line, let column = location.column else { + guard parseDocumentation else { return [] } // Inline documentation not currently supported - _ = column + _ = location.column // var stop = false // var documentation = inlineDocumentationFrom(line: (lineNumber, column), stop: &stop) @@ -144,7 +139,7 @@ public struct AnnotationsParser { var documentation: Documentation = [] - for line in lines[0..