Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Add support for non-sealed keyword #236

@fbricon

Description

@fbricon

Following up on #232, Java 15's non-sealed keyword should also be highlighted:

Screen Shot 2020-09-28 at 3 52 48 PM

It's part of JEP 360:

A sealed class imposes three constraints on its permitted subclasses (the classes specified by its permits clause):

The sealed class and its permitted subclasses must belong to the same module, and, if declared in an unnamed module, the same package.

Every permitted subclass must directly extend the sealed class.

Every permitted subclass must choose a modifier to describe how it continues the sealing initiated by its superclass:

A permitted subclass may be declared final to prevent its part of the class hierarchy from being extended further.
A permitted subclass may be declared sealed to allow its part of the hierarchy to be extended further than envisaged by its sealed superclass, but in a restricted fashion.
A permitted subclass may be declared non-sealed so that its part of the hierarchy reverts to being open for extension by unknown subclasses. (A sealed class cannot prevent its permitted subclasses from doing this.)
As an example of the third constraint, Circle may be final while Rectangle is sealed and Square is non-sealed:

package com.example.geometry;

public abstract sealed class Shape
permits Circle, Rectangle, Square {...}

public final class Circle extends Shape {...}

public sealed class Rectangle extends Shape
permits TransparentRectangle, FilledRectangle {...}
public final class TransparentRectangle extends Rectangle {...}
public final class FilledRectangle extends Rectangle {...}

public non-sealed class Square extends Shape {...}
One and only one of the modifiers final, sealed, and non-sealed must be used by each permitted subclass. It is not possible for a class to be both sealed (implying subclasses) and final (implying no subclasses), or both non-sealed (implying subclasses) and final (implying no subclasses), or both sealed (implying restricted subclasses) and non-sealed (implying unrestricted subclasses).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions