Skip to content

Fix nested type inheritance conversion - #171

Open
Munishwar001 wants to merge 1 commit into
paulirwin:masterfrom
Munishwar001:fix/137-nested-type-inheritance-conversion
Open

Fix nested type inheritance conversion#171
Munishwar001 wants to merge 1 commit into
paulirwin:masterfrom
Munishwar001:fix/137-nested-type-inheritance-conversion

Conversation

@Munishwar001

Copy link
Copy Markdown

Summary

  • Fixes Nested types in inheritance are not converted properly #137 — when a Java class extends/implements a nested type (e.g.
    GeneratorFactory.AbstractXmlFeatureGeneratorFactory), the declaring
    type qualifier was silently dropped, producing invalid/incorrect C#
    (AbstractXmlFeatureGeneratorFactory instead of
    GeneratorFactory.AbstractXmlFeatureGeneratorFactory).
  • Root cause: TypeHelper.GetSyntaxFromType only read
    ClassOrInterfaceType.getNameAsString(), which returns just the
    simple name. JavaParser exposes the declaring type separately via
    getScope(), which was never consulted.
  • Fix: after resolving the leaf type syntax, check getScope() and,
    if present, recursively resolve it and wrap the result in a
    QualifiedName, preserving Outer.Inner qualification (valid in
    both Java and C#).

Test plan

  • Added ConvertNestedTypeInheritanceTests reproducing the exact
    scenario from Nested types in inheritance are not converted properly #137 (class extending/implementing nested types keeps
    the GeneratorFactory. qualifier).
  • Added a sanity test confirming plain (non-nested) extends is
    unaffected.
  • Full test suite passes: dotnet test — 337/337 passed.

Copilot AI lite review requested due to automatic review settings August 17, 2026 12:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes conversion of Java inheritance clauses when the base type is a nested type (e.g., Outer.Inner), ensuring the declaring type qualifier is preserved in the generated C#.

Changes:

  • Update TypeHelper.GetSyntaxFromType(ClassOrInterfaceType) to consult ClassOrInterfaceType.getScope() and emit a QualifiedName (Outer.Inner) when a scope is present.
  • Add ConvertNestedTypeInheritanceTests to cover nested-type extends/implements and a non-nested inheritance sanity check.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
JavaToCSharp/TypeHelper.cs Preserves nested type qualification by incorporating JavaParser scope into the emitted C# type syntax.
JavaToCSharp.Tests/ConvertNestedTypeInheritanceTests.cs Adds regression tests validating nested-type inheritance qualification is retained and simple inheritance remains unchanged.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested types in inheritance are not converted properly

2 participants