-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Labels
generatorIssues binding a Java library (generator, class-parse, etc.)Issues binding a Java library (generator, class-parse, etc.)
Description
Imagine you have bound a method that has a non-blittable (bool
/char
) parameter. With 57f7bc8, generator
will now cast the parameters as sbyte
/ushort
:
// Metadata.xml XPath method reference: path="/api/package[@name='androidx.work.impl.constraints.controllers']/class[@name='BatteryChargingController']/method[@name='isConstrained' and count(parameter)=1 and parameter[1][@type='boolean']]"
[Register ("isConstrained", "(Z)Z", "")]
protected override unsafe bool IsConstrained (bool value)
{
const string __id = "isConstrained.(Z)Z";
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (value ? (sbyte) 1 : (sbyte) 0);
var __rm = _members.InstanceMethods.InvokeAbstractBooleanMethod (__id, this, __args);
return __rm;
} finally {
global::System.GC.KeepAlive (value);
}
}
However, if you have used managedType
metadata to change the parameter type, for example to Java.Lang.Object
, the cast will still be added but will not compile:
<attr
path="/api/package[@name='androidx.work.impl.constraints.controllers']/class[@name='BatteryChargingController']/method[@name='isConstrained' and count(parameter)=1]/parameter[1]"
name="managedType">
Java.Lang.Object
</attr>
// Metadata.xml XPath method reference: path="/api/package[@name='androidx.work.impl.constraints.controllers']/class[@name='BatteryChargingController']/method[@name='isConstrained' and count(parameter)=1 and parameter[1][@type='boolean']]"
[Register ("isConstrained", "(Z)Z", "")]
protected override unsafe bool IsConstrained (global::Java.Lang.Object? value)
{
const string __id = "isConstrained.(Z)Z";
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (value ? (sbyte) 1 : (sbyte) 0); // Generated
var __rm = _members.InstanceMethods.InvokeAbstractBooleanMethod (__id, this, __args);
return __rm;
} finally {
global::System.GC.KeepAlive (value);
}
}
error CS0266: Cannot implicitly convert type 'Java.Lang.Object' to 'bool'. An explicit conversion exists (are you missing a cast?)
Fixing this requires removing the method with <remove-node>
and hand-binding the method with the needed cast.
__args [0] = new JniArgumentValue ((bool)value ? (sbyte) 1 : (sbyte) 0);
Metadata
Metadata
Assignees
Labels
generatorIssues binding a Java library (generator, class-parse, etc.)Issues binding a Java library (generator, class-parse, etc.)