From 47881528ccf15ce9543a04f35b3e6709cfebdda9 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 21 Nov 2022 21:05:20 +0100 Subject: [PATCH] [Foundation] Unify a few NSAttributedString constructor implementations. (#16804) Unify the code for the following constructors: * NSAttributedString (NSData data, NSDictionary options, out NSDictionary resultDocumentAttributes, ref/out NSError error); * NSAttributedString (NSUrl url, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, ref/out NSError error); * NSAttributedString (NSData data, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, ref/out NSError error); These functions use 'ref' arguments instead of 'out' arguments for mobile platforms (likely due to the generator not having proper 'out' parameter support when these functions were implemented), so improve to use 'out' parameters in XAMCORE_5_0 (and macOS, where they already use 'out' parameters). Also fix nullability. Ref: https://github.com/xamarin/xamarin-macios/issues/15216 --- src/foundation.cs | 52 +++++++++---------- .../api-annotations-dotnet/iOS-UIKit.ignore | 1 - .../macOS-AppKit.ignore | 1 - .../api-annotations-dotnet/tvOS-UIKit.ignore | 1 - tests/xtro-sharpie/iOS-UIKit.ignore | 1 - tests/xtro-sharpie/macOS-AppKit.ignore | 1 - tests/xtro-sharpie/tvOS-UIKit.ignore | 1 - tests/xtro-sharpie/watchOS-UIKit.ignore | 1 - 8 files changed, 24 insertions(+), 35 deletions(-) diff --git a/src/foundation.cs b/src/foundation.cs index 9eda2bab343b..e2859c09d5f5 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -332,23 +332,6 @@ partial interface NSAttributedString : NSCoding, NSMutableCopying, NSSecureCodin [Export ("initWithString:")] NativeHandle Constructor (string str); -#if !MONOMAC - [NoMac] - [iOS (7,0)] - [Wrap ("this (url, options.GetDictionary ()!, out resultDocumentAttributes, ref error)")] - NativeHandle Constructor (NSUrl url, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, ref NSError error); - - [NoMac] - [iOS (7,0)] - [Export ("initWithData:options:documentAttributes:error:")] - NativeHandle Constructor (NSData data, [NullAllowed] NSDictionary options, out NSDictionary resultDocumentAttributes, ref NSError error); - - [NoMac] - [iOS (7,0)] - [Wrap ("this (data, options.GetDictionary ()!, out resultDocumentAttributes, ref error)")] - NativeHandle Constructor (NSData data, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, ref NSError error); -#endif - [Export ("initWithString:attributes:")] [EditorBrowsable (EditorBrowsableState.Advanced)] NativeHandle Constructor (string str, [NullAllowed] NSDictionary attributes); @@ -369,11 +352,32 @@ partial interface NSAttributedString : NSCoding, NSMutableCopying, NSSecureCodin NativeHandle Constructor (NSUrl url, NSDictionary options, out NSDictionary resultDocumentAttributes, out NSError error); #endif -#if MONOMAC - [NoiOS][NoMacCatalyst][NoWatch][NoTV] [Export ("initWithData:options:documentAttributes:error:")] - NativeHandle Constructor (NSData data, [NullAllowed] NSDictionary options, out NSDictionary docAttributes, out NSError error); +#if XAMCORE_5_0 + NativeHandle Constructor (NSData data, NSDictionary options, out NSDictionary resultDocumentAttributes, out NSError error); +#elif __MACOS__ + NativeHandle Constructor (NSData data, NSDictionary options, out NSDictionary docAttributes, out NSError error); +#else + NativeHandle Constructor (NSData data, NSDictionary options, out NSDictionary resultDocumentAttributes, ref NSError error); +#endif + +#if __MACOS__ || XAMCORE_5_0 + [Wrap ("this (url, options.GetDictionary ()!, out resultDocumentAttributes, out error)")] + NativeHandle Constructor (NSUrl url, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, out NSError error); +#else + [Wrap ("this (url, options.GetDictionary ()!, out resultDocumentAttributes, ref error)")] + NativeHandle Constructor (NSUrl url, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, ref NSError error); +#endif + +#if __MACOS__ || XAMCORE_5_0 + [Wrap ("this (data, options.GetDictionary ()!, out resultDocumentAttributes, out error)")] + NativeHandle Constructor (NSData data, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, out NSError error); +#else + [Wrap ("this (data, options.GetDictionary ()!, out resultDocumentAttributes, ref error)")] + NativeHandle Constructor (NSData data, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, ref NSError error); +#endif +#if MONOMAC [NoiOS][NoMacCatalyst][NoWatch][NoTV] [Export ("initWithDocFormat:documentAttributes:")] NativeHandle Constructor(NSData wordDocFormat, out NSDictionary docAttributes); @@ -386,14 +390,6 @@ partial interface NSAttributedString : NSCoding, NSMutableCopying, NSSecureCodin [Export ("drawWithRect:options:")] void DrawString (CGRect rect, NSStringDrawingOptions options); - [NoiOS][NoMacCatalyst][NoWatch][NoTV] - [Wrap ("this (url, options.GetDictionary ()!, out resultDocumentAttributes, out error)")] - NativeHandle Constructor (NSUrl url, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, out NSError error); - - [NoiOS][NoMacCatalyst][NoWatch][NoTV] - [Wrap ("this (data, options.GetDictionary ()!, out resultDocumentAttributes, out error)")] - NativeHandle Constructor (NSData data, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, out NSError error); - [NoiOS][NoMacCatalyst][NoWatch][NoTV] [Deprecated (PlatformName.MacOSX, 10, 11, message: "Use 'NSAttributedString (NSUrl, NSDictionary, out NSDictionary, ref NSError)' instead.")] [Export ("initWithPath:documentAttributes:")] diff --git a/tests/xtro-sharpie/api-annotations-dotnet/iOS-UIKit.ignore b/tests/xtro-sharpie/api-annotations-dotnet/iOS-UIKit.ignore index 2c8343b13a16..e698b8382b38 100644 --- a/tests/xtro-sharpie/api-annotations-dotnet/iOS-UIKit.ignore +++ b/tests/xtro-sharpie/api-annotations-dotnet/iOS-UIKit.ignore @@ -60,7 +60,6 @@ !extra-null-allowed! 'System.Boolean UIKit.NSLayoutManagerDelegate::ShouldSetLineFragmentRect(UIKit.NSLayoutManager,CoreGraphics.CGRect&,CoreGraphics.CGRect&,System.Runtime.InteropServices.NFloat&,UIKit.NSTextContainer,Foundation.NSRange)' has a extraneous [NullAllowed] on parameter #2 !extra-null-allowed! 'System.Boolean UIKit.NSLayoutManagerDelegate::ShouldSetLineFragmentRect(UIKit.NSLayoutManager,CoreGraphics.CGRect&,CoreGraphics.CGRect&,System.Runtime.InteropServices.NFloat&,UIKit.NSTextContainer,Foundation.NSRange)' has a extraneous [NullAllowed] on parameter #3 !extra-null-allowed! 'System.Boolean UIKit.UIApplication::CanOpenUrl(Foundation.NSUrl)' has a extraneous [NullAllowed] on parameter #0 -!extra-null-allowed! 'System.Void Foundation.NSAttributedString::.ctor(Foundation.NSData,Foundation.NSDictionary,Foundation.NSDictionary&,Foundation.NSError&)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIAccessibilityCustomAction::.ctor(Foundation.NSAttributedString,UIKit.UIAccessibilityCustomActionHandler)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIAccessibilityCustomAction::.ctor(System.String,UIKit.UIAccessibilityCustomActionHandler)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIAccessibilityCustomAction::set_Name(System.String)' has a extraneous [NullAllowed] on parameter #0 diff --git a/tests/xtro-sharpie/api-annotations-dotnet/macOS-AppKit.ignore b/tests/xtro-sharpie/api-annotations-dotnet/macOS-AppKit.ignore index 6fd4b16ca30a..38af37d1554d 100644 --- a/tests/xtro-sharpie/api-annotations-dotnet/macOS-AppKit.ignore +++ b/tests/xtro-sharpie/api-annotations-dotnet/macOS-AppKit.ignore @@ -267,7 +267,6 @@ !extra-null-allowed! 'System.Void AppKit.NSView::set_ContentFilters(CoreImage.CIFilter[])' has a extraneous [NullAllowed] on parameter #0 !extra-null-allowed! 'System.Void AppKit.NSView::WillRemoveSubview(AppKit.NSView)' has a extraneous [NullAllowed] on parameter #0 !extra-null-allowed! 'System.Void Foundation.NSAttributedString::.ctor(Foundation.NSData,Foundation.NSDictionary,Foundation.NSDictionary&)' has a extraneous [NullAllowed] on parameter #1 -!extra-null-allowed! 'System.Void Foundation.NSAttributedString::.ctor(Foundation.NSData,Foundation.NSDictionary,Foundation.NSDictionary&,Foundation.NSError&)' has a extraneous [NullAllowed] on parameter #1 # Initial result from new rule missing-null-allowed !missing-null-allowed! 'AppKit.INSPasteboardWriting AppKit.NSCollectionViewDelegate::PasteboardWriterForItem(AppKit.NSCollectionView,System.UIntPtr)' is missing an [NullAllowed] on return type diff --git a/tests/xtro-sharpie/api-annotations-dotnet/tvOS-UIKit.ignore b/tests/xtro-sharpie/api-annotations-dotnet/tvOS-UIKit.ignore index 9c383206fc96..b885df600efe 100644 --- a/tests/xtro-sharpie/api-annotations-dotnet/tvOS-UIKit.ignore +++ b/tests/xtro-sharpie/api-annotations-dotnet/tvOS-UIKit.ignore @@ -101,7 +101,6 @@ !extra-null-allowed! 'System.Boolean UIKit.NSLayoutManagerDelegate::ShouldSetLineFragmentRect(UIKit.NSLayoutManager,CoreGraphics.CGRect&,CoreGraphics.CGRect&,System.Runtime.InteropServices.NFloat&,UIKit.NSTextContainer,Foundation.NSRange)' has a extraneous [NullAllowed] on parameter #2 !extra-null-allowed! 'System.Boolean UIKit.NSLayoutManagerDelegate::ShouldSetLineFragmentRect(UIKit.NSLayoutManager,CoreGraphics.CGRect&,CoreGraphics.CGRect&,System.Runtime.InteropServices.NFloat&,UIKit.NSTextContainer,Foundation.NSRange)' has a extraneous [NullAllowed] on parameter #3 !extra-null-allowed! 'System.Boolean UIKit.UIApplication::CanOpenUrl(Foundation.NSUrl)' has a extraneous [NullAllowed] on parameter #0 -!extra-null-allowed! 'System.Void Foundation.NSAttributedString::.ctor(Foundation.NSData,Foundation.NSDictionary,Foundation.NSDictionary&,Foundation.NSError&)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIAccessibilityCustomAction::.ctor(Foundation.NSAttributedString,UIKit.UIAccessibilityCustomActionHandler)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIAccessibilityCustomAction::.ctor(System.String,UIKit.UIAccessibilityCustomActionHandler)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIAccessibilityCustomAction::set_Name(System.String)' has a extraneous [NullAllowed] on parameter #0 diff --git a/tests/xtro-sharpie/iOS-UIKit.ignore b/tests/xtro-sharpie/iOS-UIKit.ignore index 4384d9d7fa8c..474decaf3685 100644 --- a/tests/xtro-sharpie/iOS-UIKit.ignore +++ b/tests/xtro-sharpie/iOS-UIKit.ignore @@ -82,7 +82,6 @@ !extra-null-allowed! 'System.Boolean UIKit.NSLayoutManagerDelegate::ShouldSetLineFragmentRect(UIKit.NSLayoutManager,CoreGraphics.CGRect&,CoreGraphics.CGRect&,System.nfloat&,UIKit.NSTextContainer,Foundation.NSRange)' has a extraneous [NullAllowed] on parameter #2 !extra-null-allowed! 'System.Boolean UIKit.NSLayoutManagerDelegate::ShouldSetLineFragmentRect(UIKit.NSLayoutManager,CoreGraphics.CGRect&,CoreGraphics.CGRect&,System.nfloat&,UIKit.NSTextContainer,Foundation.NSRange)' has a extraneous [NullAllowed] on parameter #3 !extra-null-allowed! 'System.Boolean UIKit.UIApplication::CanOpenUrl(Foundation.NSUrl)' has a extraneous [NullAllowed] on parameter #0 -!extra-null-allowed! 'System.Void Foundation.NSAttributedString::.ctor(Foundation.NSData,Foundation.NSDictionary,Foundation.NSDictionary&,Foundation.NSError&)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIAccessibilityCustomAction::.ctor(Foundation.NSAttributedString,UIKit.UIAccessibilityCustomActionHandler)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIAccessibilityCustomAction::.ctor(System.String,UIKit.UIAccessibilityCustomActionHandler)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIAccessibilityCustomAction::set_Name(System.String)' has a extraneous [NullAllowed] on parameter #0 diff --git a/tests/xtro-sharpie/macOS-AppKit.ignore b/tests/xtro-sharpie/macOS-AppKit.ignore index 256a36fd644b..935118949519 100644 --- a/tests/xtro-sharpie/macOS-AppKit.ignore +++ b/tests/xtro-sharpie/macOS-AppKit.ignore @@ -367,7 +367,6 @@ !extra-null-allowed! 'System.Void AppKit.NSView::set_ContentFilters(CoreImage.CIFilter[])' has a extraneous [NullAllowed] on parameter #0 !extra-null-allowed! 'System.Void AppKit.NSView::WillRemoveSubview(AppKit.NSView)' has a extraneous [NullAllowed] on parameter #0 !extra-null-allowed! 'System.Void Foundation.NSAttributedString::.ctor(Foundation.NSData,Foundation.NSDictionary,Foundation.NSDictionary&)' has a extraneous [NullAllowed] on parameter #1 -!extra-null-allowed! 'System.Void Foundation.NSAttributedString::.ctor(Foundation.NSData,Foundation.NSDictionary,Foundation.NSDictionary&,Foundation.NSError&)' has a extraneous [NullAllowed] on parameter #1 # Initial result from new rule missing-null-allowed !missing-null-allowed! 'AppKit.INSPasteboardWriting AppKit.NSCollectionViewDelegate::PasteboardWriterForItem(AppKit.NSCollectionView,System.nuint)' is missing an [NullAllowed] on return type diff --git a/tests/xtro-sharpie/tvOS-UIKit.ignore b/tests/xtro-sharpie/tvOS-UIKit.ignore index b483119ed90e..b91dbdec1925 100644 --- a/tests/xtro-sharpie/tvOS-UIKit.ignore +++ b/tests/xtro-sharpie/tvOS-UIKit.ignore @@ -113,7 +113,6 @@ !extra-null-allowed! 'System.Boolean UIKit.NSLayoutManagerDelegate::ShouldSetLineFragmentRect(UIKit.NSLayoutManager,CoreGraphics.CGRect&,CoreGraphics.CGRect&,System.nfloat&,UIKit.NSTextContainer,Foundation.NSRange)' has a extraneous [NullAllowed] on parameter #2 !extra-null-allowed! 'System.Boolean UIKit.NSLayoutManagerDelegate::ShouldSetLineFragmentRect(UIKit.NSLayoutManager,CoreGraphics.CGRect&,CoreGraphics.CGRect&,System.nfloat&,UIKit.NSTextContainer,Foundation.NSRange)' has a extraneous [NullAllowed] on parameter #3 !extra-null-allowed! 'System.Boolean UIKit.UIApplication::CanOpenUrl(Foundation.NSUrl)' has a extraneous [NullAllowed] on parameter #0 -!extra-null-allowed! 'System.Void Foundation.NSAttributedString::.ctor(Foundation.NSData,Foundation.NSDictionary,Foundation.NSDictionary&,Foundation.NSError&)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIAccessibilityCustomAction::.ctor(Foundation.NSAttributedString,UIKit.UIAccessibilityCustomActionHandler)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIAccessibilityCustomAction::.ctor(System.String,UIKit.UIAccessibilityCustomActionHandler)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIAccessibilityCustomAction::set_Name(System.String)' has a extraneous [NullAllowed] on parameter #0 diff --git a/tests/xtro-sharpie/watchOS-UIKit.ignore b/tests/xtro-sharpie/watchOS-UIKit.ignore index d9d593c07400..e40de500d40d 100644 --- a/tests/xtro-sharpie/watchOS-UIKit.ignore +++ b/tests/xtro-sharpie/watchOS-UIKit.ignore @@ -25,7 +25,6 @@ !missing-pinvoke! UIImageSymbolWeightForFontWeight is not bound # Initial result from new rule extra-null-allowed -!extra-null-allowed! 'System.Void Foundation.NSAttributedString::.ctor(Foundation.NSData,Foundation.NSDictionary,Foundation.NSDictionary&,Foundation.NSError&)' has a extraneous [NullAllowed] on parameter #1 !extra-null-allowed! 'System.Void UIKit.UIBezierPath::set_CGPath(CoreGraphics.CGPath)' has a extraneous [NullAllowed] on parameter #0 # Initial result from new rule missing-null-allowed