Replace MaybeNullWhen(false) with NotNullWhen(true)

This commit is contained in:
DrSmugleaf
2020-12-20 04:14:41 +01:00
parent f7edb9ce7e
commit 026d96fd2d
11 changed files with 41 additions and 48 deletions

View File

@@ -55,7 +55,7 @@ namespace Content.Client.GameObjects.Components.Items
return Hands.FirstOrDefault(hand => hand.Name == name);
}
private bool TryHand(string name, [MaybeNullWhen(false)] out Hand hand)
private bool TryHand(string name, [NotNullWhen(true)] out Hand? hand)
{
return (hand = GetHand(name)) != null;
}

View File

@@ -13,7 +13,7 @@ namespace Content.Server.Atmos
{
public static class AtmosHelpers
{
public static TileAtmosphere GetTileAtmosphere(this EntityCoordinates coordinates, IEntityManager? entityManager = null)
public static TileAtmosphere? GetTileAtmosphere(this EntityCoordinates coordinates, IEntityManager? entityManager = null)
{
entityManager ??= IoCManager.Resolve<IEntityManager>();
@@ -24,19 +24,19 @@ namespace Content.Server.Atmos
public static GasMixture? GetTileAir(this EntityCoordinates coordinates, IEntityManager? entityManager = null)
{
return coordinates.GetTileAtmosphere(entityManager).Air;
return coordinates.GetTileAtmosphere(entityManager)?.Air;
}
public static bool TryGetTileAtmosphere(this EntityCoordinates coordinates, [MaybeNullWhen(false)] out TileAtmosphere atmosphere)
public static bool TryGetTileAtmosphere(this EntityCoordinates coordinates, [NotNullWhen(true)] out TileAtmosphere? atmosphere)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(atmosphere = coordinates.GetTileAtmosphere()!, default);
return !Equals(atmosphere = coordinates.GetTileAtmosphere(), default);
}
public static bool TryGetTileAir(this EntityCoordinates coordinates, [MaybeNullWhen(false)] out GasMixture air, IEntityManager? entityManager = null)
public static bool TryGetTileAir(this EntityCoordinates coordinates, [NotNullWhen(true)] out GasMixture? air, IEntityManager? entityManager = null)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(air = coordinates.GetTileAir(entityManager)!, default);
return !Equals(air = coordinates.GetTileAir(entityManager), default);
}
public static bool IsTileAirProbablySafe(this EntityCoordinates coordinates)
@@ -56,7 +56,7 @@ namespace Content.Server.Atmos
return true;
}
public static TileAtmosphere GetTileAtmosphere(this Vector2i indices, GridId gridId)
public static TileAtmosphere? GetTileAtmosphere(this Vector2i indices, GridId gridId)
{
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId);
@@ -69,28 +69,25 @@ namespace Content.Server.Atmos
}
public static bool TryGetTileAtmosphere(this Vector2i indices, GridId gridId,
[MaybeNullWhen(false)] out TileAtmosphere atmosphere)
[NotNullWhen(true)] out TileAtmosphere? atmosphere)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(atmosphere = indices.GetTileAtmosphere(gridId)!, default);
return !Equals(atmosphere = indices.GetTileAtmosphere(gridId), default);
}
public static bool TryGetTileAir(this Vector2i indices, GridId gridId, [MaybeNullWhen(false)] out GasMixture air)
public static bool TryGetTileAir(this Vector2i indices, GridId gridId, [NotNullWhen(true)] out GasMixture? air)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return !Equals(air = indices.GetTileAir(gridId)!, default);
return !Equals(air = indices.GetTileAir(gridId), default);
}
public static bool InvalidateTileAir(this ITransformComponent transform, AtmosphereSystem? atmosSystem = null)
{
return InvalidateTileAir(transform.Coordinates, atmosSystem);
return InvalidateTileAir(transform.Coordinates);
}
public static bool InvalidateTileAir(this EntityCoordinates coordinates, AtmosphereSystem? atmosSystem = null, IEntityManager? entityManager = null)
public static bool InvalidateTileAir(this EntityCoordinates coordinates)
{
atmosSystem ??= EntitySystem.Get<AtmosphereSystem>();
entityManager ??= IoCManager.Resolve<IEntityManager>();
if (!coordinates.TryGetTileAtmosphere(out var tileAtmos))
{
return false;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using Content.Server.GameObjects.Components.Atmos;
using Content.Server.GameObjects.Components.Atmos.Piping;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
@@ -120,7 +121,7 @@ namespace Content.Server.Atmos
/// <param name="indices"></param>
/// <param name="createSpace"></param>
/// <returns></returns>
TileAtmosphere GetTile(Vector2i indices, bool createSpace = true);
TileAtmosphere? GetTile(Vector2i indices, bool createSpace = true);
/// <summary>
/// Returns a tile.
@@ -128,7 +129,7 @@ namespace Content.Server.Atmos
/// <param name="coordinates"></param>
/// <param name="createSpace"></param>
/// <returns></returns>
TileAtmosphere GetTile(EntityCoordinates coordinates, bool createSpace = true);
TileAtmosphere? GetTile(EntityCoordinates coordinates, bool createSpace = true);
/// <summary>
/// Returns if the tile in question is air-blocked.

View File

@@ -42,7 +42,7 @@ namespace Content.Server.GameObjects.Components
/// <param name="utilizing">The tool being used, can be null if forcing it</param>
/// <param name="force">Whether or not to check if the tool is valid</param>
/// <returns>true if it is valid, false otherwise</returns>
private async Task<bool> Valid(IEntity user, IEntity? utilizing, [MaybeNullWhen(false)] bool force = false)
private async Task<bool> Valid(IEntity user, IEntity? utilizing, [NotNullWhen(true)] bool force = false)
{
if (!Owner.HasComponent<IPhysicsComponent>())
{

View File

@@ -130,7 +130,7 @@ namespace Content.Server.GameObjects.Components.Atmos
// Already get the pressure before Dirty(), because we can't get the EntitySystem in that thread or smth
var pressure = 0f;
var gam = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(Owner.Transform.GridID);
var tile = gam?.GetTile(Owner.Transform.Coordinates).Air;
var tile = gam?.GetTile(Owner.Transform.Coordinates)?.Air;
if (tile != null)
{
pressure = tile.Pressure;
@@ -190,7 +190,7 @@ namespace Content.Server.GameObjects.Components.Atmos
var atmosSystem = EntitySystem.Get<AtmosphereSystem>();
var gam = atmosSystem.GetGridAtmosphere(pos.GetGridId(Owner.EntityManager));
var tile = gam?.GetTile(pos).Air;
var tile = gam.GetTile(pos)?.Air;
if (tile == null)
{
error = "No Atmosphere!";

View File

@@ -2,7 +2,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using Content.Server.Atmos;
@@ -10,7 +9,6 @@ using Content.Server.GameObjects.Components.Atmos.Piping;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.GameObjects.EntitySystems.Atmos;
using Content.Shared;
using Content.Shared.Atmos;
using Content.Shared.Maps;
using Robust.Server.GameObjects.EntitySystems.TileLookup;
@@ -19,7 +17,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.ComponentDependencies;
using Robust.Shared.GameObjects.Components.Map;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Configuration;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Log;
using Robust.Shared.Map;

View File

@@ -9,7 +9,6 @@ using Content.Server.GameObjects.Components.Strap;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Alert;
using Content.Shared.GameObjects.Components.Buckle;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Strap;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs;
@@ -27,7 +26,6 @@ using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -157,7 +155,7 @@ namespace Content.Server.GameObjects.Components.Buckle
}
}
private bool CanBuckle(IEntity? user, IEntity to, [MaybeNullWhen(false)] out StrapComponent strap)
private bool CanBuckle(IEntity? user, IEntity to, [NotNullWhen(true)] out StrapComponent? strap)
{
strap = null;

View File

@@ -105,10 +105,9 @@ namespace Content.Server.GameObjects.Components.GUI
return GetHand(handName)?.Entity?.GetComponent<ItemComponent>();
}
public bool TryGetItem(string handName, [MaybeNullWhen(false)] out ItemComponent item)
public bool TryGetItem(string handName, [NotNullWhen(true)] out ItemComponent? item)
{
item = GetItem(handName);
return item != null;
return (item = GetItem(handName)) != null;
}
public ItemComponent? GetActiveHand => ActiveHand == null
@@ -240,7 +239,7 @@ namespace Content.Server.GameObjects.Components.GUI
return true;
}
public bool TryHand(IEntity entity, [MaybeNullWhen(false)] out string handName)
public bool TryHand(IEntity entity, [NotNullWhen(true)] out string? handName)
{
handName = null;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Server.GameObjects.Components.Conveyor;
using Content.Server.GameObjects.Components.Items.Storage;
@@ -40,12 +41,12 @@ namespace Content.Server.GameObjects.Components.Recycling
private int _efficiency; // TODO
private bool Powered =>
!Owner.TryGetComponent(out PowerReceiverComponent receiver) ||
!Owner.TryGetComponent(out PowerReceiverComponent? receiver) ||
receiver.Powered;
private void Bloodstain()
{
if (Owner.TryGetComponent(out AppearanceComponent appearance))
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(RecyclerVisuals.Bloody, true);
}
@@ -53,7 +54,7 @@ namespace Content.Server.GameObjects.Components.Recycling
private void Clean()
{
if (Owner.TryGetComponent(out AppearanceComponent appearance))
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(RecyclerVisuals.Bloody, false);
}
@@ -64,7 +65,7 @@ namespace Content.Server.GameObjects.Components.Recycling
return entity.HasComponent<IBody>() && !_safe && Powered;
}
private bool CanRecycle(IEntity entity, [MaybeNullWhen(false)] out ConstructionPrototype prototype)
private bool CanRecycle(IEntity entity, [NotNullWhen(true)] out ConstructionPrototype? prototype)
{
prototype = null;
@@ -100,7 +101,7 @@ namespace Content.Server.GameObjects.Components.Recycling
private bool CanRun()
{
if (Owner.TryGetComponent(out PowerReceiverComponent receiver) &&
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver) &&
!receiver.Powered)
{
return false;
@@ -121,7 +122,7 @@ namespace Content.Server.GameObjects.Components.Recycling
return false;
}
if (!entity.TryGetComponent(out IPhysicsComponent physics) ||
if (!entity.TryGetComponent(out IPhysicsComponent? physics) ||
physics.Anchored)
{
return false;
@@ -165,7 +166,7 @@ namespace Content.Server.GameObjects.Components.Recycling
continue;
}
if (entity.TryGetComponent(out IPhysicsComponent physics))
if (entity.TryGetComponent(out IPhysicsComponent? physics))
{
var controller = physics.EnsureController<ConveyedController>();
controller.Move(direction, frameTime, entity.Transform.WorldPosition - Owner.Transform.WorldPosition);

View File

@@ -47,7 +47,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
/// <param name="handName">The name of the hand to get.</param>
/// <param name="item">The item in the held, null if no item is held</param>
/// <returns>Whether it was holding an item</returns>
bool TryGetItem(string handName, [MaybeNullWhen(false)] out ItemComponent item);
bool TryGetItem(string handName, [NotNullWhen(true)] out ItemComponent? item);
/// <summary>
/// Gets item held by the current active hand
@@ -102,7 +102,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
/// <returns>
/// true if the entity is held, false otherwise
/// </returns>
bool TryHand(IEntity entity, [MaybeNullWhen(false)] out string handName);
bool TryHand(IEntity entity, [NotNullWhen(true)] out string? handName);
/// <summary>
/// Drops the item contained in the slot to the same position as our entity.

View File

@@ -177,7 +177,7 @@ namespace Content.Shared.GameObjects.EntitySystems
moverComp.SetSprinting(subTick, walking);
}
private static bool TryGetAttachedComponent<T>(ICommonSession? session, [MaybeNullWhen(false)] out T component)
private static bool TryGetAttachedComponent<T>(ICommonSession? session, [NotNullWhen(true)] out T? component)
where T : class, IComponent
{
component = default;