ikvmnet / ikvm

A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Other
1.23k stars 111 forks source link

Generic types are omitted #299

Closed VahidN closed 1 year ago

VahidN commented 1 year ago

I'm trying to convert the latest java-parser to a .NET assembly using the following settings:

  <ItemGroup>
    <PackageReference Include="IKVM" Version="8.4.5" />
  </ItemGroup>

  <ItemGroup>
    <IkvmReference Include="javaparser-core-3.25.1.jar" />
  </ItemGroup>

It compiles fine and produces the output .dll file, but it converts the following code:

   default Optional<Position> getBegin() {
        return getRange().map(r -> r.begin);
    }

To this:

    [MethodImpl(MethodImplOptions.NoInlining)]
    [SpecialName]
    [LineNumberTable(42)]
    static Optional <default>getBegin(NodeWithRange P_0)
    {
        Optional result = P_0.getRange().map(new __<>Anon1());
        _ = null;
        return result;
    }

When I decompile the output .dll using the ILSpy, as you can see, its signature is just Optional and not the original Optional<Position>. Because its generics type info is omitted, it can't be used efficiently. Is there any solution for it?

wasabii commented 1 year ago

Java doesn't consider generics at runtime. So the code we generate also doesn't.

GeorgeS2019 commented 1 year ago

@wasabii

We may need to re-visit this issue IF it is relevant to JavaParser in the JavaToCsharp project!

If we could coordinate, it is important!

wasabii commented 1 year ago

Revisit what exactly? IKVM is a JVM implementation, not a language parser.