Skip to content

Commit

Permalink
enh(java) add sealed and non-sealed keywords (#3386)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleymackey committed Nov 3, 2021
1 parent c100a39 commit 99e05df
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -4,6 +4,7 @@ Grammars:

- fix(python) Fix recognition of numeric literals followed by keywords without whitespace (#2985) [Richard Gibson][]
- enh(swift) add SE-0290 unavailability condition (#3382) [Bradley Mackey][]
- enh(java) add `sealed` and `non-sealed` keywords (#3386) [Bradley Mackey][]

[Richard Gibson]: https://github.com/gibson042
[Bradley Mackey]: https://github.com/bradleymackey
Expand Down
8 changes: 7 additions & 1 deletion src/languages/java.js
Expand Up @@ -73,7 +73,8 @@ export default function(hljs) {
'module',
'requires',
'exports',
'do'
'do',
'sealed'
];

const BUILT_INS = [
Expand Down Expand Up @@ -179,6 +180,11 @@ export default function(hljs) {
3: "title.class"
}
},
{
// Exceptions for hyphenated keywords
match: /non-sealed/,
scope: "keyword"
},
{
begin: [
JAVA_IDENT_RE,
Expand Down
8 changes: 8 additions & 0 deletions test/markup/java/titles.expect.txt
Expand Up @@ -8,3 +8,11 @@
}
}
}

<span class="hljs-keyword">sealed</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">Command</span> permits LoginCommand {
<span class="hljs-keyword">void</span> <span class="hljs-title function_">run</span><span class="hljs-params">()</span>;
}

<span class="hljs-keyword">non-sealed</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserPluginCommand</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Command</span> {
<span class="hljs-keyword">void</span> <span class="hljs-title function_">runAsUser</span><span class="hljs-params">()</span>;
}
8 changes: 8 additions & 0 deletions test/markup/java/titles.txt
Expand Up @@ -8,3 +8,11 @@ public class Greet {
}
}
}

sealed interface Command permits LoginCommand {
void run();
}

non-sealed abstract class UserPluginCommand extends Command {
void runAsUser();
}

0 comments on commit 99e05df

Please sign in to comment.