Skip to content

C#: Improve type attribution coverage on identifiers and declarations#6994

Merged
jkschneider merged 1 commit intomainfrom
csharp-type-attribution
Mar 16, 2026
Merged

C#: Improve type attribution coverage on identifiers and declarations#6994
jkschneider merged 1 commit intomainfrom
csharp-type-attribution

Conversation

@jkschneider
Copy link
Member

Summary

  • Adds JavaType attribution to ~30 identifier creation sites in the C# parser that were previously null, null
  • Covers declaration names (class, method, constructor, property, event, enum, delegate), expression identifiers (VisitIdentifierName fieldType, FieldAccess name, MethodInvocation name), variable declaration names (fields, locals, parameters, for/foreach, catch, pattern match, lambda params), and type references (non-primitive predefined types, generic raw type identifiers)
  • Adds FieldType(), TypeAndFieldType(), and RawType() methods to CSharpTypeMapping for reference resolution, combined Roslyn API calls, and unparameterized generic type lookup
  • Caches JavaType.Variable instances by ISymbol in MapVariable for referential deduplication across declaration and reference sites
  • Adds comprehensive test verifying class name type, method name type, property fieldType, field variable fieldType, and round-trip correctness

Test plan

  • Existing parseWithTypeAttribution test passes
  • New comprehensiveTypeAttribution test passes — verifies class/method/property/field type attribution
  • All 50+ existing CSharpRpcTest round-trip tests pass (no regressions)
  • All CSharpRecipeTest recipe tests pass
  • C# solution builds with zero warnings

The C# parser was missing JavaType information on most identifier nodes.
This adds type and fieldType attribution across ~30 identifier creation
sites covering declarations, expressions, type references, and variable
names. Also adds referential deduplication for JavaType.Variable via
ISymbol-keyed caching, and a combined TypeAndFieldType() method to avoid
redundant Roslyn API calls on expression identifiers.
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Mar 16, 2026
@jkschneider jkschneider merged commit 295df98 into main Mar 16, 2026
1 check failed
@jkschneider jkschneider deleted the csharp-type-attribution branch March 16, 2026 21:47
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Mar 16, 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