Skip to content

Commit

Permalink
(java) add Java 14 switch expression keyword yield (#3650)
Browse files Browse the repository at this point in the history
  • Loading branch information
MBoegers authored Oct 30, 2022
1 parent f035aab commit bc88ed5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Grammars:
- fix(bash) recognize the `((` keyword [Nick Chambers][]
- fix(nix) support escaped dollar signs in strings [h7x4][]
- enh(cmake) support bracket comments [Hirse][]
- enh(java) add yield keyword to java [MBoegers][]
- enh(java) add permits keyword to java [MBoegers][]

[Josh Goebel]: https://github.com/joshgoebel
Expand Down
1 change: 1 addition & 0 deletions src/languages/java.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default function(hljs) {
'exports',
'do',
'sealed',
'yield',
'permits'
];

Expand Down
13 changes: 13 additions & 0 deletions test/markup/java/switch.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<span class="hljs-keyword">switch</span>(a) {
<span class="hljs-keyword">case</span> <span class="hljs-literal">null</span> -&gt; <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;n&quot;</span>;
<span class="hljs-keyword">case</span> String s -&gt; <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;s&quot;</span>;
<span class="hljs-keyword">case</span> Object o -&gt; <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;o&quot;</span>;
<span class="hljs-keyword">default</span>: <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;d&quot;</span>,
}

<span class="hljs-keyword">switch</span>(a) {
<span class="hljs-keyword">case</span> <span class="hljs-literal">null</span>: <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;n&quot;</span>;
<span class="hljs-keyword">case</span> <span class="hljs-string">&quot;s&quot;</span>: <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;s&quot;</span>;
<span class="hljs-keyword">case</span> <span class="hljs-string">&quot;o&quot;</span>: <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;o&quot;</span>;
<span class="hljs-keyword">default</span>: <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;d&quot;</span>;
}
13 changes: 13 additions & 0 deletions test/markup/java/switch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
switch(a) {
case null -> yield "n";
case String s -> yield "s";
case Object o -> yield "o";
default: yield "d",
}

switch(a) {
case null: return "n";
case "s": return "s";
case "o": return "o";
default: return "d";
}

0 comments on commit bc88ed5

Please sign in to comment.