[catalyst][addressbookui] Remove AddressBookUI framework that is not available on Catalyst (#10711)

This required working around internal ctor that uses internal (non
re-generated) types. E.g.

```
build/dotnet/maccatalyst/ref/Xamarin.iOS.cs(9201,64): error CS0234: The type or namespace name 'ABFunc<>' does not exist in the namespace 'AddressBookUI' (are you missing an assembly reference?)
```

We cannot just skip such constructor since the C# compiler will add a
**public** default one when none is present (and that's the case for
the error above),

This also required fixing the ctor chaining code (which can't be shared
with the, previously fixed, override code) so base classes could be
called for some `*EventArg` types.

Follow up to https://github.com/xamarin/xamarin-macios/pull/10658 , https://github.com/xamarin/xamarin-macios/pull/10678 and https://github.com/xamarin/xamarin-macios/pull/10706

This is the last framework that needs removal - but there's still a few
`unknown-*` entries in Catalyst-supported frameworks (more PR coming).
This commit is contained in:
Sebastien Pouliot 2021-02-25 11:22:02 -05:00 коммит произвёл GitHub
Родитель b857c971f9
Коммит 0f69381be8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 57 добавлений и 52 удалений

Просмотреть файл

@ -2183,7 +2183,6 @@ MACCATALYST_FRAMEWORKS = \
AdServices \
AdSupport \
AddressBook \
AddressBookUI \
AppTrackingTransparency \
AudioToolbox \
AudioUnit \

Просмотреть файл

@ -97,7 +97,21 @@ namespace GenerateTypeForwarders {
{
if (method.IsPrivate)
return;
if (!method.IsConstructor && method.IsSpecialName)
if (method.IsConstructor) {
// we can have an internal ctor using internal types that are not generated leading to uncompilable code
// e.g. `internal DisplayedPropertiesCollection (ABFunc<NSNumber[]> g, Action<NSNumber[]> s)`
if (method.IsAssembly && method.HasParameters) {
foreach (var p in method.Parameters) {
// check is the type is public - if not it won't be generated
if (p.ParameterType.Resolve ().IsNotPublic) {
// but we can't skip the generation as without any .ctor the compiler will add a default, public one
// so we create a custom signature to ensure an (internal) ctor exists
p.ParameterType = method.DeclaringType;
}
}
}
} else if (method.IsSpecialName)
return;
if (method.Name == "Finalize")
@ -201,15 +215,14 @@ namespace GenerateTypeForwarders {
if (nsobject && method.IsConstructor && !method.IsStatic)
sb.Append ('\t', indent + 1).AppendLine (" : base (System.IntPtr.Zero)");
// if there is a base constructor with the same signature, call it
else if (method.IsConstructor && method.HasParameters && method.Parameters.Count > 0) {
var baseConstructors = method.DeclaringType.BaseType?.Resolve ()?.Methods?.Where (v => v.IsConstructor && v.Parameters.Count == method.Parameters.Count);
if (AllParameterTypeMatch (baseConstructors, method.Parameters, out var _)) {
else if (method.IsConstructor && method.HasParameters) {
var baseConstructors = method.DeclaringType.BaseType?.Resolve ()?.Methods?.Where (v => v.IsConstructor && v.HasParameters);
if (StartParameterTypeMatch (baseConstructors, method.Parameters, out var baseCtor)) {
sb.Append ($"{strIndent}\t: base (");
for (var i = 0; i < method.Parameters.Count; i++) {
var param = method.Parameters [i];
for (var i = 0; i < baseCtor.Parameters.Count; i++) {
if (i > 0)
sb.Append (", ");
sb.Append ($"@{param.Name}");
sb.Append ($"@{method.Parameters [i].Name}"); // need the original name
}
sb.AppendLine (")");
}
@ -272,6 +285,28 @@ namespace GenerateTypeForwarders {
return false;
}
static bool StartParameterTypeMatch (IEnumerable<MethodDefinition> methods, IList<ParameterDefinition> parameters, out MethodDefinition matchingMethod)
{
matchingMethod = null;
foreach (var method in methods) {
if (parameters.Count == 0) {
matchingMethod = method;
return true;
}
var parameterCount = method.HasParameters ? method.Parameters.Count : 0;
for (var i = 0; i < parameters.Count; i++) {
var a = method.Parameters [i];
var b = parameters [i];
if (a.ParameterType.FullName == b.ParameterType.FullName) {
matchingMethod = method;
return true;
}
}
}
return false;
}
static void EmitField (StringBuilder sb, FieldDefinition fd, int indent)
{
var strIndent = new string ('\t', indent);

Просмотреть файл

@ -22,8 +22,10 @@ using System.Xml;
using Mono.Data.Sqlite;
#endif
using MonoTouch;
#if !__TVOS__ && !__WATCHOS__
#if HAS_ADDRESSBOOK
using AddressBook;
#endif
#if HAS_ADDRESSBOOKUI
using AddressBookUI;
#endif
#if !__WATCHOS__
@ -172,7 +174,7 @@ namespace LinkSdk {
Assert.That (m.GetType ().Name, Is.EqualTo ("RuntimeModule"), "RuntimeModule");
}
#if !__TVOS__ && !__WATCHOS__
#if HAS_ADDRESSBOOK && HAS_ADDRESSBOOKUI
[Test]
// http://bugzilla.xamarin.com/show_bug.cgi?id=980
public void Bug980_AddressBook_NRE ()
@ -199,7 +201,7 @@ namespace LinkSdk {
TestRuntime.AssertSystemVersion (PlatformName.MacCatalyst, 14, 0, throwIfOtherPlatform: false); // The AddressBook framework was introduced in Mac Catalyst 14.0
Assert.IsNotNull (ABPersonAddressKey.City, "ABPersonAddressKey");
}
#endif // !__TVOS__ && !__WATCHOS__
#endif // HAS_ADDRESSBOOKUI
[Test]
// http://bugzilla.xamarin.com/show_bug.cgi?id=1387

Просмотреть файл

@ -7,7 +7,7 @@
// Copyright 2012 Xamarin Inc. All rights reserved.
//
#if !__TVOS__ && !__WATCHOS__ && !MONOMAC
#if HAS_ADDRESSBOOK
using System;
using Foundation;
@ -61,4 +61,4 @@ namespace MonoTouchFixtures.AddressBook {
}
}
#endif // !__TVOS__ && !__WATCHOS__
#endif // HAS_ADDRESSBOOKUI

Просмотреть файл

@ -7,7 +7,7 @@
// Copyright 2012-2014, 2016 Xamarin Inc. All rights reserved.
//
#if !__TVOS__ && !__WATCHOS__ && !MONOMAC
#if HAS_ADDRESSBOOKUI
using System;
using System.Globalization;
@ -76,4 +76,4 @@ namespace MonoTouchFixtures.AddressBookUI {
}
}
#endif // !__TVOS__ && !__WATCHOS__
#endif // HAS_ADDRESSBOOKUI

Просмотреть файл

@ -7,8 +7,10 @@ using System.Threading;
using CoreFoundation;
using MapKit;
#if !__TVOS__ && !__WATCHOS__ && !MONOMAC
#if HAS_ADDRESSBOOK
using AddressBook;
#endif
#if HAS_ADDRESSBOOKUI
using AddressBookUI;
#endif
using Foundation;
@ -2202,7 +2204,7 @@ namespace MonoTouchFixtures.ObjCRuntime {
}
#endif // !__WATCHOS__
#if !__TVOS__ && !__WATCHOS__ && !MONOMAC// No ABPeoplePickerNavigationControllerDelegate
#if HAS_ADDRESSBOOK && HAS_ADDRESSBOOKUI
[Test]
public void VoidPtrToINativeObjectArgument ()
{
@ -2225,7 +2227,7 @@ namespace MonoTouchFixtures.ObjCRuntime {
personHandle = selectedPerson.Handle;
}
}
#endif // !__TVOS__
#endif // HAS_ADDRESSBOOKUI
#if !__TVOS__ // No Contacts framework in TVOS
[Test]

Просмотреть файл

@ -1,33 +0,0 @@
!missing-release-attribute-on-return-value! Foundation.NSObject AddressBookUI.ABNewPersonViewController::get_WeakDelegate()'s selector's ('newPersonViewDelegate') Objective-C method family ('new') indicates that the native method returns a retained object, and as such a '[return: Release]' attribute is required.
!unknown-field! ABPersonBirthdayProperty bound
!unknown-field! ABPersonDatesProperty bound
!unknown-field! ABPersonDepartmentNameProperty bound
!unknown-field! ABPersonEmailAddressesProperty bound
!unknown-field! ABPersonFamilyNameProperty bound
!unknown-field! ABPersonGivenNameProperty bound
!unknown-field! ABPersonInstantMessageAddressesProperty bound
!unknown-field! ABPersonJobTitleProperty bound
!unknown-field! ABPersonMiddleNameProperty bound
!unknown-field! ABPersonNamePrefixProperty bound
!unknown-field! ABPersonNameSuffixProperty bound
!unknown-field! ABPersonNicknameProperty bound
!unknown-field! ABPersonNoteProperty bound
!unknown-field! ABPersonOrganizationNameProperty bound
!unknown-field! ABPersonPhoneNumbersProperty bound
!unknown-field! ABPersonPhoneticFamilyNameProperty bound
!unknown-field! ABPersonPhoneticGivenNameProperty bound
!unknown-field! ABPersonPhoneticMiddleNameProperty bound
!unknown-field! ABPersonPostalAddressesProperty bound
!unknown-field! ABPersonPreviousFamilyNameProperty bound
!unknown-field! ABPersonRelatedNamesProperty bound
!unknown-field! ABPersonSocialProfilesProperty bound
!unknown-field! ABPersonUrlAddressesProperty bound
!unknown-pinvoke! ABCreateStringWithAddressDictionary bound
!unknown-protocol! ABNewPersonViewControllerDelegate bound
!unknown-protocol! ABPeoplePickerNavigationControllerDelegate bound
!unknown-protocol! ABPersonViewControllerDelegate bound
!unknown-protocol! ABUnknownPersonViewControllerDelegate bound
!unknown-type! ABNewPersonViewController bound
!unknown-type! ABPeoplePickerNavigationController bound
!unknown-type! ABPersonViewController bound
!unknown-type! ABUnknownPersonViewController bound