Skip to content

Commit

Permalink
Misc warning fixes (#14766)
Browse files Browse the repository at this point in the history
* Fix XML doc warnings

* Fix nullability warnings

* Fix misc warnings
  • Loading branch information
MrJul authored Feb 29, 2024
1 parent a634743 commit cac27dd
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 33 deletions.
15 changes: 9 additions & 6 deletions src/Android/Avalonia.Android/AndroidRuntimePlatform.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#nullable enable

using System;
using Android.Content.PM;
using Android.Content;
using Avalonia.Platform;
Expand Down Expand Up @@ -27,7 +29,7 @@ public static void Register(Assembly? assembly = null)

internal class AndroidRuntimePlatform : StandardRuntimePlatform
{
private static readonly Lazy<RuntimePlatformInfo> Info = new(() =>
private static readonly Lazy<RuntimePlatformInfo> s_info = new(() =>
{
var isDesktop = IsRunningOnDesktop(App.Context);
var isTv = IsRunningOnTv(App.Context);
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/Avalonia.Base/Data/Core/ExpressionParseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace Avalonia.Data.Core
{
/// <summary>
/// Exception thrown when <see cref="ExpressionObserver"/> could not parse the provided
/// expression string.
/// Exception thrown when the provided binding expression string could not be parsed.
/// </summary>
#if !BUILDTASK
public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class BindingExpressionVisitor<TIn> : 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;
Expand Down
3 changes: 1 addition & 2 deletions src/Avalonia.Base/Data/Core/UntypedBindingExpressionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ public override void Dispose()
}

/// <summary>
/// Starts the binding expression following a call to
/// <see cref="AttachCore(IBindingExpressionSink, AvaloniaObject, AvaloniaProperty, BindingPriority)"/>.
/// Starts the binding expression following a call to <see cref="AttachCore"/>.
/// </summary>
public void Start() => Start(produceValue: true);

Expand Down
1 change: 0 additions & 1 deletion src/Avalonia.Base/Media/FormattedText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class FormattedText
/// <param name="typeface">Type face used to display text.</param>
/// <param name="emSize">Font em size in visual units (1/96 of an inch).</param>
/// <param name="foreground">Foreground brush used to render text.</param>
/// <param name="features">Optional list of turned on/off features.</param>
public FormattedText(
string textToFormat,
CultureInfo culture,
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Base/Rendering/Composition/Compositor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ internal bool UnitTestIsRegisteredForSerialization(ICompositorSerializable seria
_objectSerializationHashSet.Contains(serializable);

/// <summary>
/// Attempts to get the Compositor instance that will be used by default for new <see cref="Avalonia.Controls.TopLevel"/>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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
/// <param name="bgraPixelData">The target buffer which will contain the bitmap data on return.</param>
/// <param name="width">The pixel width (X, horizontal) of the resulting bitmap.</param>
/// <param name="height">The pixel height (Y, vertical) of the resulting bitmap.</param>
/// <param name="orientation">The orientation of the resulting bitmap (gradient direction).</param>
Expand Down
8 changes: 5 additions & 3 deletions src/Avalonia.Controls/NativeMenuItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Windows.Input;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Media.Imaging;
using Avalonia.Metadata;
Expand Down Expand Up @@ -65,11 +66,11 @@ public Bitmap? Icon
set => SetValue(IconProperty, value);
}

/// <inheritdoc cref="MenuItem.HeaderProperty"/>
/// <inheritdoc cref="HeaderedSelectingItemsControl.HeaderProperty"/>
public static readonly StyledProperty<string?> HeaderProperty =
AvaloniaProperty.Register<NativeMenuItem, string?>(nameof(Header));

/// <inheritdoc cref="MenuItem.Header"/>
/// <inheritdoc cref="HeaderedSelectingItemsControl.Header"/>
public string? Header
{
get => GetValue(HeaderProperty);
Expand Down Expand Up @@ -134,10 +135,11 @@ public NativeMenuItemToggleType ToggleType
public static readonly StyledProperty<object?> CommandParameterProperty =
MenuItem.CommandParameterProperty.AddOwner<NativeMenuItem>();

/// <inheritdoc cref="InputElement.IsEnabledProperty"/>
public static readonly StyledProperty<bool> IsEnabledProperty =
AvaloniaProperty.Register<NativeMenuItem, bool>(nameof(IsEnabled), true);

/// <inheritdoc cref="MenuItem.IsEnabled"/>
/// <inheritdoc cref="InputElement.IsEnabled"/>
public bool IsEnabled
{
get => GetValue(IsEnabledProperty);
Expand Down
1 change: 0 additions & 1 deletion src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
#nullable enable

using System.Collections.Generic;
using System.Linq;
using XamlX;
using XamlX.Ast;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using Avalonia.Data;
using Avalonia.UnitTests;
using Xunit;
Expand Down
2 changes: 1 addition & 1 deletion tests/Avalonia.Base.UnitTests/DispatcherTests.Exception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ public void Binds_To_TemplatedParent_From_Non_Control()
</Button>
</Window>";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
var button = window.FindControl<Button>("button");
var button = window.GetControl<Button>("button");

button.Tag = new GridLength(5, GridUnitType.Star);

Expand Down Expand Up @@ -1985,7 +1985,7 @@ public void Should_Negate_Boolean_Value(bool value)
<TextBlock Name='textBlock' Tag='{{Binding !BoolProperty}}'/>
</Window>";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
var textBlock = window.FindControl<TextBlock>("textBlock");
var textBlock = window.GetControl<TextBlock>("textBlock");

var dataContext = new TestDataContext { BoolProperty = value };
window.DataContext = dataContext;
Expand Down Expand Up @@ -2013,7 +2013,7 @@ public void Can_Use_Implicit_Conversions()
</TextBlock>
</Window>";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
var textBlock = window.FindControl<TextBlock>("textBlock");
var textBlock = window.GetControl<TextBlock>("textBlock");

var dataContext = new ImplicitConvertible("Green");
window.DataContext = dataContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class RelativePointTestPrimitivesHelper : Control
{
private readonly IBrush? _brush;
private readonly bool _shadow;
private readonly IPen _line;
private static readonly Geometry s_Geometry = Geometry.Parse("m 80 200 c 40 20 150 -40 160 0 l 0 30 c -40 -30 -160 10 -160 -30 z");
private readonly IPen? _line;
private static readonly Geometry s_geometry = Geometry.Parse("m 80 200 c 40 20 150 -40 160 0 l 0 30 c -40 -30 -160 10 -160 -30 z");

public RelativePointTestPrimitivesHelper(IBrush? brush, bool shadow = false)
{
Expand All @@ -42,8 +42,9 @@ public override void Render(DrawingContext context)

context.DrawRectangle(_brush, null, new Rect(20, 20, 200, 60));
context.DrawEllipse(_brush, null, new Rect(40, 100, 200, 20));
context.DrawLine(_line, new Point(60, 140), new Point(240, 160));
context.DrawGeometry(_brush, null, s_Geometry);
if (_line is not null)
context.DrawLine(_line, new Point(60, 140), new Point(240, 160));
context.DrawGeometry(_brush, null, s_geometry);

base.Render(context);
}
Expand Down

0 comments on commit cac27dd

Please sign in to comment.