Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added try branch for java #2346

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions data/fixtures/scopes/java/branch.if.iteration.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if (true) {}
else if (false) {}
else {}
---

[Range] =
[Domain] = 0:0-2:7
>------------
0| if (true) {}
1| else if (false) {}
2| else {}
-------<
35 changes: 35 additions & 0 deletions data/fixtures/scopes/java/branch.if.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if (true) {}
else if (false) {}
else {}
---

[#1 Content] =
[#1 Domain] = 0:0-0:12
>------------<
0| if (true) {}

[#1 Removal] = 0:0-1:5
>------------
0| if (true) {}
1| else if (false) {}
-----<

[#1 Insertion delimiter] = "\n"


[#2 Content] =
[#2 Removal] =
[#2 Domain] = 1:0-1:18
>------------------<
1| else if (false) {}

[#2 Insertion delimiter] = "\n"


[#3 Content] =
[#3 Removal] =
[#3 Domain] = 2:0-2:7
>-------<
2| else {}

[#3 Insertion delimiter] = "\n"
12 changes: 12 additions & 0 deletions data/fixtures/scopes/java/branch.try.iteration.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
try {}
catch(Exception e) {}
finally {}
---

[Range] =
[Domain] = 0:0-2:10
>------
0| try {}
1| catch(Exception e) {}
2| finally {}
----------<
30 changes: 30 additions & 0 deletions data/fixtures/scopes/java/branch.try.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
try {}
catch(Exception e) {}
finally {}
---

[#1 Content] =
[#1 Removal] =
[#1 Domain] = 0:0-0:6
>------<
0| try {}

[#1 Insertion delimiter] = "\n"


[#2 Content] =
[#2 Removal] =
[#2 Domain] = 1:0-1:21
>---------------------<
1| catch(Exception e) {}

[#2 Insertion delimiter] = "\n"


[#3 Content] =
[#3 Removal] =
[#3 Domain] = 2:0-2:10
>----------<
2| finally {}

[#3 Insertion delimiter] = "\n"
5 changes: 5 additions & 0 deletions packages/common/src/scopeSupportFacets/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ export const javaScopeSupport: LanguageScopeSupportFacetMap = {
attribute: notApplicable,
"key.attribute": notApplicable,
"value.attribute": notApplicable,

"branch.if": supported,
"branch.if.iteration": supported,
"branch.try": supported,
"branch.try.iteration": supported,
};
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ export const scopeSupportFacetInfos: Record<
description: "A try/catch/finally branch",
scopeType: "branch",
},
"branch.try.iteration": {
description:
"Iteration scope for try/catch/finally branch; should be the entire try-catch statement",
scopeType: "branch",
isIteration: true,
},
"branch.switchCase": {
description: "A case/default branch in a switch/match statement",
scopeType: "branch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const scopeSupportFacets = [
"branch.if",
"branch.if.iteration",
"branch.try",
"branch.try.iteration",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally left this one out because I couldn't see how it would be useful. But I'm not opposed

"branch.switchCase",
"branch.switchCase.iteration",
"branch.ternary",
Expand Down
22 changes: 22 additions & 0 deletions queries/java.scm
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,28 @@
alternative: (block) @branch.end
)

(
(if_statement) @branch.iteration
(#not-parent-type? @branch.iteration "if_statement")
)

;;!! try {}
;;! ^^^^^^
(try_statement
"try" @branch.start
body: (_) @branch.end
)

;;!! catch (Exception e) {}
;;! ^^^^^^^^^^^^^^^^^^^^^^
(catch_clause) @branch

;;!! finally {}
;;! ^^^^^^^^^^
(finally_clause) @branch

(try_statement) @branch.iteration

;;!! for (int i = 0; i < 5; ++i) {}
;;! ^^^^^
;;! ------------------------------
Expand Down
Loading