From cac27ddfc07984c8554dab39f053221cd674a6d1 Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Thu, 29 Feb 2024 22:23:19 +0100 Subject: [PATCH] Misc warning fixes (#14766) * Fix XML doc warnings * Fix nullability warnings * Fix misc warnings --- .../Avalonia.Android/AndroidRuntimePlatform.cs | 15 +++++++++------ .../Reflection/ReflectionIndexerNode.cs | 2 +- .../Data/Core/ExpressionParseException.cs | 3 +-- .../Data/Core/Parsers/BindingExpressionVisitor.cs | 2 +- .../Data/Core/UntypedBindingExpressionBase.cs | 3 +-- src/Avalonia.Base/Media/FormattedText.cs | 1 - .../Rendering/Composition/Compositor.cs | 2 +- .../Helpers/ColorPickerHelpers.cs | 1 + src/Avalonia.Controls/NativeMenuItem.cs | 8 +++++--- .../PullToRefresh/RefreshVisualizer.cs | 1 - .../AvaloniaXamlIlControlTemplatePartsChecker.cs | 4 +++- .../BindingExpressionTests.UpdateSourceTrigger.cs | 2 ++ .../DispatcherTests.Exception.cs | 2 +- .../Input/KeyboardNavigationTests_XY.cs | 10 +++++----- .../VirtualizingStackPanelTests.cs | 2 +- .../CompiledBindingExtensionTests.cs | 6 +++--- .../Media/RelativePointTestPrimitivesHelper.cs | 9 +++++---- 17 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/Android/Avalonia.Android/AndroidRuntimePlatform.cs b/src/Android/Avalonia.Android/AndroidRuntimePlatform.cs index f38492005ae..ed3b9b6ccbe 100644 --- a/src/Android/Avalonia.Android/AndroidRuntimePlatform.cs +++ b/src/Android/Avalonia.Android/AndroidRuntimePlatform.cs @@ -1,4 +1,6 @@ -using System; +#nullable enable + +using System; using Android.Content.PM; using Android.Content; using Avalonia.Platform; @@ -27,7 +29,7 @@ public static void Register(Assembly? assembly = null) internal class AndroidRuntimePlatform : StandardRuntimePlatform { - private static readonly Lazy Info = new(() => + private static readonly Lazy s_info = new(() => { var isDesktop = IsRunningOnDesktop(App.Context); var isTv = IsRunningOnTv(App.Context); @@ -41,12 +43,13 @@ internal class AndroidRuntimePlatform : StandardRuntimePlatform }); private static bool IsRunningOnDesktop(Context context) => - context.PackageManager.HasSystemFeature("org.chromium.arc") || - context.PackageManager.HasSystemFeature("org.chromium.arc.device_management"); + context.PackageManager is { } packageManager && + (packageManager.HasSystemFeature("org.chromium.arc") || + packageManager.HasSystemFeature("org.chromium.arc.device_management")); private static bool IsRunningOnTv(Context context) => - context.PackageManager.HasSystemFeature(PackageManager.FeatureLeanback); + context.PackageManager?.HasSystemFeature(PackageManager.FeatureLeanback) == true; - public override RuntimePlatformInfo GetRuntimeInfo() => Info.Value; + public override RuntimePlatformInfo GetRuntimeInfo() => s_info.Value; } } diff --git a/src/Avalonia.Base/Data/Core/ExpressionNodes/Reflection/ReflectionIndexerNode.cs b/src/Avalonia.Base/Data/Core/ExpressionNodes/Reflection/ReflectionIndexerNode.cs index 16b9cda490e..52526431dc5 100644 --- a/src/Avalonia.Base/Data/Core/ExpressionNodes/Reflection/ReflectionIndexerNode.cs +++ b/src/Avalonia.Base/Data/Core/ExpressionNodes/Reflection/ReflectionIndexerNode.cs @@ -15,7 +15,7 @@ namespace Avalonia.Data.Core.ExpressionNodes.Reflection; [RequiresUnreferencedCode(TrimmingMessages.ReflectionBindingRequiresUnreferencedCodeMessage)] internal sealed class ReflectionIndexerNode : CollectionNodeBase, ISettableNode { - private static readonly BindingFlags InstanceFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly; + private const BindingFlags InstanceFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly; private MethodInfo? _getter; private MethodInfo? _setter; private object?[]? _indexes; diff --git a/src/Avalonia.Base/Data/Core/ExpressionParseException.cs b/src/Avalonia.Base/Data/Core/ExpressionParseException.cs index a50e79f9cdd..39ebda18224 100644 --- a/src/Avalonia.Base/Data/Core/ExpressionParseException.cs +++ b/src/Avalonia.Base/Data/Core/ExpressionParseException.cs @@ -3,8 +3,7 @@ namespace Avalonia.Data.Core { /// - /// Exception thrown when could not parse the provided - /// expression string. + /// Exception thrown when the provided binding expression string could not be parsed. /// #if !BUILDTASK public diff --git a/src/Avalonia.Base/Data/Core/Parsers/BindingExpressionVisitor.cs b/src/Avalonia.Base/Data/Core/Parsers/BindingExpressionVisitor.cs index 9844ed5ce9e..4a507cdd927 100644 --- a/src/Avalonia.Base/Data/Core/Parsers/BindingExpressionVisitor.cs +++ b/src/Avalonia.Base/Data/Core/Parsers/BindingExpressionVisitor.cs @@ -15,7 +15,7 @@ internal class BindingExpressionVisitor : ExpressionVisitor { private static readonly PropertyInfo AvaloniaObjectIndexer; private static readonly MethodInfo CreateDelegateMethod; - private static readonly string IndexerGetterName = "get_Item"; + private const string IndexerGetterName = "get_Item"; private const string MultiDimensionalArrayGetterMethodName = "Get"; private readonly bool _enableDataValidation; private readonly LambdaExpression _rootExpression; diff --git a/src/Avalonia.Base/Data/Core/UntypedBindingExpressionBase.cs b/src/Avalonia.Base/Data/Core/UntypedBindingExpressionBase.cs index 5c7ea945993..fc0135b199e 100644 --- a/src/Avalonia.Base/Data/Core/UntypedBindingExpressionBase.cs +++ b/src/Avalonia.Base/Data/Core/UntypedBindingExpressionBase.cs @@ -140,8 +140,7 @@ public override void Dispose() } /// - /// Starts the binding expression following a call to - /// . + /// Starts the binding expression following a call to . /// public void Start() => Start(produceValue: true); diff --git a/src/Avalonia.Base/Media/FormattedText.cs b/src/Avalonia.Base/Media/FormattedText.cs index 2029cbf7cd9..c285ce2f511 100644 --- a/src/Avalonia.Base/Media/FormattedText.cs +++ b/src/Avalonia.Base/Media/FormattedText.cs @@ -51,7 +51,6 @@ public class FormattedText /// Type face used to display text. /// Font em size in visual units (1/96 of an inch). /// Foreground brush used to render text. - /// Optional list of turned on/off features. public FormattedText( string textToFormat, CultureInfo culture, diff --git a/src/Avalonia.Base/Rendering/Composition/Compositor.cs b/src/Avalonia.Base/Rendering/Composition/Compositor.cs index b8b0d736798..a3a8e0e97a1 100644 --- a/src/Avalonia.Base/Rendering/Composition/Compositor.cs +++ b/src/Avalonia.Base/Rendering/Composition/Compositor.cs @@ -294,7 +294,7 @@ internal bool UnitTestIsRegisteredForSerialization(ICompositorSerializable seria _objectSerializationHashSet.Contains(serializable); /// - /// Attempts to get the Compositor instance that will be used by default for new s + /// Attempts to get the Compositor instance that will be used by default for new TopLevels /// created by the current platform backend. /// /// This won't work for every single platform backend and backend settings, e. g. with web we'll need to have diff --git a/src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs b/src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs index 71c6b5c1783..c0f3b0a336f 100644 --- a/src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs +++ b/src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs @@ -24,6 +24,7 @@ internal static class ColorPickerHelpers /// Generates a new bitmap of the specified size by changing a specific color component. /// This will produce a gradient representing a sweep of all possible values of the color component. /// + /// The target buffer which will contain the bitmap data on return. /// The pixel width (X, horizontal) of the resulting bitmap. /// The pixel height (Y, vertical) of the resulting bitmap. /// The orientation of the resulting bitmap (gradient direction). diff --git a/src/Avalonia.Controls/NativeMenuItem.cs b/src/Avalonia.Controls/NativeMenuItem.cs index d67e6a58fc0..558b2aa0713 100644 --- a/src/Avalonia.Controls/NativeMenuItem.cs +++ b/src/Avalonia.Controls/NativeMenuItem.cs @@ -1,5 +1,6 @@ using System; using System.Windows.Input; +using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Media.Imaging; using Avalonia.Metadata; @@ -65,11 +66,11 @@ public Bitmap? Icon set => SetValue(IconProperty, value); } - /// + /// public static readonly StyledProperty HeaderProperty = AvaloniaProperty.Register(nameof(Header)); - /// + /// public string? Header { get => GetValue(HeaderProperty); @@ -134,10 +135,11 @@ public NativeMenuItemToggleType ToggleType public static readonly StyledProperty CommandParameterProperty = MenuItem.CommandParameterProperty.AddOwner(); + /// public static readonly StyledProperty IsEnabledProperty = AvaloniaProperty.Register(nameof(IsEnabled), true); - /// + /// public bool IsEnabled { get => GetValue(IsEnabledProperty); diff --git a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs index b7647df4444..f92151e02a6 100644 --- a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs +++ b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs @@ -14,7 +14,6 @@ namespace Avalonia.Controls { public class RefreshVisualizer : ContentControl { - private const int DefaultIndicatorSize = 24; private const float MinimumIndicatorOpacity = 0.4f; private const float ParallaxPositionRatio = 0.5f; private double _executingRatio = 0.8; diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlControlTemplatePartsChecker.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlControlTemplatePartsChecker.cs index 2764971326c..3bfc5881d03 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlControlTemplatePartsChecker.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlControlTemplatePartsChecker.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +#nullable enable + +using System.Collections.Generic; using System.Linq; using XamlX; using XamlX.Ast; diff --git a/tests/Avalonia.Base.UnitTests/Data/Core/BindingExpressionTests.UpdateSourceTrigger.cs b/tests/Avalonia.Base.UnitTests/Data/Core/BindingExpressionTests.UpdateSourceTrigger.cs index b1e21467fd3..434a0c38ae6 100644 --- a/tests/Avalonia.Base.UnitTests/Data/Core/BindingExpressionTests.UpdateSourceTrigger.cs +++ b/tests/Avalonia.Base.UnitTests/Data/Core/BindingExpressionTests.UpdateSourceTrigger.cs @@ -1,3 +1,5 @@ +#nullable enable + using Avalonia.Data; using Avalonia.UnitTests; using Xunit; diff --git a/tests/Avalonia.Base.UnitTests/DispatcherTests.Exception.cs b/tests/Avalonia.Base.UnitTests/DispatcherTests.Exception.cs index 8da7815e221..45ca7d290b5 100644 --- a/tests/Avalonia.Base.UnitTests/DispatcherTests.Exception.cs +++ b/tests/Avalonia.Base.UnitTests/DispatcherTests.Exception.cs @@ -265,7 +265,7 @@ public void MultipleUnhandledExceptionCannotResetHandleFlag() dispatcher.Post(ThrowAnException, DispatcherPriority.Normal); dispatcher.RunJobs(); } - catch (Exception e) + catch (Exception) { // should be no exception here. caughtCorrectException = false; diff --git a/tests/Avalonia.Base.UnitTests/Input/KeyboardNavigationTests_XY.cs b/tests/Avalonia.Base.UnitTests/Input/KeyboardNavigationTests_XY.cs index 1b8238f4b78..2ea3a51908f 100644 --- a/tests/Avalonia.Base.UnitTests/Input/KeyboardNavigationTests_XY.cs +++ b/tests/Avalonia.Base.UnitTests/Input/KeyboardNavigationTests_XY.cs @@ -350,11 +350,11 @@ public void Arrow_Key_Should_Focus_Element(Key key, NavigationDirection directio } [Theory] - [InlineData(Key.Left, NavigationDirection.Left)] - [InlineData(Key.Right, NavigationDirection.Right)] - [InlineData(Key.Up, NavigationDirection.Up)] - [InlineData(Key.Down, NavigationDirection.Down)] - public void Arrow_Key_Should_Not_Be_Handled_If_No_Focus(Key key, NavigationDirection direction) + [InlineData(Key.Left)] + [InlineData(Key.Right)] + [InlineData(Key.Up)] + [InlineData(Key.Down)] + public void Arrow_Key_Should_Not_Be_Handled_If_No_Focus(Key key) { using var _ = UnitTestApplication.Start(TestServices.FocusableWindow); diff --git a/tests/Avalonia.Controls.UnitTests/VirtualizingStackPanelTests.cs b/tests/Avalonia.Controls.UnitTests/VirtualizingStackPanelTests.cs index b72f2376deb..5d96e68f1e1 100644 --- a/tests/Avalonia.Controls.UnitTests/VirtualizingStackPanelTests.cs +++ b/tests/Avalonia.Controls.UnitTests/VirtualizingStackPanelTests.cs @@ -1144,7 +1144,7 @@ public void ScrollIntoView_With_TargetRect_Outside_Viewport_Should_Scroll_To_Ite { ev.Container.AddHandler(Control.RequestBringIntoViewEvent, (_, e) => { - var dataContext = e.TargetObject.DataContext as ItemWithHeight; + var dataContext = (ItemWithHeight)e.TargetObject!.DataContext!; e.TargetRect = new Rect(dataContext.Height - 50, 0, 50, 10); }); }; diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs index c2cec8cf798..905b3456d63 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs @@ -1005,7 +1005,7 @@ public void Binds_To_TemplatedParent_From_Non_Control() "; var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); - var button = window.FindControl