Skip to content

C#: Populate Methods and Members on JavaType.Class#7072

Draft
knutwannheden wants to merge 2 commits intomainfrom
investigate-incomplete-methods-list-on-javatype.class-from-c-parser
Draft

C#: Populate Methods and Members on JavaType.Class#7072
knutwannheden wants to merge 2 commits intomainfrom
investigate-incomplete-methods-list-on-javatype.class-from-c-parser

Conversation

@knutwannheden
Copy link
Copy Markdown
Contributor

Summary

  • CSharpTypeMapping.MapNamedType() was passing null for both Methods and Members when constructing JavaType.Class, causing TypeUtils.HasMethod() to always return false for every type
  • Now populates Methods (ordinary methods + constructors) and Members (non-implicit fields) from Roslyn's INamedTypeSymbol.GetMembers()
  • The existing shell cache pattern protects against infinite recursion from cyclic type references

Context

This broke recipe logic in recipes-csharp that uses TypeUtils.HasMethod(type, "ThrowIfNull") to check whether System.ArgumentNullException supports ThrowIfNull (a .NET 6+ API). Because Methods was always null, the guard always returned false, causing 5 test failures.

Test plan

  • New CSharpTypeMappingTests.ClassTypeShouldHaveMethods — verifies ThrowIfNull is found on ArgumentNullException
  • New CSharpTypeMappingTests.ClassTypeShouldHaveMethodsOnException — verifies GetBaseException is found on Exception
  • New CSharpTypeMappingTests.UserDefinedClassShouldHaveMembers — verifies user-defined fields appear in Members
  • All 1532 existing C# tests pass

CSharpTypeMapping.MapNamedType() was setting Methods and Members to null
on every JavaType.Class, causing TypeUtils.HasMethod() to always return
false. This broke recipe logic that checks method availability on types
(e.g., checking if ArgumentNullException.ThrowIfNull exists for TFM
compatibility).

Now populates Methods (ordinary methods + constructors) and Members
(non-implicit fields) by iterating symbol.GetMembers(). The existing
shell cache pattern protects against infinite recursion from cyclic
type references.
@knutwannheden knutwannheden changed the title C#: Populate Methods and Members on JavaType.Class C#: Populate Methods and Members on JavaType.Class Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant