diff --git a/src/ObjCBindings/ExportAttribute.cs b/src/ObjCBindings/ExportAttribute.cs index 3fe280d781f3..ce41262f5a06 100644 --- a/src/ObjCBindings/ExportAttribute.cs +++ b/src/ObjCBindings/ExportAttribute.cs @@ -54,7 +54,7 @@ public class ExportAttribute : Attribute where T : Enum { /// /// The type of the result for an async method. /// - public TypeInfo? ResultType { get; set; } = null; + public Type? ResultType { get; set; } = null; /// /// The name of the generated async method. @@ -71,6 +71,16 @@ public class ExportAttribute : Attribute where T : Enum { /// public string? PostNonResultSnippet { get; set; } = null; + /// + /// The type of the strong delegate for a weak delegate property. + /// + public Type? StrongDelegateType { get; set; } = null; + + /// + /// The name of the strong delegate for a weak delegate property. + /// + public string? StrongDelegateName { get; set; } = null; + protected ExportAttribute () { } /// diff --git a/src/arkit.cs b/src/arkit.cs index 21682d72cf59..a35eaefd3cbc 100644 --- a/src/arkit.cs +++ b/src/arkit.cs @@ -7,6 +7,8 @@ // Copyright 2017 Microsoft Inc. All rights reserved. // +#nullable enable + using System; using System.ComponentModel; using System.Numerics; @@ -724,7 +726,7 @@ interface ARReferenceImage : NSCopying { [iOS (13, 0)] [Async] [Export ("validateWithCompletionHandler:")] - void Validate (Action completionHandler); + void Validate (Action completionHandler); /// To be added. /// To be added. @@ -1010,7 +1012,7 @@ interface ARSession { To be added. """)] [Export ("getCurrentWorldMapWithCompletionHandler:")] - void GetCurrentWorldMap (Action completionHandler); + void GetCurrentWorldMap (Action completionHandler); [Async (XmlDocs = """ The transform to the position and orientation of the region from which to create a reference object. @@ -1022,7 +1024,7 @@ interface ARSession { """)] [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] [Export ("createReferenceObjectWithTransform:center:extent:completionHandler:")] - void CreateReferenceObject (Matrix4 transform, Vector3 center, Vector3 extent, Action completionHandler); + void CreateReferenceObject (Matrix4 transform, Vector3 center, Vector3 extent, Action completionHandler); [iOS (13, 0)] [Export ("raycast:")] @@ -1047,7 +1049,7 @@ interface ARSession { [iOS (16, 0)] [Async] [Export ("captureHighResolutionFrameWithCompletion:")] - void CaptureHighResolutionFrame (Action handler); + void CaptureHighResolutionFrame (Action handler); } /// Interface defining methods that respond to events in an . @@ -2696,12 +2698,12 @@ interface ARGeoTrackingConfiguration { [Async] [Static] [Export ("checkAvailabilityWithCompletionHandler:")] - void CheckAvailability (Action completionHandler); + void CheckAvailability (Action completionHandler); [Async] [Static] [Export ("checkAvailabilityAtCoordinate:completionHandler:")] - void CheckAvailability (CLLocationCoordinate2D coordinate, Action completionHandler); + void CheckAvailability (CLLocationCoordinate2D coordinate, Action completionHandler); [Static] [Export ("new")] diff --git a/src/rgen/Microsoft.Macios.Bindings.Analyzer/Microsoft.Macios.Bindings.Analyzer.csproj b/src/rgen/Microsoft.Macios.Bindings.Analyzer/Microsoft.Macios.Bindings.Analyzer.csproj index f91c463fbb5e..5dcff18b4fc4 100644 --- a/src/rgen/Microsoft.Macios.Bindings.Analyzer/Microsoft.Macios.Bindings.Analyzer.csproj +++ b/src/rgen/Microsoft.Macios.Bindings.Analyzer/Microsoft.Macios.Bindings.Analyzer.csproj @@ -18,12 +18,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/src/rgen/Microsoft.Macios.Bindings.CodeFixers/Microsoft.Macios.Bindings.CodeFixers.csproj b/src/rgen/Microsoft.Macios.Bindings.CodeFixers/Microsoft.Macios.Bindings.CodeFixers.csproj index 083846f42783..5ba887a19649 100644 --- a/src/rgen/Microsoft.Macios.Bindings.CodeFixers/Microsoft.Macios.Bindings.CodeFixers.csproj +++ b/src/rgen/Microsoft.Macios.Bindings.CodeFixers/Microsoft.Macios.Bindings.CodeFixers.csproj @@ -15,12 +15,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/src/rgen/Microsoft.Macios.Generator/Attributes/ExportData.cs b/src/rgen/Microsoft.Macios.Generator/Attributes/ExportData.cs index 6fb418148e4a..1f3d56af57fc 100644 --- a/src/rgen/Microsoft.Macios.Generator/Attributes/ExportData.cs +++ b/src/rgen/Microsoft.Macios.Generator/Attributes/ExportData.cs @@ -75,6 +75,16 @@ namespace Microsoft.Macios.Generator.Attributes; /// public string? PostNonResultSnippet { get; init; } + /// + /// The type of the strong delegate for a weak delegate property. + /// + public TypeInfo? StrongDelegateType { get; init; } + + /// + /// The name of the strong delegate for a weak delegate property. + /// + public string? StrongDelegateName { get; init; } + public ExportData () { } public ExportData (string? selector) @@ -119,6 +129,9 @@ public static bool TryParse (AttributeData attributeData, string? methodName = null; string? resultTypeName = null; string? postNonResultSnippet = null; + // weak delegate related data + TypeInfo? strongDelegateType = null; + string? strongDelegateName = null; switch (count) { case 1: @@ -163,6 +176,7 @@ public static bool TryParse (AttributeData attributeData, // from this point we have to check the name of the argument AND if the export method is an Async method. var isAsync = typeof (T) == typeof (ObjCBindings.Method) && flags is not null && flags.HasFlag (ObjCBindings.Method.Async); + var isWeakDelegate = typeof (T) == typeof (ObjCBindings.Property) && flags is not null && flags.HasFlag (ObjCBindings.Property.WeakDelegate); // loop over all the named arguments and set the data accordingly, ignore the Flags one since we already set it foreach (var (name, value) in attrsDict) { @@ -206,6 +220,17 @@ public static bool TryParse (AttributeData attributeData, postNonResultSnippet = (string?) value; } break; + // weak delegate related data + case "StrongDelegateType": + if (isWeakDelegate) { + strongDelegateType = new ((INamedTypeSymbol) value!); + } + break; + case "StrongDelegateName": + if (isWeakDelegate) { + strongDelegateName = (string?) value!; + } + break; default: data = null; return false; @@ -221,7 +246,10 @@ public static bool TryParse (AttributeData attributeData, ResultType = isAsync ? resultType : null, MethodName = isAsync ? methodName : null, ResultTypeName = isAsync ? resultTypeName : null, - PostNonResultSnippet = isAsync ? postNonResultSnippet : null + PostNonResultSnippet = isAsync ? postNonResultSnippet : null, + // we set the data for the weak delegate only if the flags are set + StrongDelegateType = isWeakDelegate ? strongDelegateType : null, + StrongDelegateName = isWeakDelegate ? strongDelegateName : null }; return true; } diff --git a/src/rgen/Microsoft.Macios.Generator/DataModel/Property.Generator.cs b/src/rgen/Microsoft.Macios.Generator/DataModel/Property.Generator.cs index 15cbb20303be..2d8537845aec 100644 --- a/src/rgen/Microsoft.Macios.Generator/DataModel/Property.Generator.cs +++ b/src/rgen/Microsoft.Macios.Generator/DataModel/Property.Generator.cs @@ -266,6 +266,19 @@ public bool Equals (Property other) return RequiresDirtyCheck == other.RequiresDirtyCheck; } + public Property ToStrongDelegate () + { + // has to be a property, weak delegate and have its strong delegate type set + if (!IsProperty || !IsWeakDelegate || ExportPropertyData.Value.StrongDelegateType is null) + return this; + + // update the return type, all the rest is the same + return this with { + Name = ExportPropertyData.Value.StrongDelegateName ?? Name.Remove (0, 4 /* "Weak".Length */), + ReturnType = ExportPropertyData.Value.StrongDelegateType.Value.WithNullable (true), + }; + } + /// public override string ToString () { diff --git a/src/rgen/Microsoft.Macios.Generator/DataModel/Property.cs b/src/rgen/Microsoft.Macios.Generator/DataModel/Property.cs index 015d97317fe1..813565da9f87 100644 --- a/src/rgen/Microsoft.Macios.Generator/DataModel/Property.cs +++ b/src/rgen/Microsoft.Macios.Generator/DataModel/Property.cs @@ -18,7 +18,7 @@ namespace Microsoft.Macios.Generator.DataModel; /// /// Name of the property. /// - public string Name { get; } = string.Empty; + public string Name { get; init; } = string.Empty; readonly string? backingField = null; diff --git a/src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.cs b/src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.cs index b158a7d597f7..c1073c876524 100644 --- a/src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.cs +++ b/src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.cs @@ -556,20 +556,19 @@ public TypeInfo ToArrayElementType () } /// - /// If the current is nullable, this method returns a new - /// representing the non-nullable version of the type. Otherwise, it returns the current instance. + /// Returns a new with the specified nullability. /// + /// A boolean value indicating whether the new type should be nullable. /// - /// A new instance with set to false if the original was true; - /// otherwise, returns the current instance. + /// A new instance with the specified nullability. If the current instance already has the + /// specified nullability, the current instance is returned. /// - public TypeInfo ToNonNullable () + public TypeInfo WithNullable (bool isNullable) { - if (!IsNullable) + if (IsNullable == isNullable) return this; - // copy all the elements from the current array type and set the array type to false return this with { - IsNullable = false, + IsNullable = isNullable, }; } diff --git a/src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.ObjCRuntime.cs b/src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.ObjCRuntime.cs index 596102b3d0f4..baa37115dab9 100644 --- a/src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.ObjCRuntime.cs +++ b/src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.ObjCRuntime.cs @@ -1229,12 +1229,12 @@ internal static SyntaxNode ThrowIfNull (string variableName) // NSObject[] => CFArray.ArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, Selector.GetHandle ("results")))!; { Type.IsArray: true, Type.ArrayElementTypeIsWrapped: true } - => GetCFArrayFromHandle (info.Type.ToArrayElementType ().ToNonNullable ().GetIdentifierSyntax (), [ + => GetCFArrayFromHandle (info.Type.ToArrayElementType ().WithNullable (isNullable: false).GetIdentifierSyntax (), [ Argument (expression) ], suppressNullableWarning: !info.Type.IsNullable), { Type.IsArray: true, Type.ArrayElementIsINativeObject: true } - => GetCFArrayFromHandle (info.Type.ToArrayElementType ().ToNonNullable ().GetIdentifierSyntax (), [ + => GetCFArrayFromHandle (info.Type.ToArrayElementType ().WithNullable (isNullable: false).GetIdentifierSyntax (), [ Argument (expression) ], suppressNullableWarning: !info.Type.IsNullable), @@ -1244,7 +1244,7 @@ internal static SyntaxNode ThrowIfNull (string variableName) // Runtime.GetINativeObject (auxVariable, false)!; { Type.IsINativeObject: true, Type.IsNSObject: false, ReleaseHandle: not null} => GetINativeObject ( - nsObjectType: info.Type.ToNonNullable ().GetIdentifierSyntax (), + nsObjectType: info.Type.WithNullable (isNullable: false).GetIdentifierSyntax (), args: [ Argument (expression), BoolArgument (info.ReleaseHandle.Value) @@ -1253,7 +1253,7 @@ internal static SyntaxNode ThrowIfNull (string variableName) { Type.IsINativeObject: true, Type.IsNSObject: false, ReleaseHandle: null} => GetINativeObject ( - nsObjectType: info.Type.ToNonNullable ().GetIdentifierSyntax (), + nsObjectType: info.Type.WithNullable (isNullable: false).GetIdentifierSyntax (), args: [ Argument (expression), ], @@ -1263,7 +1263,7 @@ internal static SyntaxNode ThrowIfNull (string variableName) // Runtime.GetNSObject (auxVariable, false)!; { Type.IsNSObject: true, ReleaseHandle: not null} => GetNSObject ( - nsObjectType: info.Type.ToNonNullable ().GetIdentifierSyntax (), + nsObjectType: info.Type.WithNullable (isNullable: false).GetIdentifierSyntax (), args: [ Argument (expression), BoolArgument (false) @@ -1272,7 +1272,7 @@ internal static SyntaxNode ThrowIfNull (string variableName) { Type.IsNSObject: true, ReleaseHandle: null} => GetNSObject ( - nsObjectType: info.Type.ToNonNullable ().GetIdentifierSyntax (), + nsObjectType: info.Type.WithNullable (isNullable: false).GetIdentifierSyntax (), args: [ Argument (expression), ], diff --git a/src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.Trampoline.cs b/src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.Trampoline.cs index 670c25156a5e..01af4351efa9 100644 --- a/src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.Trampoline.cs +++ b/src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.Trampoline.cs @@ -208,7 +208,7 @@ internal static (SyntaxToken ParameterName, TypeSyntax ParameterType) GetTrampol // parameters that are passed by reference, depend on the type that is referenced { IsByRef: true, Type.IsReferenceType: false, Type.IsNullable: true} => (parameterIdentifier, - PointerType (GetLowLevelType (parameterType.ToNonNullable ()))), + PointerType (GetLowLevelType (parameterType.WithNullable (isNullable: false)))), { IsByRef: true, Type.IsReferenceType: false, Type.IsNullable: false} => (parameterIdentifier, @@ -333,7 +333,7 @@ internal static ArgumentSyntax GetTrampolineInvokeArgument (string trampolineNam // Runtime.GetNSObject (ParameterName) { Type.IsNSObject: true, Type.IsNullable: true} => - GetNSObject (parameterType.ToNonNullable ().GetIdentifierSyntax (), [ + GetNSObject (parameterType.WithNullable (isNullable: false).GetIdentifierSyntax (), [ Argument (parameterIdentifier) ], suppressNullableWarning: false), @@ -345,7 +345,7 @@ internal static ArgumentSyntax GetTrampolineInvokeArgument (string trampolineNam // Runtime.GetINativeObject (ParameterName, false)! { Type.IsINativeObject: true, Type.IsNullable: true } => - GetINativeObject (parameterType.ToNonNullable ().GetIdentifierSyntax (), [ + GetINativeObject (parameterType.WithNullable (isNullable: false).GetIdentifierSyntax (), [ Argument (parameterIdentifier), BoolArgument (false) ], suppressNullableWarning: false), diff --git a/src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.cs b/src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.cs index a267fdc485d7..59642c107699 100644 --- a/src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.cs +++ b/src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.cs @@ -68,6 +68,37 @@ static ExpressionSyntax StaticInvocationGenericExpression (ExpressionSyntax stat : invocation; } + /// + /// Creates an invocation expression for calling a method on an instance variable. + /// + /// The name of the instance variable. + /// The name of the method to call. + /// The arguments to pass to the method. + /// An invocation expression for the method call. + static InvocationExpressionSyntax MemberInvocationExpression (TypeSyntax instanceVariable, string methodName, + ImmutableArray arguments) + { + var argumentList = ArgumentList ( + SeparatedList (arguments.ToSyntaxNodeOrTokenArray ())); + return InvocationExpression ( + MemberAccessExpression ( + SyntaxKind.SimpleMemberAccessExpression, + instanceVariable, + IdentifierName (methodName).WithTrailingTrivia (Space))) + .WithArgumentList (argumentList); + } + + /// + /// Creates an invocation expression for calling a method on an instance variable. + /// + /// The name of the instance variable. + /// The name of the method to call. + /// The arguments to pass to the method. + /// An invocation expression for the method call. + static InvocationExpressionSyntax MemberInvocationExpression (string instanceVariable, string methodName, + ImmutableArray arguments) + => MemberInvocationExpression (IdentifierName (instanceVariable), methodName, arguments); + static ExpressionSyntax ThrowException (string type, string? message = null) { var throwExpression = ObjectCreationExpression (IdentifierName (type)); @@ -296,4 +327,25 @@ internal static ArgumentSyntax ArgumentForParameter (in Parameter parameter) /// An representing the parameter. internal static ArgumentSyntax ArgumentForParameter (in DelegateParameter parameter) => ArgumentForParameter (parameter.Name, parameter.ReferenceKind); + + /// + /// Creates an invocation expression for the SetException method of a TaskCompletionSource. + /// + /// The name of the TaskCompletionSource variable. + /// The arguments to pass to the SetException method. + /// An invocation expression for the SetException method. + internal static InvocationExpressionSyntax TcsSetException (string tcsVariableName, + ImmutableArray arguments) + => MemberInvocationExpression (tcsVariableName, "SetException", arguments); + + /// + /// Creates an invocation expression for the SetResult method of a TaskCompletionSource. + /// + /// The name of the TaskCompletionSource variable. + /// The arguments to pass to the SetResult method. + /// An invocation expression for the SetResult method. + internal static InvocationExpressionSyntax TcsSetResult (string tcsVariableName, + ImmutableArray arguments) + => MemberInvocationExpression (tcsVariableName, "SetResult", arguments); + } diff --git a/src/rgen/Microsoft.Macios.Generator/Emitters/ClassEmitter.cs b/src/rgen/Microsoft.Macios.Generator/Emitters/ClassEmitter.cs index 5a6d2056240e..3d6fb012c91d 100644 --- a/src/rgen/Microsoft.Macios.Generator/Emitters/ClassEmitter.cs +++ b/src/rgen/Microsoft.Macios.Generator/Emitters/ClassEmitter.cs @@ -259,6 +259,33 @@ void EmitProperties (in BindingContext context, TabbedWriter class } } } + + // if the property is a weak delegate and has the strong delegate type set, we need to emit the + // strong delegate property + if (property is { IsProperty: true, IsWeakDelegate: true } + && property.ExportPropertyData.Value.StrongDelegateType is not null) { + classBlock.WriteLine (); + var strongDelegate = property.ToStrongDelegate (); + using (var propertyBlock = + classBlock.CreateBlock (strongDelegate.ToDeclaration ().ToString (), block: true)) { + using (var getterBlock = + propertyBlock.CreateBlock ("get", block: true)) { + getterBlock.WriteLine ( + $"return {property.Name} as {strongDelegate.ReturnType.WithNullable (isNullable: false).GetIdentifierSyntax ()};"); + } + + using (var setterBlock = + propertyBlock.CreateBlock ("set", block: true)) { + setterBlock.WriteRaw ( +$@"var rvalue = value as NSObject; +if (!(value is null) && rvalue is null) {{ + throw new ArgumentException ($""The object passed of type {{value.GetType ()}} does not derive from NSObject""); +}} +{property.Name} = rvalue; +"); + } + } + } } } diff --git a/src/rgen/Microsoft.Macios.Generator/Microsoft.Macios.Generator.csproj b/src/rgen/Microsoft.Macios.Generator/Microsoft.Macios.Generator.csproj index d43293852e0b..75c79cfea9e0 100644 --- a/src/rgen/Microsoft.Macios.Generator/Microsoft.Macios.Generator.csproj +++ b/src/rgen/Microsoft.Macios.Generator/Microsoft.Macios.Generator.csproj @@ -18,11 +18,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/rgen/Microsoft.Macios.Transformer/Microsoft.Macios.Transformer.csproj b/src/rgen/Microsoft.Macios.Transformer/Microsoft.Macios.Transformer.csproj index 2b14f26d00d2..76100618877a 100644 --- a/src/rgen/Microsoft.Macios.Transformer/Microsoft.Macios.Transformer.csproj +++ b/src/rgen/Microsoft.Macios.Transformer/Microsoft.Macios.Transformer.csproj @@ -14,14 +14,14 @@ - - - - + + + + - - + + diff --git a/src/uikit.cs b/src/uikit.cs index f51e9a56d083..6735d353b800 100644 --- a/src/uikit.cs +++ b/src/uikit.cs @@ -445,7 +445,7 @@ public enum UISearchControllerScopeBarActivation : long { /// Completion handler used with . delegate void UIPrinterContactPrinterHandler (bool available); /// Completion handler used with various presentation methods. - delegate void UIPrinterPickerCompletionHandler (UIPrinterPickerController printerPickerController, bool userDidSelect, NSError error); + delegate void UIPrinterPickerCompletionHandler ([NullAllowed] UIPrinterPickerController printerPickerController, bool userDidSelect, [NullAllowed] NSError error); delegate UISplitViewControllerDisplayMode UISplitViewControllerFetchTargetForActionHandler (UISplitViewController svc); delegate bool UISplitViewControllerDisplayEvent (UISplitViewController splitViewController, UIViewController vc, NSObject sender); @@ -453,7 +453,7 @@ public enum UISearchControllerScopeBarActivation : long { delegate bool UISplitViewControllerCanCollapsePredicate (UISplitViewController splitViewController, UIViewController secondaryViewController, UIViewController primaryViewController); delegate UIViewController UISplitViewControllerGetSecondaryViewController (UISplitViewController splitViewController, UIViewController primaryViewController); /// The callback executed after a is dismissed. - delegate void UIActivityViewControllerCompletion (NSString activityType, bool completed, NSExtensionItem [] returnedItems, NSError error); + delegate void UIActivityViewControllerCompletion ([NullAllowed] NSString activityType, bool completed, [NullAllowed] NSExtensionItem [] returnedItems, [NullAllowed] NSError error); // In the hopes that the parameter is self document: this array can contain either UIDocuments or UIResponders /// To be added. @@ -1703,6 +1703,7 @@ partial interface UIAccessibilityCustomAction { NSString CategoryEdit { get; } } + [return: NullAllowed] delegate UIAccessibilityCustomRotorItemResult UIAccessibilityCustomRotorSearch (UIAccessibilityCustomRotorSearchPredicate predicate); [MacCatalyst (13, 1)] @@ -4494,7 +4495,9 @@ public enum UITextSearchMatchMethod : long { FullWord, } + [return: NullAllowed] delegate UIViewController UIContextMenuContentPreviewProvider (); + [return: NullAllowed] delegate UIMenu UIContextMenuActionProvider (UIMenuElement [] suggestedActions); [TV (17, 0), iOS (13, 0)] @@ -12193,6 +12196,7 @@ interface UIBezierPath : NSSecureCoding, NSCopying { [NoTV, iOS (13, 4)] [MacCatalyst (13, 1)] + [return: NullAllowed] delegate UIPointerStyle UIButtonPointerStyleProvider (UIButton button, UIPointerEffect proposedEffect, UIPointerShape proposedShape); [NoTV, iOS (15, 0), MacCatalyst (15, 0)] @@ -25336,6 +25340,7 @@ interface UIStepper { [iOS (13, 0), TV (13, 0)] [MacCatalyst (13, 1)] + [return: NullAllowed] delegate UIViewController UIStoryboardViewControllerCreator (NSCoder coder); [MacCatalyst (13, 1)] @@ -26270,7 +26275,7 @@ interface UIPrintInteractionControllerDelegate { } /// A delegate executed after printing completes or after a printing error occurs. - delegate void UIPrintInteractionCompletionHandler (UIPrintInteractionController printInteractionController, bool completed, NSError error); + delegate void UIPrintInteractionCompletionHandler ([NullAllowed] UIPrintInteractionController printInteractionController, bool completed, [NullAllowed] NSError error); /// [NoTV] @@ -31250,6 +31255,7 @@ interface UICollectionViewCompositionalLayoutConfiguration : NSCopying { [TV (13, 0), iOS (13, 0)] [MacCatalyst (13, 1)] + [return: NullAllowed] delegate NSCollectionLayoutSection UICollectionViewCompositionalLayoutSectionProvider (nint section, INSCollectionLayoutEnvironment layoutEnvironment); [TV (13, 0), iOS (13, 0)] @@ -31665,7 +31671,7 @@ interface UIScreenshotService { [iOS (13, 0), TV (13, 0)] [MacCatalyst (13, 1)] - delegate NSDictionary UIScreenshotServiceDelegatePdfHandler (NSData pdfData, nint indexOfCurrentPage, CGRect rectInCurrentPage); + delegate NSDictionary UIScreenshotServiceDelegatePdfHandler ([NullAllowed] NSData pdfData, nint indexOfCurrentPage, CGRect rectInCurrentPage); interface IUIScreenshotServiceDelegate { } @@ -32120,10 +32126,12 @@ interface UITabBarItemAppearance : NSCopying, NSSecureCoding { [TV (13, 0), iOS (13, 0)] [MacCatalyst (13, 1)] + [return: NullAllowed] delegate UICollectionViewCell UICollectionViewDiffableDataSourceCellProvider (UICollectionView collectionView, NSIndexPath indexPath, NSObject itemIdentifier); [TV (13, 0), iOS (13, 0)] [MacCatalyst (13, 1)] + [return: NullAllowed] delegate UICollectionReusableView UICollectionViewDiffableDataSourceSupplementaryViewProvider (UICollectionView collectionView, string elementKind, NSIndexPath indexPath); [TV (13, 0), iOS (13, 0)] @@ -32204,6 +32212,7 @@ interface UICollectionViewDiffableDataSource /// [MacCatalyst (13, 1)] - delegate void VNRequestCompletionHandler (VNRequest request, NSError error); + delegate void VNRequestCompletionHandler (VNRequest request, [NullAllowed] NSError error); /// A subclass of that uses a Core ML model for processing. [MacCatalyst (13, 1)] diff --git a/src/webkit.cs b/src/webkit.cs index cc2899b828fc..57b7ba90ce29 100644 --- a/src/webkit.cs +++ b/src/webkit.cs @@ -7866,7 +7866,7 @@ interface WKWebExtensionWindow { void Close (WKWebExtensionContext context, WKWebExtensionWindowCallback completionHandler); } - delegate void WKWebExtensionControllerDataRecordCallback (WKWebExtensionDataRecord dataRecord); + delegate void WKWebExtensionControllerDataRecordCallback ([NullAllowed] WKWebExtensionDataRecord dataRecord); delegate void WKWebExtensionControllerDataRecordsCallback (WKWebExtensionDataRecord [] dataRecords); [Mac (15, 4), iOS (18, 4), MacCatalyst (18, 4), NoTV] diff --git a/src/xkit.cs b/src/xkit.cs index fe2fe27098a4..fcaf0ed7b446 100644 --- a/src/xkit.cs +++ b/src/xkit.cs @@ -3842,7 +3842,7 @@ interface INSTextLayoutManagerDelegate { } delegate bool NSTextLayoutManagerEnumerateRenderingAttributesDelegate (NSTextLayoutManager textLayoutManager, NSDictionary attributes, NSTextRange textRange); [TV (15, 0), iOS (15, 0), MacCatalyst (15, 0)] - delegate bool NSTextLayoutManagerEnumerateTextSegmentsDelegate (NSTextRange textSegmentRange, CGRect textSegmentFrame, nfloat baselinePosition, NSTextContainer textContainer); + delegate bool NSTextLayoutManagerEnumerateTextSegmentsDelegate ([NullAllowed] NSTextRange textSegmentRange, CGRect textSegmentFrame, nfloat baselinePosition, NSTextContainer textContainer); [TV (15, 0), iOS (15, 0), MacCatalyst (15, 0)] [DesignatedDefaultCtor] @@ -4409,7 +4409,7 @@ interface NSTextSelection : NSSecureCoding { } [TV (15, 0), iOS (15, 0), MacCatalyst (15, 0)] - delegate void NSTextSelectionDataSourceEnumerateSubstringsDelegate (NSString substring, NSTextRange substringRange, NSTextRange enclodingRange, out bool stop); + delegate void NSTextSelectionDataSourceEnumerateSubstringsDelegate ([NullAllowed] NSString substring, NSTextRange substringRange, [NullAllowed] NSTextRange enclodingRange, out bool stop); [TV (15, 0), iOS (15, 0), MacCatalyst (15, 0)] delegate void NSTextSelectionDataSourceEnumerateCaretOffsetsDelegate (nfloat caretOffset, INSTextLocation location, bool leadingEdge, out bool stop); diff --git a/tests/rgen/Microsoft.Macios.Bindings.Analyzer.Tests/Microsoft.Macios.Bindings.Analyzer.Tests.csproj b/tests/rgen/Microsoft.Macios.Bindings.Analyzer.Tests/Microsoft.Macios.Bindings.Analyzer.Tests.csproj index 16b50f5ee8f8..39f3d8e5eea5 100644 --- a/tests/rgen/Microsoft.Macios.Bindings.Analyzer.Tests/Microsoft.Macios.Bindings.Analyzer.Tests.csproj +++ b/tests/rgen/Microsoft.Macios.Bindings.Analyzer.Tests/Microsoft.Macios.Bindings.Analyzer.Tests.csproj @@ -10,9 +10,9 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/rgen/Microsoft.Macios.Bindings.CodeFixers.Tests/Microsoft.Macios.Bindings.CodeFixers.Tests.csproj b/tests/rgen/Microsoft.Macios.Bindings.CodeFixers.Tests/Microsoft.Macios.Bindings.CodeFixers.Tests.csproj index 1dac34ff1738..1b79a99e5c02 100644 --- a/tests/rgen/Microsoft.Macios.Bindings.CodeFixers.Tests/Microsoft.Macios.Bindings.CodeFixers.Tests.csproj +++ b/tests/rgen/Microsoft.Macios.Bindings.CodeFixers.Tests/Microsoft.Macios.Bindings.CodeFixers.Tests.csproj @@ -14,9 +14,9 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/BaseGeneratorTestClass.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/BaseGeneratorTestClass.cs index 82623be6d8dc..4878519cc1fc 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/BaseGeneratorTestClass.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/BaseGeneratorTestClass.cs @@ -105,6 +105,8 @@ protected void CompareGeneratedCode (GenerationTestData testData) // Run generators and retrieve all results. var runResult = RunGenerators (driver, compilation); + var errors = runResult.Diagnostics.Where (d => d.Severity == DiagnosticSeverity.Error); + Assert.Empty (errors); // All generated files can be found in 'RunResults.GeneratedTrees'. var generatedFileSyntax = runResult.GeneratedTrees.Where (t => t.FilePath.EndsWith ($"{testData.ClassName}.g.cs")).ToArray (); diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AVAudioPcmBufferDefaultCtr.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AVAudioPcmBufferDefaultCtr.cs index 15beb599a233..9a25a78c8cdd 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AVAudioPcmBufferDefaultCtr.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AVAudioPcmBufferDefaultCtr.cs @@ -1,3 +1,4 @@ +#pragma warning disable APL0003 using System; using Foundation; using ObjCBindings; diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AVAudioPcmBufferNoDefaultCtr.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AVAudioPcmBufferNoDefaultCtr.cs index 72956722d1ba..124d55ddf353 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AVAudioPcmBufferNoDefaultCtr.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AVAudioPcmBufferNoDefaultCtr.cs @@ -1,3 +1,4 @@ +#pragma warning disable APL0003 using System; using Foundation; using ObjCBindings; diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AVAudioPcmBufferNoNativeName.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AVAudioPcmBufferNoNativeName.cs index e015ac4c2ece..0bcc0bb9080d 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AVAudioPcmBufferNoNativeName.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AVAudioPcmBufferNoNativeName.cs @@ -1,3 +1,4 @@ +#pragma warning disable APL0003 using System; using Foundation; using ObjCBindings; diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AppKitPropertyTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AppKitPropertyTests.cs index f03d36057663..b66e465f8e23 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AppKitPropertyTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/AppKitPropertyTests.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#pragma warning disable APL0003 using System; using System.Runtime.Versioning; diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/CIImage.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/CIImage.cs index 8441ffd7d72c..d7e443904c13 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/CIImage.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/CIImage.cs @@ -1,3 +1,4 @@ +#pragma warning disable APL0003 using System; using System.Runtime.Versioning; using Foundation; diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/MethodTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/MethodTests.cs index dc3ff9a7a50c..9e07750e9b47 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/MethodTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/MethodTests.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#pragma warning disable APL0003 using System; using System.Runtime.Versioning; diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/NSUserDefaults.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/NSUserDefaults.cs index fe2138fdd5ac..0e4ebf76a331 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/NSUserDefaults.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/NSUserDefaults.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#pragma warning disable APL0003 using System; using System.Runtime.Versioning; diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/PropertyTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/PropertyTests.cs index 47b5474a829b..901200085a3c 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/PropertyTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/PropertyTests.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#pragma warning disable APL0003 using System; using System.Runtime.Versioning; @@ -12,7 +13,7 @@ namespace TestNamespace; -[BindingType] +[BindingType] public partial class PropertyTests { // the following are a list of examples of all possible property definitions @@ -62,7 +63,7 @@ public partial class PropertyTests { [SupportedOSPlatform ("tvos")] [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("maccatalyst13.1")] - public virtual partial string? Name { get; set; } + public virtual partial string? OtherName { get; set; } // array of strings [Export ("surnames")] @@ -70,7 +71,7 @@ public partial class PropertyTests { [SupportedOSPlatform ("tvos")] [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("maccatalyst13.1")] - public virtual partial string [] Name { get; set; } + public virtual partial string [] Names { get; set; } // simple NSObject [SupportedOSPlatform ("ios")] @@ -85,7 +86,10 @@ public partial class PropertyTests { [SupportedOSPlatform ("tvos")] [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("maccatalyst13.1")] - [Export ("delegate", ArgumentSemantic.Weak, Flags = Property.WeakDelegate)] + [Export ("delegate", + ArgumentSemantic.Weak, + Flags = Property.WeakDelegate, + StrongDelegateType = typeof (INSUserActivityDelegate))] public virtual partial NSObject? WeakDelegate { get; set; } // array nsobject @@ -144,16 +148,6 @@ public virtual partial bool IsLenient { set; } - // wrapper property example - [SupportedOSPlatform ("ios")] - [SupportedOSPlatform ("tvos")] - [SupportedOSPlatform ("macos")] - [SupportedOSPlatform ("maccatalyst13.1")] - public virtual INSMetadataQueryDelegate? Delegate { - get => WeakDelegate as INSMetadataQueryDelegate; - set => WeakDelegate = value; - } - // bindfrom [SupportedOSPlatform ("ios")] [SupportedOSPlatform ("tvos")] diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ThreadSafeAppKitPropertyTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ThreadSafeAppKitPropertyTests.cs index 60dd67b6d312..98867924449a 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ThreadSafeAppKitPropertyTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ThreadSafeAppKitPropertyTests.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#pragma warning disable APL0003 using System; using System.Runtime.Versioning; diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ThreadSafeUIKitPropertyTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ThreadSafeUIKitPropertyTests.cs index 3313a5496ebc..ce71e955e4d1 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ThreadSafeUIKitPropertyTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ThreadSafeUIKitPropertyTests.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#pragma warning disable APL0003 using System; using System.Runtime.Versioning; diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/TrampolinePropertyTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/TrampolinePropertyTests.cs index 8b25c0e2cf55..ebc3de0f0a39 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/TrampolinePropertyTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/TrampolinePropertyTests.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#pragma warning disable APL0003 namespace Microsoft.Macios.Generator.Tests.Classes.Data; diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/UIKitPropertyTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/UIKitPropertyTests.cs index 8661a28d9e51..78b19399db57 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/UIKitPropertyTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/UIKitPropertyTests.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#pragma warning disable APL0003 using System; using System.Runtime.Versioning; diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/iOSExpectedPropertyTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/iOSExpectedPropertyTests.cs index 0a0aedd948ed..4024ff21c381 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/iOSExpectedPropertyTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/iOSExpectedPropertyTests.cs @@ -734,7 +734,7 @@ public virtual partial string Name [SupportedOSPlatform ("tvos")] [SupportedOSPlatform ("maccatalyst13.1")] [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] - public virtual partial string? Name + public virtual partial string[] Names { [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("ios")] @@ -742,11 +742,11 @@ public virtual partial string? Name [SupportedOSPlatform ("maccatalyst13.1")] get { - string? ret; + string[] ret; if (IsDirectBinding) { - ret = global::CoreFoundation.CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("name")), false); + ret = global::CoreFoundation.CFArray.StringArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("surnames")), false)!; } else { - ret = global::CoreFoundation.CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("name")), false); + ret = global::CoreFoundation.CFArray.StringArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("surnames")), false)!; } global::System.GC.KeepAlive (this); return ret; @@ -758,14 +758,16 @@ public virtual partial string? Name [SupportedOSPlatform ("maccatalyst13.1")] set { - var nsvalue = global::CoreFoundation.CFString.CreateNative (value); + if (value is null) + global::ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value)); + using var nsa_value = global::Foundation.NSArray.FromStrings (value); if (IsDirectBinding) { - global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setName:"), nsvalue); + global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setSurnames:"), nsa_value); } else { - global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setName:"), nsvalue); + global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setSurnames:"), nsa_value); } global::System.GC.KeepAlive (this); - global::CoreFoundation.CFString.ReleaseNative (nsvalue); + global::System.GC.KeepAlive (nsa_value); } } @@ -774,7 +776,7 @@ public virtual partial string? Name [SupportedOSPlatform ("tvos")] [SupportedOSPlatform ("maccatalyst13.1")] [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] - public virtual partial string[] Name + public virtual partial string? OtherName { [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("ios")] @@ -782,11 +784,11 @@ public virtual partial string[] Name [SupportedOSPlatform ("maccatalyst13.1")] get { - string[] ret; + string? ret; if (IsDirectBinding) { - ret = global::CoreFoundation.CFArray.StringArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("surnames")), false)!; + ret = global::CoreFoundation.CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("name")), false); } else { - ret = global::CoreFoundation.CFArray.StringArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("surnames")), false)!; + ret = global::CoreFoundation.CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("name")), false); } global::System.GC.KeepAlive (this); return ret; @@ -798,16 +800,14 @@ public virtual partial string[] Name [SupportedOSPlatform ("maccatalyst13.1")] set { - if (value is null) - global::ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value)); - using var nsa_value = global::Foundation.NSArray.FromStrings (value); + var nsvalue = global::CoreFoundation.CFString.CreateNative (value); if (IsDirectBinding) { - global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setSurnames:"), nsa_value); + global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setName:"), nsvalue); } else { - global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setSurnames:"), nsa_value); + global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setName:"), nsvalue); } global::System.GC.KeepAlive (this); - global::System.GC.KeepAlive (nsa_value); + global::CoreFoundation.CFString.ReleaseNative (nsvalue); } } @@ -1025,5 +1025,21 @@ public virtual partial string[] Name __mt_WeakDelegate_var = value; } } + + public virtual partial global::Foundation.INSUserActivityDelegate? Delegate + { + get + { + return WeakDelegate as global::Foundation.INSUserActivityDelegate; + } + set + { + var rvalue = value as NSObject; + if (!(value is null) && rvalue is null) { + throw new ArgumentException ($"The object passed of type {value.GetType ()} does not derive from NSObject"); + } + WeakDelegate = rvalue; + } + } // TODO: add binding code here } diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/macOSExpectedPropertyTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/macOSExpectedPropertyTests.cs index 0a0aedd948ed..4024ff21c381 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/macOSExpectedPropertyTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/macOSExpectedPropertyTests.cs @@ -734,7 +734,7 @@ public virtual partial string Name [SupportedOSPlatform ("tvos")] [SupportedOSPlatform ("maccatalyst13.1")] [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] - public virtual partial string? Name + public virtual partial string[] Names { [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("ios")] @@ -742,11 +742,11 @@ public virtual partial string? Name [SupportedOSPlatform ("maccatalyst13.1")] get { - string? ret; + string[] ret; if (IsDirectBinding) { - ret = global::CoreFoundation.CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("name")), false); + ret = global::CoreFoundation.CFArray.StringArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("surnames")), false)!; } else { - ret = global::CoreFoundation.CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("name")), false); + ret = global::CoreFoundation.CFArray.StringArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("surnames")), false)!; } global::System.GC.KeepAlive (this); return ret; @@ -758,14 +758,16 @@ public virtual partial string? Name [SupportedOSPlatform ("maccatalyst13.1")] set { - var nsvalue = global::CoreFoundation.CFString.CreateNative (value); + if (value is null) + global::ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value)); + using var nsa_value = global::Foundation.NSArray.FromStrings (value); if (IsDirectBinding) { - global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setName:"), nsvalue); + global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setSurnames:"), nsa_value); } else { - global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setName:"), nsvalue); + global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setSurnames:"), nsa_value); } global::System.GC.KeepAlive (this); - global::CoreFoundation.CFString.ReleaseNative (nsvalue); + global::System.GC.KeepAlive (nsa_value); } } @@ -774,7 +776,7 @@ public virtual partial string? Name [SupportedOSPlatform ("tvos")] [SupportedOSPlatform ("maccatalyst13.1")] [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] - public virtual partial string[] Name + public virtual partial string? OtherName { [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("ios")] @@ -782,11 +784,11 @@ public virtual partial string[] Name [SupportedOSPlatform ("maccatalyst13.1")] get { - string[] ret; + string? ret; if (IsDirectBinding) { - ret = global::CoreFoundation.CFArray.StringArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("surnames")), false)!; + ret = global::CoreFoundation.CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("name")), false); } else { - ret = global::CoreFoundation.CFArray.StringArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("surnames")), false)!; + ret = global::CoreFoundation.CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("name")), false); } global::System.GC.KeepAlive (this); return ret; @@ -798,16 +800,14 @@ public virtual partial string[] Name [SupportedOSPlatform ("maccatalyst13.1")] set { - if (value is null) - global::ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value)); - using var nsa_value = global::Foundation.NSArray.FromStrings (value); + var nsvalue = global::CoreFoundation.CFString.CreateNative (value); if (IsDirectBinding) { - global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setSurnames:"), nsa_value); + global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setName:"), nsvalue); } else { - global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setSurnames:"), nsa_value); + global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setName:"), nsvalue); } global::System.GC.KeepAlive (this); - global::System.GC.KeepAlive (nsa_value); + global::CoreFoundation.CFString.ReleaseNative (nsvalue); } } @@ -1025,5 +1025,21 @@ public virtual partial string[] Name __mt_WeakDelegate_var = value; } } + + public virtual partial global::Foundation.INSUserActivityDelegate? Delegate + { + get + { + return WeakDelegate as global::Foundation.INSUserActivityDelegate; + } + set + { + var rvalue = value as NSObject; + if (!(value is null) && rvalue is null) { + throw new ArgumentException ($"The object passed of type {value.GetType ()} does not derive from NSObject"); + } + WeakDelegate = rvalue; + } + } // TODO: add binding code here } diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/tvOSExpectedPropertyTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/tvOSExpectedPropertyTests.cs index 0a0aedd948ed..4024ff21c381 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/tvOSExpectedPropertyTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/tvOSExpectedPropertyTests.cs @@ -734,7 +734,7 @@ public virtual partial string Name [SupportedOSPlatform ("tvos")] [SupportedOSPlatform ("maccatalyst13.1")] [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] - public virtual partial string? Name + public virtual partial string[] Names { [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("ios")] @@ -742,11 +742,11 @@ public virtual partial string? Name [SupportedOSPlatform ("maccatalyst13.1")] get { - string? ret; + string[] ret; if (IsDirectBinding) { - ret = global::CoreFoundation.CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("name")), false); + ret = global::CoreFoundation.CFArray.StringArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("surnames")), false)!; } else { - ret = global::CoreFoundation.CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("name")), false); + ret = global::CoreFoundation.CFArray.StringArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("surnames")), false)!; } global::System.GC.KeepAlive (this); return ret; @@ -758,14 +758,16 @@ public virtual partial string? Name [SupportedOSPlatform ("maccatalyst13.1")] set { - var nsvalue = global::CoreFoundation.CFString.CreateNative (value); + if (value is null) + global::ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value)); + using var nsa_value = global::Foundation.NSArray.FromStrings (value); if (IsDirectBinding) { - global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setName:"), nsvalue); + global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setSurnames:"), nsa_value); } else { - global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setName:"), nsvalue); + global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setSurnames:"), nsa_value); } global::System.GC.KeepAlive (this); - global::CoreFoundation.CFString.ReleaseNative (nsvalue); + global::System.GC.KeepAlive (nsa_value); } } @@ -774,7 +776,7 @@ public virtual partial string? Name [SupportedOSPlatform ("tvos")] [SupportedOSPlatform ("maccatalyst13.1")] [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)] - public virtual partial string[] Name + public virtual partial string? OtherName { [SupportedOSPlatform ("macos")] [SupportedOSPlatform ("ios")] @@ -782,11 +784,11 @@ public virtual partial string[] Name [SupportedOSPlatform ("maccatalyst13.1")] get { - string[] ret; + string? ret; if (IsDirectBinding) { - ret = global::CoreFoundation.CFArray.StringArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("surnames")), false)!; + ret = global::CoreFoundation.CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("name")), false); } else { - ret = global::CoreFoundation.CFArray.StringArrayFromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("surnames")), false)!; + ret = global::CoreFoundation.CFString.FromHandle (global::ObjCRuntime.Messaging.NativeHandle_objc_msgSendSuper (this.Handle, global::ObjCRuntime.Selector.GetHandle ("name")), false); } global::System.GC.KeepAlive (this); return ret; @@ -798,16 +800,14 @@ public virtual partial string[] Name [SupportedOSPlatform ("maccatalyst13.1")] set { - if (value is null) - global::ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value)); - using var nsa_value = global::Foundation.NSArray.FromStrings (value); + var nsvalue = global::CoreFoundation.CFString.CreateNative (value); if (IsDirectBinding) { - global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setSurnames:"), nsa_value); + global::ObjCRuntime.Messaging.void_objc_msgSend_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setName:"), nsvalue); } else { - global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setSurnames:"), nsa_value); + global::ObjCRuntime.Messaging.void_objc_msgSendSuper_NativeHandle (this.Handle, global::ObjCRuntime.Selector.GetHandle ("setName:"), nsvalue); } global::System.GC.KeepAlive (this); - global::System.GC.KeepAlive (nsa_value); + global::CoreFoundation.CFString.ReleaseNative (nsvalue); } } @@ -1025,5 +1025,21 @@ public virtual partial string[] Name __mt_WeakDelegate_var = value; } } + + public virtual partial global::Foundation.INSUserActivityDelegate? Delegate + { + get + { + return WeakDelegate as global::Foundation.INSUserActivityDelegate; + } + set + { + var rvalue = value as NSObject; + if (!(value is null) && rvalue is null) { + throw new ArgumentException ($"The object passed of type {value.GetType ()} does not derive from NSObject"); + } + WeakDelegate = rvalue; + } + } // TODO: add binding code here } diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/PropertyTests/GeneralPropertyTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/PropertyTests/GeneralPropertyTests.cs index f59a95f67313..b792a51823f3 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/PropertyTests/GeneralPropertyTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/PropertyTests/GeneralPropertyTests.cs @@ -467,4 +467,48 @@ public void IsWeakDelegate (ObjCBindings.Property flag, bool expectedResult) }; Assert.Equal (expectedResult, property.IsWeakDelegate); } + + [Theory] + [InlineData (true, true, true, true)] // isProperty, isWeakDelegate, hasStrongDelegateType, shouldChange + [InlineData (false, true, true, false)] + [InlineData (true, false, true, false)] + [InlineData (true, true, false, false)] + public void ToStrongDelegate (bool isProperty, bool isWeakDelegate, bool hasStrongDelegateType, bool shouldChange) + { + TypeInfo? strongDelegateType = hasStrongDelegateType ? ReturnTypeForNSObject ("StrongDelegate") : null; + var flags = isWeakDelegate ? ObjCBindings.Property.WeakDelegate : ObjCBindings.Property.Default; + var property = new Property ( + name: "Test", + returnType: ReturnTypeForNSObject (), + symbolAvailability: new (), + attributes: [], + modifiers: [], + accessors: [] + ); + + if (isProperty) { + property = property with { + ExportPropertyData = new ExportData ( + "name", + ArgumentSemantic.None, + flags + ) { + StrongDelegateType = strongDelegateType + }, + }; + } else { + property = property with { + ExportFieldData = new (new FieldData ("name", flags), ""), + }; + } + + var newProperty = property.ToStrongDelegate (); + + if (shouldChange) { + Assert.NotEqual (property, newProperty); + Assert.Equal (strongDelegateType!.Value.WithNullable (true), newProperty.ReturnType); + } else { + Assert.Equal (property, newProperty); + } + } } diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/BindingSyntaxFactoryRuntimeTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/BindingSyntaxFactoryRuntimeTests.cs index 98f0ddf146ff..aba439e93544 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/BindingSyntaxFactoryRuntimeTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/BindingSyntaxFactoryRuntimeTests.cs @@ -1005,4 +1005,64 @@ void ArgumentSyntaxForParameterTests (string argumentName, ReferenceKind referen Assert.Equal (expectedSyntax, argumentSyntax.ToFullString ()); } + class TestDataTcsSetExceptionTests : IEnumerable { + public IEnumerator GetEnumerator () + { + yield return [ + "tcs", + ImmutableArray.Create ( + Argument (IdentifierName ("ex"))), + "tcs.SetException (ex)" + ]; + + yield return [ + "myTcs", + ImmutableArray.Create ( + Argument (IdentifierName ("exception")), + Argument (IdentifierName ("additionalArg"))), + "myTcs.SetException (exception, additionalArg)" + ]; + } + + IEnumerator IEnumerable.GetEnumerator () => GetEnumerator (); + } + + [Theory] + [ClassData (typeof (TestDataTcsSetExceptionTests))] + void TcsSetExceptionTests (string tcsVariableName, ImmutableArray arguments, string expectedDeclaration) + { + var declaration = TcsSetException (tcsVariableName, arguments); + Assert.Equal (expectedDeclaration, declaration.ToFullString ()); + } + + class TestDataTcsSetResultTests : IEnumerable { + public IEnumerator GetEnumerator () + { + yield return [ + "tcs", + ImmutableArray.Create ( + Argument (IdentifierName ("result"))), + "tcs.SetResult (result)" + ]; + + yield return [ + "myTcs", + ImmutableArray.Create ( + Argument (IdentifierName ("value")), + Argument (IdentifierName ("additionalArg"))), + "myTcs.SetResult (value, additionalArg)" + ]; + } + + IEnumerator IEnumerable.GetEnumerator () => GetEnumerator (); + } + + [Theory] + [ClassData (typeof (TestDataTcsSetResultTests))] + void TcsSetResultTests (string tcsVariableName, ImmutableArray arguments, string expectedDeclaration) + { + var declaration = TcsSetResult (tcsVariableName, arguments); + Assert.Equal (expectedDeclaration, declaration.ToFullString ()); + } + } diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Extensions/TypeSymbolExtensionsTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Extensions/TypeSymbolExtensionsTests.cs index dc9f129e389b..9eda0317f7fb 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Extensions/TypeSymbolExtensionsTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Extensions/TypeSymbolExtensionsTests.cs @@ -204,7 +204,9 @@ public void GetParentTests (ApplePlatform platform, string inputText, var semanticModel = compilation.GetSemanticModel (syntaxTrees [0]); var declaration = getNode (syntaxTrees [0].GetRoot ()); Assert.NotNull (declaration); +#pragma warning disable RS1039 var symbol = semanticModel.GetDeclaredSymbol (declaration); +#pragma warning restore RS1039 Assert.NotNull (symbol); var parents = symbol.GetParents ().Select (p => p.Name).ToArray (); Assert.Equal (expectedParents, parents); diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Microsoft.Macios.Generator.Tests.csproj b/tests/rgen/Microsoft.Macios.Generator.Tests/Microsoft.Macios.Generator.Tests.csproj index 706ed2664fce..786c5cf6ec84 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Microsoft.Macios.Generator.Tests.csproj +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Microsoft.Macios.Generator.Tests.csproj @@ -15,12 +15,12 @@ - - + + - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/BindAsDataTests.cs b/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/BindAsDataTests.cs index 86b88aef4301..57dcbf82f4cb 100644 --- a/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/BindAsDataTests.cs +++ b/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/BindAsDataTests.cs @@ -123,7 +123,9 @@ void TryCreateTests (ApplePlatform platform, T _, (string Source, string Path Assert.NotNull (declaration); +#pragma warning disable RS1039 var symbol = semanticModel.GetDeclaredSymbol (declaration); +#pragma warning restore RS1039 Assert.NotNull (symbol); var attribute = symbol.GetAttribute (AttributesNames.BindAsAttribute, BindAsData.TryParse); Assert.NotNull (attribute); diff --git a/tests/rgen/Microsoft.Macios.Transformer.Tests/Microsoft.Macios.Transformer.Tests.csproj b/tests/rgen/Microsoft.Macios.Transformer.Tests/Microsoft.Macios.Transformer.Tests.csproj index efba1360375b..ce0397956fcc 100644 --- a/tests/rgen/Microsoft.Macios.Transformer.Tests/Microsoft.Macios.Transformer.Tests.csproj +++ b/tests/rgen/Microsoft.Macios.Transformer.Tests/Microsoft.Macios.Transformer.Tests.csproj @@ -20,11 +20,17 @@ - - - - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +