Support Java 17 sealed classes (#66) - #166
Merged
Merged
Conversation
Translates Java `sealed`, `permits`, and `non-sealed` as far as C# allows: - Sealed classes gain the C# 15 `closed` modifier, controlled by the new `UseClosedForSealedClasses` option (enabled by default). When disabled, the modifier is omitted and a warning is raised instead. - Sealed interfaces have no C# equivalent, so they are emitted as plain interfaces with a warning. - `non-sealed` classes are emitted without a modifier, with a warning. In all cases a `// Java: sealed, permits X, Y` comment is added above the type so the original hierarchy is not lost. The option is exposed on the CLI as `--no-closed-for-sealed-classes` and as a checkbox in the GUI settings window. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #66.
Translates Java
sealed,permits, andnon-sealedas far as C# allows.Behavior
sealed class(option on, default)public closed class Shapesealed class(option off)public class Shapesealed interfacepublic interface Servicenon-sealed classpublic class Square : ShapeIn every case a comment recording the original hierarchy is emitted above the type, so the
permitsclause is not lost:Sealed interfaces have no C# equivalent at all, so they always warn.
non-sealedre-opens a hierarchy that C# never closed in the first place, so it emits no modifier and warns.Option
New
JavaConversionOptions.UseClosedForSealedClasses, enabled by default, controls whether sealed classes get the C# 15closedmodifier (which requires .NET 11). It is exposed as--no-closed-for-sealed-classeson the CLI and as a checkbox in the GUI settings window.Notes for review
ClosedKeywordtoken yet, soclosedis emitted viaSyntaxFactory.ParseToken. Verified it survivesNormalizeWhitespace().Java17SealedClasses.javafixture is registered underGeneralSuccessfulConversionTestrather thanFullIntegrationTests, because the latter compiles the output with Roslyn andclosedwill not parse until the toolchain supports C# 15. Worth moving once it does.// Java:comment to permitted records inRecordDeclarationVisitorwould be a follow-up.Testing
New
ConvertSealedTests.cscovers all four cases above plus the no-permitsand non-sealed-type paths. Full suite passes (318 tests); solution builds clean.🤖 Generated with Claude Code