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

enh(java) add sealed and non-sealed keywords #3386

Merged
merged 5 commits into from Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
12 changes: 11 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,15 @@ export default function(hljs) {
3: "title.class"
}
},
{
// Exceptions for hyphenated keywords
match: [
/non-sealed/
],
className: {
1: "keyword"
}
},
bradleymackey marked this conversation as resolved.
Show resolved Hide resolved
{
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();
}