Skip to content

Commit 971bbfd

Browse files
committed
[JEP-409] Add support for sealed classes in the Java parser
1 parent 55c2002 commit 971bbfd

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,9 @@ object JavaParsers {
483483
addAnnot(scalaDot(jtpnme.VOLATILEkw))
484484
case SYNCHRONIZED | STRICTFP =>
485485
in.nextToken()
486+
case SEALED =>
487+
flags |= Flags.Sealed
488+
in.nextToken()
486489
case _ =>
487490
val privateWithin: TypeName =
488491
if (isPackageAccess && !inInterface) thisPackageName
@@ -806,6 +809,14 @@ object JavaParsers {
806809
else
807810
List()
808811

812+
813+
def permitedSubclassesOpt() : List[Tree] =
814+
if in.token == PERMITS then
815+
in.nextToken()
816+
repsep(() => typ(), COMMA)
817+
else
818+
Nil
819+
809820
def classDecl(start: Offset, mods: Modifiers): List[Tree] = {
810821
accept(CLASS)
811822
val nameOffset = in.offset
@@ -819,6 +830,7 @@ object JavaParsers {
819830
else
820831
javaLangObject()
821832
val interfaces = interfacesOpt()
833+
val permitedSubclasses = permitedSubclassesOpt()
822834
val (statics, body) = typeBody(CLASS, name, tparams)
823835
val cls = atSpan(start, nameOffset) {
824836
TypeDef(name, makeTemplate(superclass :: interfaces, body, tparams, true)).withMods(mods)

compiler/src/dotty/tools/dotc/parsing/JavaTokens.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object JavaTokens extends TokensCommon {
1010

1111
final val javaOnlyKeywords: TokenSet = tokenRange(INSTANCEOF, ASSERT)
1212
final val sharedKeywords: BitSet = BitSet( IF, FOR, ELSE, THIS, NULL, NEW, SUPER, ABSTRACT, FINAL, PRIVATE, PROTECTED,
13-
EXTENDS, TRUE, FALSE, CLASS, IMPORT, PACKAGE, DO, THROW, TRY, CATCH, FINALLY, WHILE, RETURN )
13+
EXTENDS, TRUE, FALSE, CLASS, IMPORT, PACKAGE, DO, THROW, TRY, CATCH, FINALLY, WHILE, RETURN, SEALED)
1414
final val primTypes: TokenSet = tokenRange(VOID, DOUBLE)
1515
final val keywords: BitSet = sharedKeywords | javaOnlyKeywords | primTypes
1616

@@ -22,6 +22,7 @@ object JavaTokens extends TokensCommon {
2222
inline val INTERFACE = 105; enter(INTERFACE, "interface")
2323
inline val ENUM = 106; enter(ENUM, "enum")
2424
inline val IMPLEMENTS = 107; enter(IMPLEMENTS, "implements")
25+
inline val PERMITS = 108; enter(PERMITS, "permits")
2526

2627
/** modifiers */
2728
inline val PUBLIC = 110; enter(PUBLIC, "public")

compiler/src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ abstract class TokensCommon {
7878
//inline val YIELD = 48; enter(YIELD, "yield")
7979
inline val DO = 49; enter(DO, "do")
8080
//inline val TRAIT = 50; enter(TRAIT, "trait")
81-
//inline val SEALED = 51; enter(SEALED, "sealed")
81+
inline val SEALED = 51; enter(SEALED, "sealed")
8282
inline val THROW = 52; enter(THROW, "throw")
8383
inline val TRY = 53; enter(TRY, "try")
8484
inline val CATCH = 54; enter(CATCH, "catch")
@@ -169,7 +169,7 @@ object Tokens extends TokensCommon {
169169
inline val OBJECT = 44; enter(OBJECT, "object")
170170
inline val YIELD = 48; enter(YIELD, "yield")
171171
inline val TRAIT = 50; enter(TRAIT, "trait")
172-
inline val SEALED = 51; enter(SEALED, "sealed")
172+
//inline val SEALED = 51; enter(SEALED, "sealed")
173173
inline val MATCH = 58; enter(MATCH, "match")
174174
inline val LAZY = 59; enter(LAZY, "lazy")
175175
inline val THEN = 60; enter(THEN, "then")

0 commit comments

Comments
 (0)