Skip to content

Commit 4548c60

Browse files
Support sealed types
1 parent 39a11c8 commit 4548c60

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

grammar.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ module.exports = grammar({
763763
optional(field('type_parameters', $.type_parameters)),
764764
optional(field('superclass', $.superclass)),
765765
optional(field('interfaces', $.super_interfaces)),
766+
optional(field('permits', $.permits)),
766767
field('body', $.class_body)
767768
),
768769

@@ -779,7 +780,9 @@ module.exports = grammar({
779780
'synchronized',
780781
'native',
781782
'transient',
782-
'volatile'
783+
'volatile',
784+
'sealed',
785+
'non-sealed',
783786
)),
784787

785788
type_parameters: $ => seq(
@@ -801,14 +804,19 @@ module.exports = grammar({
801804

802805
super_interfaces: $ => seq(
803806
'implements',
804-
$.interface_type_list
807+
$.type_list
805808
),
806809

807-
interface_type_list: $ => seq(
810+
type_list: $ => seq(
808811
$._type,
809812
repeat(seq(',', $._type))
810813
),
811814

815+
permits: $ => seq(
816+
'permits',
817+
$.type_list
818+
),
819+
812820
class_body: $ => seq(
813821
'{',
814822
repeat($._class_body_declaration),
@@ -937,12 +945,13 @@ module.exports = grammar({
937945
field('name', $.identifier),
938946
field('type_parameters', optional($.type_parameters)),
939947
optional($.extends_interfaces),
948+
optional(field('permits', $.permits)),
940949
field('body', $.interface_body)
941950
),
942951

943952
extends_interfaces: $ => seq(
944953
'extends',
945-
$.interface_type_list
954+
$.type_list
946955
),
947956

948957
interface_body: $ => seq(

queries/highlights.scm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"module"
113113
"native"
114114
"new"
115+
"non-sealed"
115116
"open"
116117
"opens"
117118
"package"
@@ -121,6 +122,7 @@
121122
"public"
122123
"requires"
123124
"return"
125+
"sealed"
124126
"static"
125127
"strictfp"
126128
"switch"

queries/tags.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
(interface_declaration
1212
name: (identifier) @name) @definition.interface
1313

14-
(interface_type_list
14+
(type_list
1515
(type_identifier) @name) @reference.implementation
1616

1717
(object_creation_expression

test/corpus/declarations.txt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public class Dog implements ISpeak {
324324
(program
325325
(class_declaration
326326
(modifiers) (identifier)
327-
(super_interfaces (interface_type_list (type_identifier))) (class_body)))
327+
(super_interfaces (type_list (type_identifier))) (class_body)))
328328

329329
============================
330330
class declaration with body
@@ -383,11 +383,11 @@ interface Bottom extends Left, Right {}
383383
(program
384384
(interface_declaration
385385
(identifier)
386-
(extends_interfaces (interface_type_list (type_identifier)))
386+
(extends_interfaces (type_list (type_identifier)))
387387
(interface_body))
388388
(interface_declaration
389389
(identifier)
390-
(extends_interfaces (interface_type_list (type_identifier) (type_identifier))) (interface_body)))
390+
(extends_interfaces (type_list (type_identifier) (type_identifier))) (interface_body)))
391391

392392
===========================================
393393
interface with annotation type declaration
@@ -668,3 +668,40 @@ class A$B {
668668
(method_invocation
669669
(identifier)
670670
(argument_list))))))))
671+
672+
================
673+
Sealed classes
674+
================
675+
676+
sealed interface A permits B, C {
677+
678+
}
679+
680+
final class B implements A {}
681+
non-sealed interface C extends A {}
682+
683+
---
684+
685+
(program
686+
(interface_declaration
687+
(modifiers)
688+
(identifier)
689+
(permits
690+
(type_list
691+
(type_identifier)
692+
(type_identifier)))
693+
(interface_body))
694+
(class_declaration
695+
(modifiers)
696+
(identifier)
697+
(super_interfaces
698+
(type_list
699+
(type_identifier)))
700+
(class_body))
701+
(interface_declaration
702+
(modifiers)
703+
(identifier)
704+
(extends_interfaces
705+
(type_list
706+
(type_identifier)))
707+
(interface_body)))

0 commit comments

Comments
 (0)