From d95fffad2a586823969d3950f777e86fea3e69cb Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sun, 19 May 2024 12:37:26 +0200 Subject: [PATCH] Added try branch for java --- .../scopes/java/branch.if.iteration.scope | 12 +++++++ data/fixtures/scopes/java/branch.if.scope | 35 +++++++++++++++++++ .../scopes/java/branch.try.iteration.scope | 12 +++++++ data/fixtures/scopes/java/branch.try.scope | 30 ++++++++++++++++ .../common/src/scopeSupportFacets/java.ts | 5 +++ .../scopeSupportFacetInfos.ts | 6 ++++ .../scopeSupportFacets.types.ts | 1 + queries/java.scm | 22 ++++++++++++ 8 files changed, 123 insertions(+) create mode 100644 data/fixtures/scopes/java/branch.if.iteration.scope create mode 100644 data/fixtures/scopes/java/branch.if.scope create mode 100644 data/fixtures/scopes/java/branch.try.iteration.scope create mode 100644 data/fixtures/scopes/java/branch.try.scope diff --git a/data/fixtures/scopes/java/branch.if.iteration.scope b/data/fixtures/scopes/java/branch.if.iteration.scope new file mode 100644 index 0000000000..86acdd382f --- /dev/null +++ b/data/fixtures/scopes/java/branch.if.iteration.scope @@ -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 {} + -------< diff --git a/data/fixtures/scopes/java/branch.if.scope b/data/fixtures/scopes/java/branch.if.scope new file mode 100644 index 0000000000..64c8edf762 --- /dev/null +++ b/data/fixtures/scopes/java/branch.if.scope @@ -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" diff --git a/data/fixtures/scopes/java/branch.try.iteration.scope b/data/fixtures/scopes/java/branch.try.iteration.scope new file mode 100644 index 0000000000..756d78c510 --- /dev/null +++ b/data/fixtures/scopes/java/branch.try.iteration.scope @@ -0,0 +1,12 @@ +try {} +catch(Exception e) {} +finally {} +--- + +[Range] = +[Domain] = 0:0-2:10 + >------ +0| try {} +1| catch(Exception e) {} +2| finally {} + ----------< diff --git a/data/fixtures/scopes/java/branch.try.scope b/data/fixtures/scopes/java/branch.try.scope new file mode 100644 index 0000000000..19049b7bd1 --- /dev/null +++ b/data/fixtures/scopes/java/branch.try.scope @@ -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" diff --git a/packages/common/src/scopeSupportFacets/java.ts b/packages/common/src/scopeSupportFacets/java.ts index 1d4e56c7e8..d65727cc87 100644 --- a/packages/common/src/scopeSupportFacets/java.ts +++ b/packages/common/src/scopeSupportFacets/java.ts @@ -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, }; diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts index 0a2b2484af..dc17f75498 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -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", diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts index 7d4cc51c76..898b19dca9 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts @@ -46,6 +46,7 @@ const scopeSupportFacets = [ "branch.if", "branch.if.iteration", "branch.try", + "branch.try.iteration", "branch.switchCase", "branch.switchCase.iteration", "branch.ternary", diff --git a/queries/java.scm b/queries/java.scm index 3058270539..145b8cb2e8 100644 --- a/queries/java.scm +++ b/queries/java.scm @@ -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) {} ;;! ^^^^^ ;;! ------------------------------