Skip to content

C#: preserve whitespace in nullable directives and widen IsPattern#7787

Merged
macsux merged 1 commit into
mainfrom
macsux/csharp-parse-fixes
May 26, 2026
Merged

C#: preserve whitespace in nullable directives and widen IsPattern#7787
macsux merged 1 commit into
mainfrom
macsux/csharp-parse-fixes

Conversation

@macsux
Copy link
Copy Markdown
Contributor

@macsux macsux commented May 26, 2026

Summary

  • Preserve the original whitespace between #nullable and the setting keyword (e.g. #nullable enable) via a new keywordSpacing field on Cs.NullableDirective, threaded through the parser, printer, and RPC sender/receiver on both the Java and C# sides.
  • Widen Cs.IsPattern.Pattern from Pattern to Expression so parenthesized patterns (J.Parentheses<Expression>) and wrapped declaration patterns fit too; parser now uses VisitPatternAsExpression.

Test plan

  • ./gradlew :rewrite-csharp:test
  • dotnet test against rewrite-csharp/csharp

Preserves the original whitespace between `#nullable` and the setting keyword
(e.g. `#nullable  enable`) via a new `keywordSpacing` field on `NullableDirective`.
Widens `Cs.IsPattern.Pattern` from `Pattern` to `Expression` so parenthesized
patterns (`J.Parentheses<Expression>`) and wrapped declaration patterns fit too.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 26, 2026
@macsux macsux merged commit a250c03 into main May 26, 2026
1 check passed
@macsux macsux deleted the macsux/csharp-parse-fixes branch May 26, 2026 19:57
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant