Skip to content

Commit 021d434

Browse files
committed
[generator] fix generic parameter code generation for interface.
This fixes bug #43513. The background for the fix is, well, complicated. It was generating wrong code: // This method is explicitly implemented as a member of an instantiated Com.Google.Android.Exoplayer.Drm.IExoMediaDrm void global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrm.SetOnEventListener (global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrmOnEventListener p0) { SetOnEventListener (global::Java.Interop.JavaObjectExtensions.JavaCast<global::Com.Google.Android.Exoplayer.Drm.IExoMediaDrmOnEventListener<Java.Lang.Object>>(p0)); } where IExoMediaDrmOnEventListener is a normally generated interface ACW which does not have any generic parameter. The problem is, the Java API has generic argument T. Usually it does not matter in normal classes. But reference to an interface type with generic arguments is treated special: `IRequireGenericMarshal` It was introduced at old monodroid commit 443598f (which is not in this Java.Interop repo) for fixing bug #5979 to handle IList and ICollection for collection marshaling. So... basically ACWs were not expected to behave as IRequireGenericMarshal. And now that behavior bites us at bug #43513. Now, how to fix this new bug? This change introduces another boolean flag to determine if reference to this type should really output generic arguments. If it is False, then do not output any further. This is the best logical explanation I can make right now. What I still wonder are 1) whether it is only about InterfaceGen, and 2) if we could rather simplify things and eliminate this IRequireGenericMarshal thing. But so far I have no answer to those.
1 parent b4e151e commit 021d434

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

tools/generator/CollectionSymbol.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public string ElementType {
5252
get { return null; }
5353
}
5454

55+
public bool MayHaveManagedGenericArguments {
56+
get { return true; }
57+
}
58+
5559
public string GetObjectHandleProperty (string variable)
5660
{
5761
return $"((global::Java.Lang.Object) {variable}).Handle";

tools/generator/GenericSymbol.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public string FromNative (CodeGenerationOptions opt, string varname, bool owned)
9191

9292
public string GetGenericType (Dictionary<string, string> mappings)
9393
{
94-
return gen.FullName + (mappings == null ? tps : MapTypeParams (mappings));
94+
var rgm = gen as IRequireGenericMarshal;
95+
return gen.FullName + (rgm != null && !rgm.MayHaveManagedGenericArguments ? null : mappings == null ? tps : MapTypeParams (mappings));
9596
}
9697

9798
public string ToNative (CodeGenerationOptions opt, string varname)

tools/generator/IRequireGenericMarshal.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace MonoDroid.Generation
55
{
66
public interface IRequireGenericMarshal
77
{
8+
bool MayHaveManagedGenericArguments { get; }
89
string GetGenericJavaObjectTypeOverride ();
910
string ToInteroperableJavaObject (string varname);
1011
}

tools/generator/InterfaceGen.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ public ManagedInterfaceGen (TypeDefinition t)
2424
AddMethod (new ManagedMethod (this, m));
2525
}
2626
}
27+
2728
public override string ArgsType {
2829
get { throw new NotImplementedException (); }
2930
}
31+
32+
public override bool MayHaveManagedGenericArguments {
33+
get { return !this.IsAcw; }
34+
}
3035
}
3136
#endif
3237

@@ -109,6 +114,10 @@ public bool IsListener {
109114
get { return Name.EndsWith ("Listener") && Properties.Count == 0 && Interfaces.Count == 0; }
110115
}
111116

117+
public virtual bool MayHaveManagedGenericArguments {
118+
get { return false; }
119+
}
120+
112121
public override string NativeType {
113122
get { return "IntPtr"; }
114123
}

0 commit comments

Comments
 (0)