Skip to content

Commit 87fdb8e

Browse files
authored
[generator-Tests] bind java.util.List (#1273)
Context: 0aec86a Commit 0aec86a mentioned: > Remaining Integration-Tests which don't support JavaInterop1: > > * Missing builtin mapping between collection types: > > warning BG8800: Unknown parameter type 'java.util.List<java.lang.Integer>' for member … > warning BG8800: Unknown parameter type 'java.util.ArrayList<java.lang.Integer>' for member > warning BG8400: Unexpected field type `java.util.List<java.lang.String>` > > Impacts: Java_Util_List.cs, NormalMethods.cs, ParameterXPath.cs The problem here is that the provided API XML did not contain a declaration for `java.util.List<E>`. This didn't matter for XAJavaInterop1 output, as it binds `List<E>` as `System.Collections.Generic.IList<T>`, but it *does* matter for JavaInterop1 output, as it doesn't special-case `List<E>`. (Perhaps it should! Or this helps "lower" the need for improved generics! Or…) Add a declaration for `java.util.List<E>` to Java_Util_List.cs, and ParameterXPath.cs, so that we can set `TryJavaInterop1 => true`. Also add a declaration for `java.util.List<E>` to NormalMethods.cs. This doesn't allow us to enable `TryJavaInterop1 => true`, because of the "`Handle` isn't a public property" issue, but it'll be a necessary prerequisite to enable NormalMethods.cs in the future.
1 parent 32506ce commit 87fdb8e

22 files changed

+272
-43
lines changed

tests/generator-Tests/Integration-Tests/Java_Util_List.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace generatortests
66
[TestFixture]
77
public class Java_Util_List : BaseGeneratorTest
88
{
9-
protected override bool TryJavaInterop1 => false;
9+
protected override bool TryJavaInterop1 => true;
1010

1111
[Test]
1212
public void GeneratedOK ()

tests/generator-Tests/Integration-Tests/PamareterXPath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace generatortests
66
[TestFixture]
77
public class ParameterXPath : BaseGeneratorTest
88
{
9-
protected override bool TryJavaInterop1 => false;
9+
protected override bool TryJavaInterop1 => true;
1010

1111
[Test]
1212
public void GeneratedOK ()

tests/generator-Tests/expected.ji/NormalMethods/NormalMethods.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414
final="false" name="Integer" static="false" visibility="public">
1515
</class>
1616
</package>
17+
18+
<package name="java.util" jni-name="java/util">
19+
<interface abstract="true" deprecated="not deprecated" final="false" name="List" static="false" visibility="public" jni-signature="Ljava/util/List;">
20+
<typeParameters>
21+
<typeParameter name="E" classBound="java.lang.Object" jni-classBound="Ljava/lang/Object;"></typeParameter>
22+
</typeParameters>
23+
</interface>
24+
<class abstract="false" deprecated="not deprecated" extends="java.lang.Object" extends-generic-aware="java.lang.Object" jni-extends="Ljava/lang/Object;" final="false" name="ArrayList" static="false" visibility="public" jni-signature="Ljava/util/ArrayList;">
25+
<typeParameters>
26+
<typeParameter name="E" classBound="java.lang.Object" jni-classBound="Ljava/lang/Object;"></typeParameter>
27+
</typeParameters>
28+
</class>
29+
</package>
30+
1731
<package name="xamarin.test">
1832
<!--
1933
public class SomeObject {

tests/generator-Tests/expected.ji/ParameterXPath/Java.Lang.Integer.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
#nullable restore
111
using System;
212
using System.Collections.Generic;
313
using Java.Interop;

tests/generator-Tests/expected.ji/ParameterXPath/Java.Lang.Object.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
#nullable restore
111
using System;
212
using System.Collections.Generic;
313
using Java.Interop;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Java.Interop;
4+
5+
namespace Java.Util {
6+
7+
// Metadata.xml XPath interface reference: path="/api/package[@name='java.util']/interface[@name='List']"
8+
[global::Java.Interop.JniTypeSignature ("java/util/List", GenerateJavaPeer=false)]
9+
[global::Java.Interop.JavaTypeParameters (new string [] {"E"})]
10+
public partial interface IList : IJavaPeerable {
11+
}
12+
13+
[global::Java.Interop.JniTypeSignature ("java/util/List", GenerateJavaPeer=false)]
14+
internal partial class IListInvoker : global::Java.Lang.Object, IList {
15+
[global::System.Diagnostics.DebuggerBrowsable (global::System.Diagnostics.DebuggerBrowsableState.Never)]
16+
[global::System.ComponentModel.EditorBrowsable (global::System.ComponentModel.EditorBrowsableState.Never)]
17+
public override global::Java.Interop.JniPeerMembers JniPeerMembers {
18+
get { return _members_java_util_List; }
19+
}
20+
21+
static readonly JniPeerMembers _members_java_util_List = new JniPeerMembers ("java/util/List", typeof (IListInvoker));
22+
23+
public IListInvoker (ref JniObjectReference reference, JniObjectReferenceOptions options) : base (ref reference, options)
24+
{
25+
}
26+
27+
}
28+
}

tests/generator-Tests/expected.ji/ParameterXPath/Mono.Android.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<ItemGroup>
88
<Compile Include="$(MSBuildThisFileDirectory)Java.Lang.Integer.cs" />
99
<Compile Include="$(MSBuildThisFileDirectory)Java.Lang.Object.cs" />
10+
<Compile Include="$(MSBuildThisFileDirectory)Java.Util.IList.cs" />
1011
<Compile Include="$(MSBuildThisFileDirectory)Xamarin.Test.A.cs" />
1112
<Compile Include="$(MSBuildThisFileDirectory)__NamespaceMapping__.cs" />
1213
</ItemGroup>

tests/generator-Tests/expected.ji/ParameterXPath/ParameterXPath.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
final="false" name="Integer" static="false" visibility="public">
88
</class>
99
</package>
10+
11+
<package name="java.util" jni-name="java/util">
12+
<interface abstract="true" deprecated="not deprecated" final="false" name="List" static="false" visibility="public" jni-signature="Ljava/util/List;">
13+
<typeParameters>
14+
<typeParameter name="E" classBound="java.lang.Object" jni-classBound="Ljava/lang/Object;"></typeParameter>
15+
</typeParameters>
16+
</interface>
17+
</package>
18+
1019
<package name="xamarin.test">
1120
<!--
1221
public class A<T extends java.lang.Object> extends java.lang.Object {

tests/generator-Tests/expected.ji/ParameterXPath/Xamarin.Test.A.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
#nullable restore
111
using System;
212
using System.Collections.Generic;
313
using Java.Interop;
@@ -21,31 +31,30 @@ protected A (ref JniObjectReference reference, JniObjectReferenceOptions options
2131
}
2232

2333
// Metadata.xml XPath method reference: path="/api/package[@name='xamarin.test']/class[@name='A']/method[@name='setA' and count(parameter)=1 and parameter[1][@type='T']]"
34+
[global::Java.Interop.JniMethodSignature ("setA", "(Ljava/lang/Object;)V")]
2435
public virtual unsafe void SetA (global::Java.Lang.Object adapter)
2536
{
2637
const string __id = "setA.(Ljava/lang/Object;)V";
27-
IntPtr native_adapter = JNIEnv.ToLocalJniHandle (adapter);
38+
var native_adapter = (adapter?.PeerReference ?? default);
2839
try {
2940
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
3041
__args [0] = new JniArgumentValue (native_adapter);
3142
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
3243
} finally {
33-
JNIEnv.DeleteLocalRef (native_adapter);
3444
global::System.GC.KeepAlive (adapter);
3545
}
3646
}
3747

3848
// Metadata.xml XPath method reference: path="/api/package[@name='xamarin.test']/class[@name='A']/method[@name='listTest' and count(parameter)=1 and parameter[1][@type='java.util.List&lt;java.lang.Integer&gt;']]"
39-
public virtual unsafe void ListTest (global::System.Collections.Generic.IList<global::Java.Lang.Integer> p0)
49+
[global::Java.Interop.JniMethodSignature ("listTest", "(Ljava/util/List;)V")]
50+
public virtual unsafe void ListTest (global::Java.Util.IList p0)
4051
{
4152
const string __id = "listTest.(Ljava/util/List;)V";
42-
IntPtr native_p0 = global::Android.Runtime.JavaList<global::Java.Lang.Integer>.ToLocalJniHandle (p0);
4353
try {
4454
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
45-
__args [0] = new JniArgumentValue (native_p0);
55+
__args [0] = new JniArgumentValue (p0);
4656
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
4757
} finally {
48-
JNIEnv.DeleteLocalRef (native_p0);
4958
global::System.GC.KeepAlive (p0);
5059
}
5160
}

tests/generator-Tests/expected.ji/java.util.List/Java.Lang.Object.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
#nullable restore
111
using System;
212
using System.Collections.Generic;
313
using Java.Interop;

0 commit comments

Comments
 (0)