Skip to content

Commit bd5bcd3

Browse files
committed
Generate compatibility layer for renamed syntax nodes
1 parent 41435de commit bd5bcd3

File tree

5 files changed

+120
-43
lines changed

5 files changed

+120
-43
lines changed

CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,23 @@ public enum SyntaxNodeKind: String, CaseIterable {
369369
return "Raw\(raw: rawValue.withFirstCharacterUppercased)SyntaxNodeProtocol"
370370
}
371371
}
372+
373+
public var deprecatedRawValue: String? {
374+
switch self {
375+
case .importPathComponentList:
376+
return "accessPath"
377+
case .importPathComponent:
378+
return "accessPathComponent"
379+
case .documentationAttributeArgumentList:
380+
return "documentationAttributeArguments"
381+
case .effectsArgumentList:
382+
return "effectsArguments"
383+
case .objCSelectorPieceList:
384+
return "objCSelector"
385+
case .stringLiteralSegmentList:
386+
return "stringLiteralSegments"
387+
default:
388+
return nil
389+
}
390+
}
372391
}

CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ struct GenerateSwiftSyntax: ParsableCommand {
9797
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["raw", "RawSyntaxNodes.swift"], rawSyntaxNodesFile),
9898
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["raw", "RawSyntaxValidation.swift"], rawSyntaxValidationFile),
9999
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["RenamedChildrenCompatibility.swift"], renamedChildrenCompatibilityFile),
100+
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["RenamedNodesCompatibility.swift"], renamedSyntaxNodesFile),
100101
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxAnyVisitor.swift"], syntaxAnyVisitorFile),
101102
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxBaseNodes.swift"], syntaxBaseNodesFile),
102103
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxCollections.swift"], syntaxCollectionsFile),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import SwiftSyntax
14+
import SwiftSyntaxBuilder
15+
import SyntaxSupport
16+
import Utils
17+
18+
let renamedSyntaxNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
19+
for syntaxKind in SyntaxNodeKind.allCases.sorted(by: { $0.deprecatedRawValue ?? "" < $1.deprecatedRawValue ?? "" }) {
20+
if let deprecatedName = syntaxKind.deprecatedRawValue {
21+
DeclSyntax(
22+
"""
23+
@available(*, deprecated, renamed: "\(syntaxKind.syntaxType)")
24+
public typealias \(raw: deprecatedName.withFirstCharacterUppercased)Syntax = \(syntaxKind.syntaxType)
25+
"""
26+
)
27+
}
28+
}
29+
30+
try! ExtensionDeclSyntax("public extension SyntaxKind") {
31+
for syntaxKind in SyntaxNodeKind.allCases.sorted(by: { $0.deprecatedRawValue ?? "" < $1.deprecatedRawValue ?? "" }) {
32+
if let deprecatedName = syntaxKind.deprecatedRawValue {
33+
DeclSyntax(
34+
"""
35+
static var \(raw: deprecatedName): Self {
36+
return .\(syntaxKind.varOrCaseName)
37+
}
38+
"""
39+
)
40+
}
41+
}
42+
}
43+
}

Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
// This file provides compatibility aliases to keep dependents of SwiftSyntax building.
1414
// All users of the declarations in this file should transition away from them ASAP.
1515

16-
@available(*, deprecated, renamed: "ImportPathSyntax")
17-
public typealias AccessPathSyntax = ImportPathSyntax
18-
19-
@available(*, deprecated, renamed: "ImportPathComponentSyntax")
20-
public typealias AccessPathComponentSyntax = ImportPathComponentSyntax
21-
2216
extension AttributeSyntax {
2317
@available(*, deprecated, renamed: "Arguments")
2418
public typealias Argument = Arguments
@@ -51,12 +45,6 @@ public extension DeclGroupSyntax {
5145
}
5246
}
5347

