Replace CanBeNull annotations with nullable reference types (#1270)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
DrSmugleaf
2020-07-08 01:41:20 +02:00
committed by GitHub
parent 5aefae184c
commit e7d756811e
25 changed files with 95 additions and 112 deletions

View File

@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Text;
@@ -11,8 +12,6 @@ using Robust.Shared.ViewVariables;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
#nullable enable
namespace Content.Client
{
internal class ClickMapManager : IClickMapManager, IPostInjectInit

View File

@@ -1,3 +1,4 @@
#nullable enable
using System;
using Robust.Client.Graphics.ClientEye;
using Robust.Client.Interfaces.GameObjects.Components;
@@ -8,8 +9,6 @@ using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
#nullable enable
namespace Content.Client.GameObjects.Components
{
[RegisterComponent]

View File

@@ -1,24 +1,17 @@
#nullable enable
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using Content.Shared.GameObjects.Components.Instruments;
using Content.Shared.Physics;
using JetBrains.Annotations;
using NFluidsynth;
using Robust.Shared.GameObjects;
using Robust.Client.Audio.Midi;
using Robust.Client.Player;
using Robust.Shared.Interfaces.Log;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
using Logger = Robust.Shared.Log.Logger;
using MidiEvent = Robust.Shared.Audio.Midi.MidiEvent;
using Timer = Robust.Shared.Timers.Timer;
@@ -32,24 +25,23 @@ namespace Content.Client.GameObjects.Components.Instruments
/// <summary>
/// Called when a midi song stops playing.
/// </summary>
public event Action OnMidiPlaybackEnded;
public event Action? OnMidiPlaybackEnded;
#pragma warning disable 649
[Dependency] private readonly IMidiManager _midiManager;
[Dependency] private readonly IMidiManager _midiManager = default!;
[Dependency] private readonly IGameTiming _gameTiming;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IClientNetManager _netManager;
[Dependency] private readonly IClientNetManager _netManager = default!;
#pragma warning restore 649
[CanBeNull]
private IMidiRenderer _renderer;
private IMidiRenderer? _renderer;
private byte _instrumentProgram = 1;
private byte _instrumentBank = 0;
private byte _instrumentBank;
private uint _sequenceDelay = 0;
private uint _sequenceDelay;
private uint _sequenceStartTick;
@@ -209,7 +201,7 @@ namespace Content.Client.GameObjects.Components.Instruments
serializer.DataField(ref _instrumentBank, "bank", (byte) 0);
}
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null)
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
{
base.HandleNetworkMessage(message, channel, session);
@@ -240,7 +232,7 @@ namespace Content.Client.GameObjects.Components.Instruments
.Min(x => x.Tick) - 1;
}
var sqrtLag = MathF.Sqrt(_netManager.ServerChannel.Ping / 1000f);
var sqrtLag = MathF.Sqrt(_netManager.ServerChannel!.Ping / 1000f);
var delay = (uint) (_renderer!.SequencerTimeScale * (.2 + sqrtLag));
var delta = delay - _sequenceStartTick;
@@ -265,12 +257,12 @@ namespace Content.Client.GameObjects.Components.Instruments
}
break;
case InstrumentStartMidiMessage startMidiMessage:
case InstrumentStartMidiMessage _:
{
SetupRenderer(true);
break;
}
case InstrumentStopMidiMessage stopMidiMessage:
case InstrumentStopMidiMessage _:
{
EndRenderer(true);
break;
@@ -278,7 +270,7 @@ namespace Content.Client.GameObjects.Components.Instruments
}
}
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (!(curState is InstrumentState state)) return;
@@ -370,7 +362,7 @@ namespace Content.Client.GameObjects.Components.Instruments
private TimeSpan _lastMeasured = TimeSpan.MinValue;
private int _sentWithinASec = 0;
private int _sentWithinASec;
private static readonly TimeSpan OneSecAgo = TimeSpan.FromSeconds(-1);

View File

