Skip to content

Commit d0a2b2a

Browse files
Added try branch for java (#2346)
* Added branch scope for try catch statements in java * Added missing iteration scope for if else branch in java ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-ca/e-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet
1 parent b8a2f42 commit d0a2b2a

File tree

8 files changed

+123
-0
lines changed

8 files changed

+123
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
if (true) {}
2+
else if (false) {}
3+
else {}
4+
---
5+
6+
[Range] =
7+
[Domain] = 0:0-2:7
8+
>------------
9+
0| if (true) {}
10+
1| else if (false) {}
11+
2| else {}
12+
-------<
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
if (true) {}
2+
else if (false) {}
3+
else {}
4+
---
5+
6+
[#1 Content] =
7+
[#1 Domain] = 0:0-0:12
8+
>------------<
9+
0| if (true) {}
10+
11+
[#1 Removal] = 0:0-1:5
12+
>------------
13+
0| if (true) {}
14+
1| else if (false) {}
15+
-----<
16+
17+
[#1 Insertion delimiter] = "\n"
18+
19+
20+
[#2 Content] =
21+
[#2 Removal] =
22+
[#2 Domain] = 1:0-1:18
23+
>------------------<
24+
1| else if (false) {}
25+
26+
[#2 Insertion delimiter] = "\n"
27+
28+
29+
[#3 Content] =
30+
[#3 Removal] =
31+
[#3 Domain] = 2:0-2:7
32+
>-------<
33+
2| else {}
34+
35+
[#3 Insertion delimiter] = "\n"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
try {}
2+
catch(Exception e) {}
3+
finally {}
4+
---
5+
6+
[Range] =
7+
[Domain] = 0:0-2:10
8+
>------
9+
0| try {}
10+
1| catch(Exception e) {}
11+
2| finally {}
12+
----------<
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
try {}
2+
catch(Exception e) {}
3+
finally {}
4+
---
5+
6+
[#1 Content] =
7+
[#1 Removal] =
8+
[#1 Domain] = 0:0-0:6
9+
>------<
10+
0| try {}
11+
12+
[#1 Insertion delimiter] = "\n"
13+
14+
15+
[#2 Content] =
16+
[#2 Removal] =
17+
[#2 Domain] = 1:0-1:21
18+
>---------------------<
19+
1| catch(Exception e) {}
20+
21+
[#2 Insertion delimiter] = "\n"
22+
23+
24+
[#3 Content] =
25+
[#3 Removal] =
26+
[#3 Domain] = 2:0-2:10
27+
>----------<
28+
2| finally {}
29+
30+
[#3 Insertion delimiter] = "\n"

packages/common/src/scopeSupportFacets/java.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ export const javaScopeSupport: LanguageScopeSupportFacetMap = {
2828
attribute: notApplicable,
2929
"key.attribute": notApplicable,
3030
"value.attribute": notApplicable,
31+
32+
"branch.if": supported,
33+
"branch.if.iteration": supported,
34+
"branch.try": supported,
35+
"branch.try.iteration": supported,
3136
};

packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ export const scopeSupportFacetInfos: Record<
310310
description: "A try/catch/finally branch",
311311
scopeType: "branch",
312312
},
313+
"branch.try.iteration": {
314+
description:
315+
"Iteration scope for try/catch/finally branch; should be the entire try-catch statement",
316+
scopeType: "branch",
317+
isIteration: true,
318+
},
313319
"branch.switchCase": {
314320
description: "A case/default branch in a switch/match statement",
315321
scopeType: "branch",

packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const scopeSupportFacets = [
7979
"branch.if",
8080
"branch.if.iteration",
8181
"branch.try",
82+
"branch.try.iteration",
8283
"branch.switchCase",
8384
"branch.switchCase.iteration",
8485
"branch.ternary",

queries/java.scm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,28 @@
155155
alternative: (block) @branch.end
156156
)
157157

158+
(
159+
(if_statement) @branch.iteration
160+
(#not-parent-type? @branch.iteration "if_statement")
161+
)
162+
163+
;;!! try {}
164+
;;! ^^^^^^
165+
(try_statement
166+
"try" @branch.start
167+
body: (_) @branch.end
168+
)
169+
170+
;;!! catch (Exception e) {}
171+
;;! ^^^^^^^^^^^^^^^^^^^^^^
172+
(catch_clause) @branch
173+
174+
;;!! finally {}
175+
;;! ^^^^^^^^^^
176+
(finally_clause) @branch
177+
178+
(try_statement) @branch.iteration
179+
158180
;;!! for (int i = 0; i < 5; ++i) {}
159181
;;! ^^^^^
160182
;;! ------------------------------

0 commit comments

Comments
 (0)