54-
@available(*, deprecated, renamed: "DocumentationAttributeArgumentListSyntax")
55-
public typealias DocumentationAttributeArgumentsSyntax = DocumentationAttributeArgumentListSyntax
56-
57-
@available(*, deprecated, renamed: "EffectsArgumentListSyntax")
58-
public typealias EffectsArgumentsSyntax = EffectsArgumentListSyntax
59-
6048
public extension FreestandingMacroExpansionSyntax {
6149
@available(*, deprecated, renamed: "genericArgumentClause")
6250
var genericArguments: GenericArgumentClauseSyntax? {
@@ -89,47 +77,16 @@ extension IdentifiedDeclSyntax where Self: NamedDeclSyntax {
8977
}
9078
}
9179

92-
@available(*, deprecated, renamed: "ImportPathComponentListSyntax")
93-
public typealias ImportPathSyntax = ImportPathComponentListSyntax
94-
95-
@available(*, deprecated, renamed: "ObjCSelectorPieceListSyntax")
96-
public typealias ObjCSelector = ObjCSelectorPieceListSyntax
97-
9880
extension PatternBindingSyntax {
9981
@available(*, deprecated, renamed: "Accessors")
10082
public typealias Accessor = Accessors
10183
}
10284

103-
@available(*, deprecated, renamed: "StringLiteralSegmentListSyntax")
104-
public typealias StringLiteralSegmentsSyntax = StringLiteralSegmentListSyntax
105-
10685
extension SubscriptDeclSyntax {
10786
@available(*, deprecated, renamed: "Accessors")
10887
public typealias Accessor = Accessors
10988
}
11089

111-
public extension SyntaxKind {
112-
static var documentationAttributeArguments: Self {
113-
return .documentationAttributeArgumentList
114-
}
115-
116-
static var effectsArguments: Self {
117-
return .effectsArgumentList
118-
}
119-
120-
static var importPath: Self {
121-
return .importPathComponentList
122-
}
123-
124-
static var objCSelector: Self {
125-
return .objCSelectorPieceList
126-
}
127-
128-
static var stringLiteralSegments: Self {
129-
return .stringLiteralSegmentList
130-
}
131-
}
132-
13390
public extension SyntaxProtocol {
13491
@available(*, deprecated, message: "Use detached computed property instead.")
13592
func detach() -> Self {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//// Automatically generated by generate-swiftsyntax
2+
//// Do not edit directly!
3+
//===----------------------------------------------------------------------===//
4+
//
5+
// This source file is part of the Swift.org open source project
6+
//
7+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
8+
// Licensed under Apache License v2.0 with Runtime Library Exception
9+
//
10+
// See https://swift.org/LICENSE.txt for license information
11+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
@available(*, deprecated, renamed: "ImportPathComponentListSyntax")
16+
public typealias AccessPathSyntax = ImportPathComponentListSyntax
17+
18+
@available(*, deprecated, renamed: "ImportPathComponentSyntax")
19+
public typealias AccessPathComponentSyntax = ImportPathComponentSyntax
20+
21+
@available(*, deprecated, renamed: "DocumentationAttributeArgumentListSyntax")
22+
public typealias DocumentationAttributeArgumentsSyntax = DocumentationAttributeArgumentListSyntax
23+
24+
@available(*, deprecated, renamed: "EffectsArgumentListSyntax")
25+
public typealias EffectsArgumentsSyntax = EffectsArgumentListSyntax
26+
27+
@available(*, deprecated, renamed: "ObjCSelectorPieceListSyntax")
28+
public typealias ObjCSelectorSyntax = ObjCSelectorPieceListSyntax
29+
30+
@available(*, deprecated, renamed: "StringLiteralSegmentListSyntax")
31+
public typealias StringLiteralSegmentsSyntax = StringLiteralSegmentListSyntax
32+
33+
public extension SyntaxKind {
34+
static var accessPath: Self {
35+
return .importPathComponentList
36+
}
37+
38+
static var accessPathComponent: Self {
39+
return .importPathComponent
40+
}
41+
42+
static var documentationAttributeArguments: Self {
43+
return .documentationAttributeArgumentList
44+
}
45+
46+
static var effectsArguments: Self {
47+
return .effectsArgumentList
48+
}
49+
50+
static var objCSelector: Self {
51+
return .objCSelectorPieceList
52+
}
53+
54+
static var stringLiteralSegments: Self {
55+
return .stringLiteralSegmentList
56+
}
57+
}

0 commit comments

Comments
 (0)