Skip to content

Commit

Permalink
Add check for JniTypeSignature.GenerateJavaPeer==false
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpeppers committed Sep 8, 2022
1 parent 721f843 commit e1b2057
Showing 1 changed file with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,25 +210,47 @@ void PreserveInterfaces (TypeDefinition type)
if (!type.HasInterfaces)
return;

// Return if [Register(DoNotGenerateAcw=true)] is on the type
if (type.HasCustomAttributes) {
foreach (var attr in type.CustomAttributes) {
if (attr.AttributeType.FullName == "Android.Runtime.RegisterAttribute") {
if (!ShouldPreserveInterfaces (type))
return;

foreach (var iface in type.Interfaces) {
Annotations.Mark (iface.InterfaceType.Resolve ());
}
}

// False if [Register(DoNotGenerateAcw=true)] is on the type
// False if [JniTypeSignature(GenerateJavaPeer=false)] is on the type
bool ShouldPreserveInterfaces (TypeDefinition type)
{
if (!type.HasCustomAttributes)
return true;

foreach (var attr in type.CustomAttributes) {
switch (attr.AttributeType.FullName) {
case "Android.Runtime.RegisterAttribute":
foreach (var property in attr.Properties) {
if (property.Name == "DoNotGenerateAcw") {
if (property.Argument.Value is bool value && value)
return;
return false;
break;
}
}
break;
}
case "Java.Interop.JniTypeSignatureAttribute":
foreach (var property in attr.Properties) {
if (property.Name == "GenerateJavaPeer") {
if (property.Argument.Value is bool value && !value)
return false;
break;
}
}
break;
default:
break;
}
}

foreach (var iface in type.Interfaces) {
Annotations.Mark (iface.InterfaceType.Resolve ());
}
return true;
}
#endif // ILLINK

Expand Down

0 comments on commit e1b2057

Please sign in to comment.