xamarin / java.interop

Java.Interop provides open-source bindings of Java's Java Native Interface (JNI) for use with .NET managed languages such as C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Callback (`cb_`) name collision when binding methods with identical signatures and Java names

moljac opened this issue · comments

Context:

In bindings we generate cb_* (delegates, etc ) stuff based on native types.
Now in the case when 2 methods with the same name and the same parameters, but different return types exist, renaming managedName does not help because there are 2 sets of cb_* variables.

There are 2 potentional workarounds:

  • generating cb_* based on managed names and types

  • addding return type to cb_*

Curently user has to remove both methods.

      <method abstract="false" deprecated="not deprecated" final="false" name="setDetectorMode" jni-signature="(I)Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions$Builder;" bridge="false" native="false" return="com.google.mlkit.vision.objects.defaults.ObjectDetectorOptions.Builder" jni-return="Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions$Builder;" static="false" synchronized="false" synthetic="false" visibility="public" return-not-null="true">
        <parameter name="detectorMode" type="int" jni-type="I" />
      </method>
      <method abstract="false" deprecated="not deprecated" final="true" name="setDetectorMode" jni-signature="(I)Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase$Builder;" bridge="true" native="false" return="java.lang.Object" jni-return="Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase$Builder;" static="false" synchronized="false" synthetic="true" visibility="public" return-not-null="true">
        <parameter name="p0" type="int" jni-type="I" />
      </method>

Discord comments:

jpobst — Today at 8:40 PM

hmm, i guess generator doesn't even read in the bridge info, so it would treat them as regular methods: 

https://github.com/xamarin/java.interop/blob/main/tools/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs#L363

while adding the return type to the cb_ would fix this one, it probably wouldn't fix all the cases, we may need to use the managed name instead of the java name 

Jonathan Pryor — Today at 8:48 PM
except in this case the method signature would be identical, which would result in C# errors anyway

jpobst — Today at 8:48 PM
if the user has changed the managed name both could coexist

Jonathan Pryor — Today at 8:48 PM

fair
so the cb_* fields should really include managedName somehow

Class

    <class abstract="false" deprecated="not deprecated" extends="com.google.mlkit.vision.objects.ObjectDetectorOptionsBase.Builder" extends-generic-aware="com.google.mlkit.vision.objects.ObjectDetectorOptionsBase.Builder&lt;com.google.mlkit.vision.objects.defaults.ObjectDetectorOptions.Builder&gt;" jni-extends="Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase$Builder;" final="false" name="ObjectDetectorOptions.Builder" static="true" visibility="public" jni-signature="Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions$Builder;">
      <constructor deprecated="not deprecated" final="false" name="ObjectDetectorOptions.Builder" jni-signature="()V" bridge="false" static="false" type="com.google.mlkit.vision.objects.defaults.ObjectDetectorOptions.Builder" synthetic="false" visibility="public" />
      <method abstract="false" deprecated="not deprecated" final="false" name="build" jni-signature="()Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions;" bridge="false" native="false" return="com.google.mlkit.vision.objects.defaults.ObjectDetectorOptions" jni-return="Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions;" static="false" synchronized="false" synthetic="false" visibility="public" return-not-null="true" />
      <method abstract="false" deprecated="not deprecated" final="true" name="build" jni-signature="()Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase;" bridge="true" native="false" return="com.google.mlkit.vision.objects.ObjectDetectorOptionsBase" jni-return="Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase;" static="false" synchronized="false" synthetic="true" visibility="public" return-not-null="true" />
      <method abstract="false" deprecated="not deprecated" final="false" name="enableClassification" jni-signature="()Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions$Builder;" bridge="false" native="false" return="com.google.mlkit.vision.objects.defaults.ObjectDetectorOptions.Builder" jni-return="Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions$Builder;" static="false" synchronized="false" synthetic="false" visibility="public" return-not-null="true" />
      <method abstract="false" deprecated="not deprecated" final="true" name="enableClassification" jni-signature="()Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase$Builder;" bridge="true" native="false" return="java.lang.Object" jni-return="Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase$Builder;" static="false" synchronized="false" synthetic="true" visibility="public" return-not-null="true" />
      <method abstract="false" deprecated="not deprecated" final="false" name="enableMultipleObjects" jni-signature="()Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions$Builder;" bridge="false" native="false" return="com.google.mlkit.vision.objects.defaults.ObjectDetectorOptions.Builder" jni-return="Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions$Builder;" static="false" synchronized="false" synthetic="false" visibility="public" return-not-null="true" />
      <method abstract="false" deprecated="not deprecated" final="true" name="enableMultipleObjects" jni-signature="()Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase$Builder;" bridge="true" native="false" return="java.lang.Object" jni-return="Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase$Builder;" static="false" synchronized="false" synthetic="true" visibility="public" return-not-null="true" />
      <method abstract="false" deprecated="not deprecated" final="false" name="setDetectorMode" jni-signature="(I)Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions$Builder;" bridge="false" native="false" return="com.google.mlkit.vision.objects.defaults.ObjectDetectorOptions.Builder" jni-return="Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions$Builder;" static="false" synchronized="false" synthetic="false" visibility="public" return-not-null="true">
        <parameter name="detectorMode" type="int" jni-type="I" />
      </method>
      <method abstract="false" deprecated="not deprecated" final="true" name="setDetectorMode" jni-signature="(I)Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase$Builder;" bridge="true" native="false" return="java.lang.Object" jni-return="Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase$Builder;" static="false" synchronized="false" synthetic="true" visibility="public" return-not-null="true">
        <parameter name="p0" type="int" jni-type="I" />
      </method>
      <method abstract="false" deprecated="not deprecated" final="false" name="setExecutor" jni-signature="(Ljava/util/concurrent/Executor;)Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions$Builder;" bridge="false" native="false" return="com.google.mlkit.vision.objects.defaults.ObjectDetectorOptions.Builder" jni-return="Lcom/google/mlkit/vision/objects/defaults/ObjectDetectorOptions$Builder;" static="false" synchronized="false" synthetic="false" visibility="public" return-not-null="true">
        <parameter name="executor" type="java.util.concurrent.Executor" jni-type="Ljava/util/concurrent/Executor;" not-null="true" />
      </method>
      <method abstract="false" deprecated="not deprecated" final="true" name="setExecutor" jni-signature="(Ljava/util/concurrent/Executor;)Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase$Builder;" bridge="true" native="false" return="java.lang.Object" jni-return="Lcom/google/mlkit/vision/objects/ObjectDetectorOptionsBase$Builder;" static="false" synchronized="false" synthetic="true" visibility="public" return-not-null="true">
        <parameter name="p0" type="java.util.concurrent.Executor" jni-type="Ljava/util/concurrent/Executor;" not-null="true" />
      </method>
    </class>

api.xml.zip

api.xml.class-parse.zip