You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Returns all labeled statements available at a particular syntax node.
18
+
///
19
+
/// - Returns: Available labeled statements at a particular syntax node in the exact order they appear in the source code, starting with the innermost statement.
20
+
///
21
+
/// Example usage:
22
+
/// ```swift
23
+
/// one: while cond1 {
24
+
/// func foo() {
25
+
/// two: while cond2 {
26
+
/// three: while cond3 {
27
+
/// break // 1
28
+
/// }
29
+
/// break // 2
30
+
/// }
31
+
/// }
32
+
/// break // 3
33
+
/// }
34
+
/// ```
35
+
/// When calling this function at the first `break`, it returns `three` and `two` in this exact order. For the second `break`, it returns only `two`. The results don't include `one`, which is unavailable at both locations due to the encapsulating function body. For `break` numbered 3, the result is `one`, as it's outside the function body and within the labeled statement. The function returns an empty array when there are no available labeled statements.
/// Returns the catch node responsible for handling an error thrown at a particular syntax node.
42
+
///
43
+
/// - Returns: The catch node responsible for handling an error thrown at the lookup source node. This could be a `do` statement, `try?`, `try!`, `init`, `deinit`, accessors, closures, or function declarations.
44
+
///
45
+
/// Example usage:
46
+
/// ```swift
47
+
/// func x() {
48
+
/// do {
49
+
/// try foo()
50
+
/// try? bar()
51
+
/// } catch {
52
+
/// throw error
53
+
/// }
54
+
/// }
55
+
/// ```
56
+
/// When calling this function on `foo`, it returns the `do` statement. Calling the function on `bar` results in `try?`. When used on `error`, the function returns the function declaration `x`. The function returns `nil` when there's no available catch node.
if stopAt.contains(where:{ currentSyntax.is($0)}){
145
+
break
166
146
}
167
-
}else{
168
-
returnwalkParentTree(
169
-
upTo: stopAt,
170
-
at: syntax.parent,
171
-
collect: collect,
172
-
stopWithFirstMatch: stopWithFirstMatch
147
+
148
+
iflet matchedSyntax = currentSyntax.as(T.self){
149
+
matches.append(matchedSyntax)
150
+
if stopWithFirstMatch {
151
+
break
152
+
}
153
+
}
154
+
155
+
nextSyntax = currentSyntax.parent
156
+
}
157
+
158
+
return matches
159
+
}
160
+
}
161
+
162
+
extensionFallThroughStmtSyntax{
163
+
/// Returns the source and destination of a `fallthrough`.
164
+
///
165
+
/// - Returns: `source` as the switch case that encapsulates the `fallthrough` keyword and `destination` as the switch case that the `fallthrough` directs to.
166
+
///
167
+
/// Example usage:
168
+
/// ```swift
169
+
/// switch value {
170
+
/// case 2:
171
+
/// doSomething()
172
+
/// fallthrough
173
+
/// case 1:
174
+
/// doSomethingElse()
175
+
/// default:
176
+
/// break
177
+
/// }
178
+
/// ```
179
+
/// When calling this function at the `fallthrough`, it returns `case 2` and `case 1` in this exact order. The `nil` results handle ill-formed code: there's no `source` if the `fallthrough` is outside of a case. There's no `destination` if there is no case or `default` after the source case.
0 commit comments