diff --git a/data/fixtures/scopes/java/condition/condition.switchCase2.scope b/data/fixtures/scopes/java/condition/condition.switchCase2.scope new file mode 100644 index 0000000000..345428df7b --- /dev/null +++ b/data/fixtures/scopes/java/condition/condition.switchCase2.scope @@ -0,0 +1,78 @@ +switch (value) { + case 1, 2: + break; + case 3, 4: + break; + default: + break; +} +--- + +[#1.1 Content] = 1:9-1:10 + >-< +1| case 1, 2: + +[#1.1 Removal] = 1:8-1:10 + >--< +1| case 1, 2: + +[#1.1 Leading delimiter] = 1:8-1:9 + >-< +1| case 1, 2: + +[#1.1 Insertion delimiter] = " " + +[#1.2 Content] = 1:12-1:13 + >-< +1| case 1, 2: + +[#1.2 Removal] = 1:11-1:13 + >--< +1| case 1, 2: + +[#1.2 Leading delimiter] = 1:11-1:12 + >-< +1| case 1, 2: + +[#1.2 Insertion delimiter] = " " + +[#1 Domain] = 1:4-2:14 + >---------- +1| case 1, 2: +2| break; + --------------< + + +[#2.1 Content] = 3:9-3:10 + >-< +3| case 3, 4: + +[#2.1 Removal] = 3:8-3:10 + >--< +3| case 3, 4: + +[#2.1 Leading delimiter] = 3:8-3:9 + >-< +3| case 3, 4: + +[#2.1 Insertion delimiter] = " " + +[#2.2 Content] = 3:12-3:13 + >-< +3| case 3, 4: + +[#2.2 Removal] = 3:11-3:13 + >--< +3| case 3, 4: + +[#2.2 Leading delimiter] = 3:11-3:12 + >-< +3| case 3, 4: + +[#2.2 Insertion delimiter] = " " + +[#2 Domain] = 3:4-4:14 + >---------- +3| case 3, 4: +4| break; + --------------< diff --git a/data/fixtures/scopes/java/interior/interior.switchCase2.scope b/data/fixtures/scopes/java/interior/interior.switchCase2.scope new file mode 100644 index 0000000000..d08b2d7795 --- /dev/null +++ b/data/fixtures/scopes/java/interior/interior.switchCase2.scope @@ -0,0 +1,153 @@ +switch (value) { + case 0 -> foo; + case 1 -> bar; + default -> { + yield baz; + } +} +--- + +[#1 Content] = 1:4-5:5 + >-------------- +1| case 0 -> foo; +2| case 1 -> bar; +3| default -> { +4| yield baz; +5| } + -----< + +[#1 Removal] = 0:16-6:0 + > +0| switch (value) { +1| case 0 -> foo; +2| case 1 -> bar; +3| default -> { +4| yield baz; +5| } +6| } + < + +[#1 Domain] = 0:0-6:1 + >---------------- +0| switch (value) { +1| case 0 -> foo; +2| case 1 -> bar; +3| default -> { +4| yield baz; +5| } +6| } + -< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:8-0:13 + >-----< +0| switch (value) { + +[#2 Domain] = 0:7-0:14 + >-------< +0| switch (value) { + +[#2 Insertion delimiter] = " " + + +[#3 Content] = 1:4-5:5 + >-------------- +1| case 0 -> foo; +2| case 1 -> bar; +3| default -> { +4| yield baz; +5| } + -----< + +[#3 Removal] = 0:16-6:0 + > +0| switch (value) { +1| case 0 -> foo; +2| case 1 -> bar; +3| default -> { +4| yield baz; +5| } +6| } + < + +[#3 Domain] = 0:15-6:1 + >- +0| switch (value) { +1| case 0 -> foo; +2| case 1 -> bar; +3| default -> { +4| yield baz; +5| } +6| } + -< + +[#3 Insertion delimiter] = " " + + +[#4 Content] = +[#4 Removal] = 1:14-1:18 + >----< +1| case 0 -> foo; + +[#4 Domain] = 1:4-1:18 + >--------------< +1| case 0 -> foo; + +[#4 Insertion delimiter] = " " + + +[#5 Content] = +[#5 Removal] = 2:14-2:18 + >----< +2| case 1 -> bar; + +[#5 Domain] = 2:4-2:18 + >--------------< +2| case 1 -> bar; + +[#5 Insertion delimiter] = " " + + +[#6 Content] = 4:8-4:18 + >----------< +4| yield baz; + +[#6 Removal] = 3:16-5:4 + > +3| default -> { +4| yield baz; +5| } + ----< + +[#6 Domain] = 3:4-5:5 + >------------ +3| default -> { +4| yield baz; +5| } + -----< + +[#6 Insertion delimiter] = " " + + +[#7 Content] = 4:8-4:18 + >----------< +4| yield baz; + +[#7 Removal] = 3:16-5:4 + > +3| default -> { +4| yield baz; +5| } + ----< + +[#7 Domain] = 3:15-5:5 + >- +3| default -> { +4| yield baz; +5| } + -----< + +[#7 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/java/value/value.yield.scope b/data/fixtures/scopes/java/value/value.yield.scope new file mode 100644 index 0000000000..3452293027 --- /dev/null +++ b/data/fixtures/scopes/java/value/value.yield.scope @@ -0,0 +1,44 @@ +switch (value) { + case 1: + yield "foo"; + default: + yield "bar"; +} +--- + +[#1 Content] = 2:14-2:19 + >-----< +2| yield "foo"; + +[#1 Removal] = 2:13-2:19 + >------< +2| yield "foo"; + +[#1 Leading delimiter] = 2:13-2:14 + >-< +2| yield "foo"; + +[#1 Domain] = 2:8-2:20 + >------------< +2| yield "foo"; + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 4:14-4:19 + >-----< +4| yield "bar"; + +[#2 Removal] = 4:13-4:19 + >------< +4| yield "bar"; + +[#2 Leading delimiter] = 4:13-4:14 + >-< +4| yield "bar"; + +[#2 Domain] = 4:8-4:20 + >------------< +4| yield "bar"; + +[#2 Insertion delimiter] = " " diff --git a/packages/common/src/scopeSupportFacets/java.ts b/packages/common/src/scopeSupportFacets/java.ts index 2847dc5b71..e51ff82871 100644 --- a/packages/common/src/scopeSupportFacets/java.ts +++ b/packages/common/src/scopeSupportFacets/java.ts @@ -141,6 +141,7 @@ export const javaScopeSupport: LanguageScopeSupportFacetMap = { "value.foreach": supported, "value.field.class": supported, "value.return": supported, + "value.yield": supported, "value.return.lambda": supported, "value.variable": supported, "value.resource": supported, @@ -289,7 +290,6 @@ export const javaScopeSupport: LanguageScopeSupportFacetMap = { "value.iteration.enum": notApplicable, // Miscellaneous - "value.yield": notApplicable, pairDelimiter: notApplicable, regularExpression: notApplicable, environment: notApplicable, diff --git a/queries/java.scm b/queries/java.scm index 8af0505a18..c49fa1865c 100644 --- a/queries/java.scm +++ b/queries/java.scm @@ -199,6 +199,7 @@ (switch_label (_) @condition ) + (#allow-multiple! @condition) ) @condition.domain ;;!! case "0" -> "zero"; @@ -524,10 +525,18 @@ ;;! ^^^^^ ;;! ------------- ( - (return_statement) @value @_.domain - (#child-range! @value 1 -2) + (return_statement + (_) @value + ) @_.domain ) +;;!! yield value; +;;! ^^^^^ +;;! ------------ +(yield_statement + (_) @value +) @_.domain + ;;!! str -> str.length > 0 ;;! ^^^^^^^^^^^^^^ ;;! ---------------------