Skip to content

Commit 595625f

Browse files
committed
[generator] Extend skipInvokerMethods support to interfaces.
1 parent 14a9470 commit 595625f

File tree

8 files changed

+49
-14
lines changed

8 files changed

+49
-14
lines changed

tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,32 @@ public void SkipInvokerMethodsMetadata ()
352352
Assert.False (writer.ToString ().Contains ("public abstract Com.Xamarin.Android.MyBaseClass DoStuff ();"), $"was: `{writer}`");
353353
}
354354

355+
[Test]
356+
public void SkipInterfaceInvokerMethodsMetadata ()
357+
{
358+
var xml = @"<api>
359+
<package name='java.lang' jni-name='java/lang'>
360+
<class abstract='false' deprecated='not deprecated' final='false' name='Object' static='false' visibility='public' jni-signature='Ljava/lang/Object;' />
361+
</package>
362+
<package name='com.xamarin.android' jni-name='com/xamarin/android'>
363+
<interface abstract='true' deprecated='not deprecated' extends='java.lang.Object' extends-generic-aware='java.lang.Object' jni-extends='Ljava/lang/Object;' final='false' name='MyInterface' static='false' visibility='public' jni-signature='Lcom/xamarin/android/MyInterface;' skipInvokerMethods='com/xamarin/android/MyInterface.countAffectedRows()I'>
364+
<method abstract='true' deprecated='not deprecated' final='false' name='countAffectedRows' jni-signature='()I' bridge='false' native='false' return='int' jni-return='I' static='false' synchronized='false' synthetic='false' visibility='public'></method>
365+
</interface>
366+
</package>
367+
</api>";
368+
369+
var gens = ParseApiDefinition (xml);
370+
var iface = gens.Single (g => g.Name == "IMyInterface");
371+
372+
generator.Context.ContextTypes.Push (iface);
373+
generator.WriteType (iface, string.Empty, new GenerationInfo ("", "", "MyAssembly"));
374+
generator.Context.ContextTypes.Pop ();
375+
376+
// Ensure the invoker for 'countAffectedRows' isn't generated
377+
Assert.False (writer.ToString ().Contains ("static Delegate cb_countAffectedRows;"), $"was: `{writer}`");
378+
Assert.False (writer.ToString ().Contains ("InvokeAbstractInt32Method"), $"was: `{writer}`");
379+
}
380+
355381
[Test]
356382
public void CompatVirtualMethod_Class ()
357383
{

tools/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ public static ClassGen CreateClass (XElement pkg, XElement elem, CodeGenerationO
117117
!options.SupportNestedInterfaceTypes
118118
};
119119

120-
if (elem.Attribute ("skipInvokerMethods")?.Value is string skip)
121-
foreach (var m in skip.Split (new char [] { ',', ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
122-
klass.SkippedInvokerMethods.Add (m);
123-
124120
FillApiSince (klass, pkg, elem);
125121
SetLineInfo (klass, elem, options);
126122

@@ -264,6 +260,10 @@ public static GenBaseSupport CreateGenBaseSupport (XElement pkg, XElement elem,
264260
Visibility = elem.XGetAttribute ("visibility")
265261
};
266262

263+
if (elem.Attribute ("skipInvokerMethods")?.Value is string skip)
264+
foreach (var m in skip.Split (new char [] { ',', ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
265+
support.SkippedInvokerMethods.Add (m);
266+
267267
if (support.IsDeprecated) {
268268
support.DeprecatedComment = elem.XGetAttribute ("deprecated");
269269

tools/generator/Java.Interop.Tools.Generator.ObjectModel/ClassGen.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ namespace MonoDroid.Generation
1111
public class ClassGen : GenBase
1212
{
1313
bool fill_explicit_implementation_started;
14-
HashSet<string> skipped_invoker_methods;
1514

1615
public List<Ctor> Ctors { get; private set; } = new List<Ctor> ();
1716

@@ -356,8 +355,6 @@ public override void ResetValidation ()
356355
base.ResetValidation ();
357356
}
358357

359-
public HashSet<string> SkippedInvokerMethods => skipped_invoker_methods ??= new HashSet<string> ();
360-
361358
public override string ToNative (CodeGenerationOptions opt, string varname, Dictionary<string, string> mappings = null)
362359
{
363360
if (opt.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1) {

tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,8 @@ bool ReturnTypeMatches (Method m, Method mm)
854854

855855
public bool ShouldGenerateAnnotationAttribute => IsAnnotation;
856856

857+
public HashSet<string> SkippedInvokerMethods => support.SkippedInvokerMethods;
858+
857859
public void StripNonBindables (CodeGenerationOptions opt)
858860
{
859861
// Strip out default interface methods if not desired

tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBaseSupport.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using System;
2+
using System.Collections.Generic;
23

34
namespace MonoDroid.Generation
45
{
56
public class GenBaseSupport
67
{
8+
HashSet<string> skipped_invoker_methods;
9+
710
public string AnnotatedVisibility { get; set; }
811
public bool IsAcw { get; set; }
912
public bool IsDeprecated { get; set; }
@@ -21,6 +24,8 @@ public class GenBaseSupport
2124
public string Visibility { get; set; }
2225
public GenericParameterDefinitionList TypeParameters { get; set; }
2326

27+
public HashSet<string> SkippedInvokerMethods => skipped_invoker_methods ??= new HashSet<string> ();
28+
2429
public virtual bool OnValidate (CodeGenerationOptions opt)
2530
{
2631
// See com.google.inject.internal.util package for this case.

tools/generator/Java.Interop.Tools.Generator.ObjectModel/Method.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public string GetMetadataXPathReference (GenBase declaringType) =>
193193

194194
public string GetSignature () => $"n_{JavaName}:{JniSignature}:{ConnectorName}";
195195

196+
public string GetSkipInvokerSignature () => $"{DeclaringType.RawJniName}.{JavaName}{JniSignature}";
197+
196198
public bool IsEventHandlerWithHandledProperty => RetVal.JavaName == "boolean" && EventName != "";
197199

198200
public override bool IsGeneric => base.IsGeneric || RetVal.IsGeneric;

tools/generator/SourceWriters/ClassInvokerClass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void AddPropertyInvokers (ClassGen klass, IEnumerable<Property> properties, Hash
103103
void AddMethodInvokers (ClassGen klass, IEnumerable<Method> methods, HashSet<string> members, HashSet<string> skipInvokers, InterfaceGen gen, CodeGenerationOptions opt)
104104
{
105105
foreach (var m in methods) {
106-
if (skipInvokers.Contains ($"{m.DeclaringType.RawJniName}.{m.JavaName}{m.JniSignature}"))
106+
if (skipInvokers.Contains (m.GetSkipInvokerSignature ()))
107107
continue;
108108

109109
var sig = m.GetSignature ();

tools/generator/SourceWriters/InterfaceInvokerClass.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public InterfaceInvokerClass (InterfaceGen iface, CodeGenerationOptions opt, Cod
6969

7070
Constructors.Add (new InterfaceInvokerConstructor (opt, iface, context));
7171

72-
AddMemberInvokers (iface, new HashSet<string> (), opt, context);
72+
AddMemberInvokers (iface, new HashSet<string> (), iface.SkippedInvokerMethods, opt, context);
7373
}
7474

7575
static HashSet<InterfaceGen> GetCompleteImplementedInterfaces (HashSet<InterfaceGen> ifaces, InterfaceGen toplevel)
@@ -81,15 +81,15 @@ static HashSet<InterfaceGen> GetCompleteImplementedInterfaces (HashSet<Interface
8181
return ifaces;
8282
}
8383

84-
void AddMemberInvokers (InterfaceGen iface, HashSet<string> members, CodeGenerationOptions opt, CodeGeneratorContext context)
84+
void AddMemberInvokers (InterfaceGen iface, HashSet<string> members, HashSet<string> skipInvokers, CodeGenerationOptions opt, CodeGeneratorContext context)
8585
{
8686
AddPropertyInvokers (iface, iface.Properties.Where (p => !p.Getter.IsStatic && !p.Getter.IsInterfaceDefaultMethod), members, opt, context);
87-
AddMethodInvokers (iface, iface.Methods.Where (m => !m.IsStatic && !m.IsInterfaceDefaultMethod), members, opt, context);
87+
AddMethodInvokers (iface, iface.Methods.Where (m => !m.IsStatic && !m.IsInterfaceDefaultMethod), members, skipInvokers, opt, context);
8888
AddCharSequenceEnumerators (iface);
8989

9090
foreach (var i in iface.GetAllDerivedInterfaces ()) {
9191
AddPropertyInvokers (iface, i.Properties.Where (p => !p.Getter.IsStatic && !p.Getter.IsInterfaceDefaultMethod), members, opt, context);
92-
AddMethodInvokers (iface, i.Methods.Where (m => !m.IsStatic && !m.IsInterfaceDefaultMethod && !iface.IsCovariantMethod (m) && !(i.FullName.StartsWith ("Java.Lang.ICharSequence", StringComparison.Ordinal) && m.Name.EndsWith ("Formatted", StringComparison.Ordinal))), members, opt, context);
92+
AddMethodInvokers (iface, i.Methods.Where (m => !m.IsStatic && !m.IsInterfaceDefaultMethod && !iface.IsCovariantMethod (m) && !(i.FullName.StartsWith ("Java.Lang.ICharSequence", StringComparison.Ordinal) && m.Name.EndsWith ("Formatted", StringComparison.Ordinal))), members, skipInvokers, opt, context);
9393
AddCharSequenceEnumerators (i);
9494
}
9595
}
@@ -113,10 +113,13 @@ void AddPropertyInvokers (InterfaceGen iface, IEnumerable<Property> properties,
113113
Properties.Add (new InterfaceInvokerProperty (iface, prop, opt, context));
114114
}
115115
}
116-
117-
void AddMethodInvokers (InterfaceGen iface, IEnumerable<Method> methods, HashSet<string> members, CodeGenerationOptions opt, CodeGeneratorContext context)
116+
117+
void AddMethodInvokers (InterfaceGen iface, IEnumerable<Method> methods, HashSet<string> members, HashSet<string> skipInvokers, CodeGenerationOptions opt, CodeGeneratorContext context)
118118
{
119119
foreach (var m in methods) {
120+
if (skipInvokers.Contains (m.GetSkipInvokerSignature ()))
121+
continue;
122+
120123
var sig = m.GetSignature ();
121124

122125
if (members.Contains (sig))

0 commit comments

Comments
 (0)