Support Java 17 Sealed Classes
https://docs.oracle.com/en/java/javase/17/language/sealed-classes-and-interfaces.html#GUID-0C709461-CC33-419A-82BF-61461336E65F
Note that we can only partially translate these for sealed classes, and it requires C# 15 coming out in .NET 11 with its Closed Hierarchies feature. We should do the following:
- For sealed interfaces, we have no alternative in C# at all. Emit as a non-sealed interface with a warning.
- For sealed classes, we should have an option as to whether to translate them as C# 15
closed classes. If so, we add the closed modifier to the translated class. Otherwise, we emit a warning. This option should be enabled by default.
- In both cases, we should add a comment on a line before the type definition outlining what the
permits clause had in Java. Example below.
Example input:
public sealed class Shape
permits Circle, Square, Rectangle {
}
Example output (C# 15 closed translation enabled):
// Java: sealed, permits Circle, Square, Rectangle
public closed class Shape
{
}
Example output (C# 15 closed translation disabled):
// Java: sealed, permits Circle, Square, Rectangle
public class Shape
{
}
Note that we also need to support the Java 17 non-sealed counterpart keyword. This keyword opens back up the hierarchy. We should translate this without emitting an equivalent keyword, with a comment added, and with a warning. i.e.:
Example input:
public non-sealed class Square extends Shape {
public double side;
}
Example output:
// Java: non-sealed
public class Square : Shape
{
public double side;
}
Support Java 17 Sealed Classes
https://docs.oracle.com/en/java/javase/17/language/sealed-classes-and-interfaces.html#GUID-0C709461-CC33-419A-82BF-61461336E65F
Note that we can only partially translate these for sealed classes, and it requires C# 15 coming out in .NET 11 with its Closed Hierarchies feature. We should do the following:
closedclasses. If so, we add theclosedmodifier to the translated class. Otherwise, we emit a warning. This option should be enabled by default.permitsclause had in Java. Example below.Example input:
Example output (C# 15
closedtranslation enabled):Example output (C# 15
closedtranslation disabled):Note that we also need to support the Java 17
non-sealedcounterpart keyword. This keyword opens back up the hierarchy. We should translate this without emitting an equivalent keyword, with a comment added, and with a warning. i.e.:Example input:
Example output: