Skip to content

Commit

Permalink
[generator] Extend skipInvokerMethods support to interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Mar 5, 2024
1 parent 14a9470 commit 03f8edf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ public static InterfaceGen CreateInterface (XElement pkg, XElement elem, CodeGen
!options.SupportNestedInterfaceTypes
};

if (elem.Attribute ("skipInvokerMethods")?.Value is string skip)
foreach (var m in skip.Split (new char [] { ',', ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
iface.SkippedInvokerMethods.Add (m);

FillApiSince (iface, pkg, elem);
SetLineInfo (iface, elem, options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace MonoDroid.Generation
public class ClassGen : GenBase
{
bool fill_explicit_implementation_started;
HashSet<string> skipped_invoker_methods;

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

Expand Down Expand Up @@ -356,8 +355,6 @@ public override void ResetValidation ()
base.ResetValidation ();
}

public HashSet<string> SkippedInvokerMethods => skipped_invoker_methods ??= new HashSet<string> ();

public override string ToNative (CodeGenerationOptions opt, string varname, Dictionary<string, string> mappings = null)
{
if (opt.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class GenBase : IGeneratable, ApiVersionsSupport.IApiAvailabilit
protected bool iface_validation_failed;
protected GenBaseSupport support;
protected bool validated = false;
HashSet<string> skipped_invoker_methods;

readonly List<string> implemented_interfaces = new List<string> ();
readonly Dictionary<string, Method> jni_sig_hash = new Dictionary<string, Method> ();
Expand Down Expand Up @@ -854,6 +855,8 @@ bool ReturnTypeMatches (Method m, Method mm)

public bool ShouldGenerateAnnotationAttribute => IsAnnotation;

public HashSet<string> SkippedInvokerMethods => skipped_invoker_methods ??= new HashSet<string> ();

public void StripNonBindables (CodeGenerationOptions opt)
{
// Strip out default interface methods if not desired
Expand Down
15 changes: 9 additions & 6 deletions tools/generator/SourceWriters/InterfaceInvokerClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public InterfaceInvokerClass (InterfaceGen iface, CodeGenerationOptions opt, Cod

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

AddMemberInvokers (iface, new HashSet<string> (), opt, context);
AddMemberInvokers (iface, new HashSet<string> (), iface.SkippedInvokerMethods, opt, context);
}

static HashSet<InterfaceGen> GetCompleteImplementedInterfaces (HashSet<InterfaceGen> ifaces, InterfaceGen toplevel)
Expand All @@ -81,15 +81,15 @@ static HashSet<InterfaceGen> GetCompleteImplementedInterfaces (HashSet<Interface
return ifaces;
}

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

foreach (var i in iface.GetAllDerivedInterfaces ()) {
AddPropertyInvokers (iface, i.Properties.Where (p => !p.Getter.IsStatic && !p.Getter.IsInterfaceDefaultMethod), members, opt, context);
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);
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);
AddCharSequenceEnumerators (i);
}
}
Expand All @@ -113,10 +113,13 @@ void AddPropertyInvokers (InterfaceGen iface, IEnumerable<Property> properties,
Properties.Add (new InterfaceInvokerProperty (iface, prop, opt, context));
}
}

void AddMethodInvokers (InterfaceGen iface, IEnumerable<Method> methods, HashSet<string> members, CodeGenerationOptions opt, CodeGeneratorContext context)
void AddMethodInvokers (InterfaceGen iface, IEnumerable<Method> methods, HashSet<string> members, HashSet<string> skipInvokers, CodeGenerationOptions opt, CodeGeneratorContext context)
{
foreach (var m in methods) {
if (skipInvokers.Contains ($"{m.DeclaringType.RawJniName}.{m.JavaName}{m.JniSignature}"))
continue;

var sig = m.GetSignature ();

if (members.Contains (sig))
Expand Down

0 comments on commit 03f8edf

Please sign in to comment.