Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
moljac opened this issue Oct 26, 2023 · 1 comment
Labels
bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.)

Comments

@moljac
Copy link
Member

moljac commented Oct 26, 2023

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
@jpobst jpobst added bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.) labels Oct 26, 2023
@jpobst jpobst changed the title Binding 2 methods with the same signature (the same name and parameters), but different return types Callback (cb_) name collision when binding methods with identical signatures and Java names Oct 26, 2023
@moljac
Copy link
Member Author

moljac commented Oct 26, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.)
Projects
None yet
Development

No branches or pull requests

2 participants