13
13
import SwiftSyntax
14
14
15
15
/// An entity that is implicitly declared based on the syntactic structure of the program.
16
- @ _spi ( Experimental ) public enum ImplicitDecl {
16
+ public enum ImplicitDecl {
17
17
/// `self` keyword representing object instance.
18
- /// Could be associated with type declaration, extension,
19
- /// or closure captures. Introduced at function edge.
20
- case `self`( DeclSyntaxProtocol )
18
+ /// Introduced at member boundary.
19
+ /// Associated syntax node could be: `FunctionDeclSyntax`,
20
+ /// `AccessorDeclSyntax`, `SubscriptDeclSyntax`,
21
+ /// `DeinitializerDeclSyntax`, or `InitializerDeclSyntax`.
22
+ case `self`( DeclSyntax )
21
23
/// `Self` keyword representing object type.
22
- /// Could be associated with type declaration or extension.
23
- case `Self`( DeclSyntaxProtocol )
24
- /// `error` value caught by a `catch`
24
+ /// Associated syntax node could be: `ExtensionDeclSyntax`,
25
+ /// or `ProtocolDeclSyntax`.
26
+ case `Self`( DeclSyntax )
27
+ /// `error` available by default inside `catch`
25
28
/// block that does not specify a catch pattern.
26
29
case error( CatchClauseSyntax )
27
30
/// `newValue` available by default inside `set` and `willSet`.
@@ -30,7 +33,7 @@ import SwiftSyntax
30
33
case oldValue( AccessorDeclSyntax )
31
34
32
35
/// Syntax associated with this name.
33
- @ _spi ( Experimental ) public var syntax : SyntaxProtocol {
36
+ public var syntax : SyntaxProtocol {
34
37
switch self {
35
38
case . self ( let syntax) :
36
39
return syntax
@@ -46,7 +49,7 @@ import SwiftSyntax
46
49
}
47
50
48
51
/// The name of the implicit declaration.
49
- private var name : StaticString {
52
+ public var name : StaticString {
50
53
switch self {
51
54
case . self :
52
55
return " self "
@@ -85,12 +88,12 @@ import SwiftSyntax
85
88
/// ```
86
89
/// `self` and `Self` identifers override implicit `self` and `Self` introduced by
87
90
/// the `Foo` class declaration.
88
- var identifier : Identifier {
91
+ public var identifier : Identifier {
89
92
Identifier ( canonicalName: name)
90
93
}
91
94
92
95
/// Position of this implicit name.
93
- @ _spi ( Experimental ) public var position : AbsolutePosition {
96
+ public var position : AbsolutePosition {
94
97
switch self {
95
98
case . self ( let declSyntax) :
96
99
switch Syntax ( declSyntax) . as ( SyntaxEnum . self) {
@@ -128,17 +131,15 @@ import SwiftSyntax
128
131
}
129
132
}
130
133
131
- @ _spi ( Experimental ) public enum LookupName {
134
+ public enum LookupName {
132
135
/// Identifier associated with the name.
133
136
/// Could be an identifier of a variable, function or closure parameter and more.
134
- case identifier( IdentifiableSyntax , accessibleAfter: AbsolutePosition ? )
137
+ case identifier( Syntax , accessibleAfter: AbsolutePosition ? )
135
138
/// Declaration associated with the name.
136
139
/// Could be class, struct, actor, protocol, function and more.
137
- case declaration( NamedDeclSyntax )
140
+ case declaration( Syntax )
138
141
/// Name introduced implicitly by certain syntax nodes.
139
142
case implicit( ImplicitDecl )
140
- /// Dollar identifier introduced by a closure without parameters.
141
- case dollarIdentifier( ClosureExprSyntax , strRepresentation: String )
142
143
/// Represents equivalent names grouped together.
143
144
/// - Important: The array should be non-empty.
144
145
///
@@ -154,32 +155,28 @@ import SwiftSyntax
154
155
case equivalentNames( [ LookupName ] )
155
156
156
157
/// Syntax associated with this name.
157
- @ _spi ( Experimental ) public var syntax : SyntaxProtocol {
158
+ public var syntax : SyntaxProtocol {
158
159
switch self {
159
160
case . identifier( let syntax, _) :
160
161
return syntax
161
162
case . declaration( let syntax) :
162
163
return syntax
163
164
case . implicit( let implicitName) :
164
165
return implicitName. syntax
165
- case . dollarIdentifier( let closureExpr, _) :
166
- return closureExpr
167
166
case . equivalentNames( let names) :
168
167
return names. first!. syntax
169
168
}
170
169
}
171
170
172
171
/// Identifier used for name comparison.
173
- @ _spi ( Experimental ) public var identifier : Identifier ? {
172
+ public var identifier : Identifier {
174
173
switch self {
175
174
case . identifier( let syntax, _) :
176
- return Identifier ( syntax. identifier)
175
+ return Identifier ( ( syntax. asProtocol ( SyntaxProtocol . self ) as! IdentifiableSyntax ) . identifier) !
177
176
case . declaration( let syntax) :
178
- return Identifier ( syntax. name)
177
+ return Identifier ( ( syntax. asProtocol ( SyntaxProtocol . self ) as! NamedDeclSyntax ) . name) !
179
178
case . implicit( let kind) :
180
179
return kind. identifier
181
- case . dollarIdentifier( _, strRepresentation: _) :
182
- return nil
183
180
case . equivalentNames( let names) :
184
181
return names. first!. identifier
185
182
}
@@ -192,16 +189,15 @@ import SwiftSyntax
192
189
/// Such cases are function parameters (as they can
193
190
/// contain two identifiers) and function declarations (where name
194
191
/// is precided by access modifiers and `func` keyword).
195
- @ _spi ( Experimental ) public var position : AbsolutePosition {
192
+ public var position : AbsolutePosition {
196
193
switch self {
197
194
case . identifier( let syntax, _) :
198
- return syntax. identifier. positionAfterSkippingLeadingTrivia
195
+ return ( syntax. asProtocol ( SyntaxProtocol . self) as! IdentifiableSyntax ) . identifier
196
+ . positionAfterSkippingLeadingTrivia
199
197
case . declaration( let syntax) :
200
- return syntax. name. positionAfterSkippingLeadingTrivia
198
+ return ( syntax. asProtocol ( SyntaxProtocol . self ) as! NamedDeclSyntax ) . name. positionAfterSkippingLeadingTrivia
201
199
case . implicit( let implicitName) :
202
200
return implicitName. position
203
- case . dollarIdentifier( let closureExpr, _) :
204
- return closureExpr. positionAfterSkippingLeadingTrivia
205
201
case . equivalentNames( let names) :
206
202
return names. first!. position
207
203
}
@@ -226,13 +222,7 @@ import SwiftSyntax
226
222
227
223
func refersTo( _ otherIdentifier: Identifier ? ) -> Bool {
228
224
guard let otherIdentifier else { return true }
229
-
230
- switch self {
231
- case . dollarIdentifier( _, let strRepresentation) :
232
- return strRepresentation == otherIdentifier. name
233
- default :
234
- return identifier == otherIdentifier
235
- }
225
+ return identifier == otherIdentifier
236
226
}
237
227
238
228
/// Extracts names introduced by the given `syntax` structure.
@@ -305,22 +295,22 @@ import SwiftSyntax
305
295
return [ ]
306
296
}
307
297
308
- return [ . identifier( identifiable, accessibleAfter: accessibleAfter) ]
298
+ return [ . identifier( Syntax ( identifiable) , accessibleAfter: accessibleAfter) ]
309
299
}
310
300
311
301
/// Extracts name introduced by `NamedDeclSyntax` node.
312
302
private static func handle(
313
303
namedDecl: NamedDeclSyntax ,
314
304
accessibleAfter: AbsolutePosition ? = nil
315
305
) -> [ LookupName ] {
316
- [ . declaration( namedDecl) ]
306
+ [ . declaration( Syntax ( namedDecl) ) ]
317
307
}
318
308
319
309
/// Debug description of this lookup name.
320
- @ _spi ( Experimental ) public var debugDescription : String {
310
+ public var debugDescription : String {
321
311
let sourceLocationConverter = SourceLocationConverter ( fileName: " " , tree: syntax. root)
322
312
let location = sourceLocationConverter. location ( for: position)
323
- let strName = ( identifier? . name ?? " NO-NAME " ) + " at: \( location. line) : \( location. column) "
313
+ let strName = identifier. name + " at: \( location. line) : \( location. column) "
324
314
325
315
switch self {
326
316
case . identifier:
@@ -336,8 +326,6 @@ import SwiftSyntax
336
326
return " declaration: \( strName) "
337
327
case . implicit:
338
328
return " implicit: \( strName) "
339
- case . dollarIdentifier( _, strRepresentation: let str) :
340
- return " dollarIdentifier: \( str) "
341
329
case . equivalentNames( let names) :
342
330
return " Composite name: [ \( names. map ( \. debugDescription) . joined ( separator: " , " ) ) ] "
343
331
}
0 commit comments