@@ -1,5 +1,5 @@
using Content.Shared.GameObjects.Components.Mobs;
using JetBrains.Annotations;
#nullable enable
using Content.Shared.GameObjects.Components.Mobs;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
@@ -9,7 +9,7 @@ namespace Content.Client.GameObjects.Components.Mobs
{
public readonly StatusEffect Effect;
public StatusControl(StatusEffect effect, [CanBeNull] Texture texture)
public StatusControl(StatusEffect effect, Texture? texture)
{
Effect = effect;

View File

@@ -1,9 +1,8 @@
#nullable enable
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Movement;
using Robust.Shared.GameObjects;
#nullable enable
namespace Content.Client.GameObjects.Components.Mobs
{
[RegisterComponent]

View File

@@ -1,14 +1,13 @@
#nullable enable
using Content.Shared.GameObjects.Components.Movement;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
#nullable enable
namespace Content.Client.GameObjects.Components.Movement
{
[RegisterComponent]
[ComponentReference(typeof(IMoverComponent))]
public class PlayerInputMoverComponent : SharedPlayerInputMoverComponent, IMoverComponent
public class PlayerInputMoverComponent : SharedPlayerInputMoverComponent
{
public override GridCoordinates LastPosition { get; set; }
public override float StepSoundDistance { get; set; }

View File

@@ -1,9 +1,8 @@
#nullable enable
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.Components.Nutrition;
using Robust.Shared.GameObjects;
#nullable enable
namespace Content.Client.GameObjects.Components.Nutrition
{
[RegisterComponent]

View File

@@ -1,9 +1,8 @@
#nullable enable
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.Components.Nutrition;
using Robust.Shared.GameObjects;
#nullable enable
namespace Content.Client.GameObjects.Components.Nutrition
{
[RegisterComponent]

View File

@@ -1,8 +1,7 @@
#nullable enable
using Content.Shared.GameObjects.Components.Projectiles;
using Robust.Shared.GameObjects;
#nullable enable
namespace Content.Client.GameObjects.Components.Projectiles
{
[RegisterComponent]

View File

@@ -1,4 +1,5 @@
using Content.Shared.GameObjects.Components.Movement;
#nullable enable
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Physics;
using JetBrains.Annotations;
@@ -7,8 +8,6 @@ using Robust.Client.Player;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.IoC;
#nullable enable
namespace Content.Client.GameObjects.EntitySystems
{
[UsedImplicitly]

View File

@@ -1,3 +1,4 @@
#nullable enable
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -13,8 +14,6 @@ using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
#nullable enable
namespace Content.Client.UserInterface
{
public sealed class CreditsWindow : SS14Window

View File

@@ -1,3 +1,4 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -15,8 +16,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Timing;
#nullable enable
namespace Content.IntegrationTests.Tests.Networking
{
// This test checks that the prediction & reconciling system is working correctly with a simple boolean flag.

View File

@@ -1,11 +1,10 @@
#nullable enable
using System.Collections.Generic;
using Content.Server.Interfaces;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
#nullable enable
namespace Content.Server.GameObjects.Components.Access
{
/// <summary>

View File

@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
@@ -10,8 +11,6 @@ using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
#nullable enable
namespace Content.Server.GameObjects.Components.Access
{
/// <summary>
@@ -68,7 +67,6 @@ namespace Content.Server.GameObjects.Components.Access
return _accessLists.Count == 0 || _accessLists.Any(a => a.IsSubsetOf(accessTags));
}
[CanBeNull]
public static ICollection<string> FindAccessTags(IEntity entity)
{
if (entity.TryGetComponent(out IAccess accessComponent))

View File

@@ -1,3 +1,4 @@
#nullable enable
using Content.Shared.Jobs;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
@@ -5,8 +6,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
#nullable enable
namespace Content.Server.GameObjects.Components.Access
{
[RegisterComponent]

View File

@@ -1,10 +1,10 @@
using Content.Server.Cargo;
#nullable enable
using Content.Server.Cargo;
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces.GameObjects.Components.Interaction;
using Content.Shared.GameObjects.Components.Cargo;
using Content.Shared.Prototypes.Cargo;
using JetBrains.Annotations;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
@@ -20,39 +20,43 @@ namespace Content.Server.GameObjects.Components.Cargo
public class CargoConsoleComponent : SharedCargoConsoleComponent, IActivate
{
#pragma warning disable 649
[Dependency] private readonly ICargoOrderDataManager _cargoOrderDataManager;
[Dependency] private readonly ICargoOrderDataManager _cargoOrderDataManager = default!;
#pragma warning restore 649
[ViewVariables]
public int Points = 1000;
private BoundUserInterface _userInterface;
private BoundUserInterface _userInterface = default!;
[ViewVariables]
public GalacticMarketComponent Market { get; private set; }
[ViewVariables]
public CargoOrderDatabaseComponent Orders { get; private set; }
private CargoBankAccount _bankAccount;
public GalacticMarketComponent Market { get; private set; } = default!;
[ViewVariables]
[CanBeNull]
public CargoBankAccount BankAccount
public CargoOrderDatabaseComponent Orders { get; private set; } = default!;
private CargoBankAccount? _bankAccount;
[ViewVariables]
public CargoBankAccount? BankAccount
{
get => _bankAccount;
private set
{
if (_bankAccount == value)
{
return;
}
if (_bankAccount != null)
{
_bankAccount.OnBalanceChange -= UpdateUIState;
}
_bankAccount = value;
if (value != null)
{
_bankAccount.OnBalanceChange += UpdateUIState;
value.OnBalanceChange += UpdateUIState;
}
UpdateUIState();
@@ -61,9 +65,9 @@ namespace Content.Server.GameObjects.Components.Cargo
private bool _requestOnly = false;
private PowerReceiverComponent _powerReceiver;
private PowerReceiverComponent _powerReceiver = default!;
private bool Powered => _powerReceiver.Powered;
private CargoConsoleSystem _cargoConsoleSystem;
private CargoConsoleSystem _cargoConsoleSystem = default!;
public override void Initialize()
{
@@ -98,8 +102,11 @@ namespace Content.Server.GameObjects.Components.Cargo
{
case CargoConsoleAddOrderMessage msg:
{
if (msg.Amount <= 0)
if (msg.Amount <= 0 || _bankAccount == null)
{
break;
}
_cargoOrderDataManager.AddOrder(Orders.Database.Id, msg.Requester, msg.Reason, msg.ProductId, msg.Amount, _bankAccount.Id);
break;
}
@@ -111,8 +118,12 @@ namespace Content.Server.GameObjects.Components.Cargo
case CargoConsoleApproveOrderMessage msg:
{
if (_requestOnly ||
!Orders.Database.TryGetOrder(msg.OrderNumber, out var order))
!Orders.Database.TryGetOrder(msg.OrderNumber, out var order) ||
_bankAccount == null)
{
break;
}
_prototypeManager.TryIndex(order.ProductId, out CargoProductPrototype product);
if (product == null)
break;

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components.Strap;
#nullable enable
using Content.Server.GameObjects.Components.Strap;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces;
using Content.Server.Interfaces.GameObjects.Components.Interaction;
@@ -8,7 +9,6 @@ using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Strap;
using Content.Shared.GameObjects.EntitySystems;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
@@ -25,15 +25,15 @@ namespace Content.Server.GameObjects.Components.Mobs
public class BuckleComponent : SharedBuckleComponent, IInteractHand, IDragDrop
{
#pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystem;
[Dependency] private readonly IServerNotifyManager _notifyManager;
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;
[Dependency] private readonly IServerNotifyManager _notifyManager = default!;
#pragma warning restore 649
[CanBeNull] private StrapComponent _buckledTo;
private StrapComponent? _buckledTo;
private int _size;
[ViewVariables, CanBeNull]
public StrapComponent BuckledTo
[ViewVariables]
public StrapComponent? BuckledTo
{
get => _buckledTo;
private set

View File

@@ -1,11 +1,7 @@
using Content.Shared.GameObjects.Components.Movement;
#nullable enable
using Content.Shared.GameObjects.Components.Movement;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.ViewVariables;
#nullable enable
namespace Content.Server.GameObjects.Components.Movement
{

View File

@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
@@ -22,8 +23,6 @@ using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
#nullable enable
namespace Content.Server.GameObjects.Components.PDA
{
[RegisterComponent]

View File

@@ -1,4 +1,5 @@
using System;
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.Interactable;
@@ -32,12 +33,12 @@ namespace Content.Server.GameObjects.Components
public class WiresComponent : SharedWiresComponent, IInteractUsing, IExamine, IMapInit
{
#pragma warning disable 649
[Dependency] private readonly IRobustRandom _random;
[Dependency] private readonly IServerNotifyManager _notifyManager;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IServerNotifyManager _notifyManager = default!;
#pragma warning restore 649
private AudioSystem _audioSystem;
private AppearanceComponent _appearance;
private BoundUserInterface _userInterface;
private AudioSystem _audioSystem = default!;
private AppearanceComponent _appearance = default!;
private BoundUserInterface _userInterface = default!;
private bool _isPanelOpen;
@@ -93,7 +94,7 @@ namespace Content.Server.GameObjects.Components
}
[ViewVariables(VVAccess.ReadWrite)]
public string SerialNumber
public string? SerialNumber
{
get => _serialNumber;
set
@@ -127,16 +128,16 @@ namespace Content.Server.GameObjects.Components
private readonly List<WireLetter> _availableLetters =
new List<WireLetter>((WireLetter[]) Enum.GetValues(typeof(WireLetter)));
private string _boardName;
private string _boardName = default!;
private string _serialNumber;
private string? _serialNumber;
// Used to generate wire appearance randomization client side.
// We honestly don't care what it is or such but do care that it doesn't change between UI re-opens.
[ViewVariables]
private int _wireSeed;
[ViewVariables]
private string _layoutId;
private string? _layoutId;
public override void Initialize()
{
@@ -186,7 +187,7 @@ namespace Content.Server.GameObjects.Components
base.Startup();
WireLayout layout = null;
WireLayout? layout = null;
var hackingSystem = EntitySystem.Get<WireHackingSystem>();
if (_layoutId != null)
{
@@ -299,9 +300,9 @@ namespace Content.Server.GameObjects.Components
{
[NotNull] private readonly WiresComponent _wires;
[NotNull] private readonly IWires _owner;
[CanBeNull] private readonly WireLayout _layout;
private readonly WireLayout? _layout;
public WiresBuilder(WiresComponent wires, IWires owner, WireLayout layout)
public WiresBuilder(WiresComponent wires, IWires owner, WireLayout? layout)
{
_wires = wires;
_owner = owner;
@@ -365,12 +366,12 @@ namespace Content.Server.GameObjects.Components
{
case WiresActionMessage msg:
var wire = WiresList.Find(x => x.Id == msg.Id);
if (wire == null)
var player = serverMsg.Session.AttachedEntity;
if (wire == null || player == null)
{
return;
}
var player = serverMsg.Session.AttachedEntity;
if (!player.TryGetComponent(out IHandsComponent handsComponent))
{
_notifyManager.PopupMessage(Owner.Transform.GridPosition, player,
@@ -386,7 +387,7 @@ namespace Content.Server.GameObjects.Components
}
var activeHandEntity = handsComponent.GetActiveHand?.Owner;
ToolComponent tool = null;
ToolComponent? tool = null;
activeHandEntity?.TryGetComponent(out tool);
switch (msg.Action)

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects;
#nullable enable
using Content.Server.GameObjects;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Movement;
@@ -23,8 +24,6 @@ using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
#nullable enable
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]

View File

@@ -1,9 +1,8 @@
#nullable enable
using System;
using Content.Server.GameObjects.Components.Access;
using System.Collections.Generic;
#nullable enable
namespace Content.Server.Interfaces
{
/// <summary>

View File

@@ -1,4 +1,5 @@
using System;
#nullable enable
using System;
using Content.Shared.GameObjects.Components.Mobs;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
@@ -13,8 +14,6 @@ using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
#nullable enable
namespace Content.Shared.GameObjects.Components.Movement
{
public abstract class SharedPlayerInputMoverComponent : Component, IMoverComponent, ICollideSpecial

View File

@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
#nullable enable
using System.Diagnostics.CodeAnalysis;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.Physics;
using Robust.Shared.Configuration;
@@ -15,8 +16,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Players;
#nullable enable
namespace Content.Shared.GameObjects.EntitySystems
{
public abstract class SharedMoverSystem : EntitySystem

View File

@@ -1,4 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeEditing/TypingAssist/CSharpAnnotationTypingAssist/IsEnabledAfterTypeName/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeEditing/TypingAssist/CSharpAnnotationTypingAssist/IsEnabledAtOtherPositions/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceDoWhileStatementBraces/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceFixedStatementBraces/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceForeachStatementBraces/@EntryIndexedValue">WARNING</s:String>