refactor: use nullable annotations instead of CanBeNullAttribute

This commit is contained in:
goat 2021-08-22 23:06:46 +02:00
parent 3c5c7fbc80
commit 010a4972cd
No known key found for this signature in database
GPG key ID: F18F057873895461
14 changed files with 33 additions and 62 deletions

View file

@ -45,8 +45,7 @@ namespace Dalamud.Configuration
/// </summary> /// </summary>
/// <param name="pluginName">Plugin name.</param> /// <param name="pluginName">Plugin name.</param>
/// <returns>Plugin configuration.</returns> /// <returns>Plugin configuration.</returns>
[CanBeNull] public IPluginConfiguration? Load(string pluginName)
public IPluginConfiguration Load(string pluginName)
{ {
var path = this.GetConfigFile(pluginName); var path = this.GetConfigFile(pluginName);

View file

@ -66,8 +66,7 @@ namespace Dalamud.Game.ClientState.Buddy
/// <summary> /// <summary>
/// Gets the active companion buddy. /// Gets the active companion buddy.
/// </summary> /// </summary>
[CanBeNull] public BuddyMember? CompanionBuddy
public BuddyMember CompanionBuddy
{ {
get get
{ {
@ -79,8 +78,7 @@ namespace Dalamud.Game.ClientState.Buddy
/// <summary> /// <summary>
/// Gets the active pet buddy. /// Gets the active pet buddy.
/// </summary> /// </summary>
[CanBeNull] public BuddyMember? PetBuddy
public BuddyMember PetBuddy
{ {
get get
{ {
@ -103,8 +101,7 @@ namespace Dalamud.Game.ClientState.Buddy
/// </summary> /// </summary>
/// <param name="index">Spawn index.</param> /// <param name="index">Spawn index.</param>
/// <returns>A <see cref="BuddyMember"/> at the specified spawn index.</returns> /// <returns>A <see cref="BuddyMember"/> at the specified spawn index.</returns>
[CanBeNull] public BuddyMember? this[int index]
public BuddyMember this[int index]
{ {
get get
{ {
@ -149,8 +146,7 @@ namespace Dalamud.Game.ClientState.Buddy
/// </summary> /// </summary>
/// <param name="address">The address of the buddy in memory.</param> /// <param name="address">The address of the buddy in memory.</param>
/// <returns><see cref="BuddyMember"/> object containing the requested data.</returns> /// <returns><see cref="BuddyMember"/> object containing the requested data.</returns>
[CanBeNull] public BuddyMember? CreateBuddyMemberReference(IntPtr address)
public BuddyMember CreateBuddyMemberReference(IntPtr address)
{ {
var clientState = Service<ClientState>.Get(); var clientState = Service<ClientState>.Get();

View file

@ -37,8 +37,7 @@ namespace Dalamud.Game.ClientState.Buddy
/// <remarks> /// <remarks>
/// This iterates the actor table, it should be used with care. /// This iterates the actor table, it should be used with care.
/// </remarks> /// </remarks>
[CanBeNull] public GameObject? GameObject => Service<ObjectTable>.Get().SearchByID(this.ObjectId);
public GameObject GameObject => Service<ObjectTable>.Get().SearchByID(this.ObjectId);
/// <summary> /// <summary>
/// Gets the current health of this buddy. /// Gets the current health of this buddy.

View file

@ -109,8 +109,7 @@ namespace Dalamud.Game.ClientState
/// <summary> /// <summary>
/// Gets the local player character, if one is present. /// Gets the local player character, if one is present.
/// </summary> /// </summary>
[CanBeNull] public PlayerCharacter? LocalPlayer => Service<ObjectTable>.Get()[0] as PlayerCharacter;
public PlayerCharacter LocalPlayer => Service<ObjectTable>.Get()[0] as PlayerCharacter;
/// <summary> /// <summary>
/// Gets the content ID of the local character. /// Gets the content ID of the local character.

View file

@ -75,8 +75,7 @@ namespace Dalamud.Game.ClientState.Fates
/// </summary> /// </summary>
/// <param name="index">Spawn index.</param> /// <param name="index">Spawn index.</param>
/// <returns>A <see cref="Fate"/> at the specified spawn index.</returns> /// <returns>A <see cref="Fate"/> at the specified spawn index.</returns>
[CanBeNull] public Fate? this[int index]
public Fate this[int index]
{ {
get get
{ {
@ -108,8 +107,7 @@ namespace Dalamud.Game.ClientState.Fates
/// </summary> /// </summary>
/// <param name="offset">The offset of the actor in memory.</param> /// <param name="offset">The offset of the actor in memory.</param>
/// <returns><see cref="Fate"/> object containing requested data.</returns> /// <returns><see cref="Fate"/> object containing requested data.</returns>
[CanBeNull] internal Fate? CreateFateReference(IntPtr offset)
internal unsafe Fate CreateFateReference(IntPtr offset)
{ {
var clientState = Service<ClientState>.Get(); var clientState = Service<ClientState>.Get();

View file

@ -49,8 +49,7 @@ namespace Dalamud.Game.ClientState.Objects
/// </summary> /// </summary>
/// <param name="index">Spawn index.</param> /// <param name="index">Spawn index.</param>
/// <returns>An <see cref="GameObject"/> at the specified spawn index.</returns> /// <returns>An <see cref="GameObject"/> at the specified spawn index.</returns>
[CanBeNull] public GameObject? this[int index]
public GameObject this[int index]
{ {
get get
{ {
@ -64,8 +63,7 @@ namespace Dalamud.Game.ClientState.Objects
/// </summary> /// </summary>
/// <param name="objectID">Object ID to find.</param> /// <param name="objectID">Object ID to find.</param>
/// <returns>A game object or null.</returns> /// <returns>A game object or null.</returns>
[CanBeNull] public GameObject? SearchByID(uint objectID)
public GameObject SearchByID(uint objectID)
{ {
foreach (var obj in this) foreach (var obj in this)
{ {
@ -97,8 +95,7 @@ namespace Dalamud.Game.ClientState.Objects
/// </summary> /// </summary>
/// <param name="address">The address of the object in memory.</param> /// <param name="address">The address of the object in memory.</param>
/// <returns><see cref="GameObject"/> object or inheritor containing the requested data.</returns> /// <returns><see cref="GameObject"/> object or inheritor containing the requested data.</returns>
[CanBeNull] public unsafe GameObject? CreateObjectReference(IntPtr address)
public unsafe GameObject CreateObjectReference(IntPtr address)
{ {
var clientState = Service<ClientState>.Get(); var clientState = Service<ClientState>.Get();

View file

@ -33,8 +33,7 @@ namespace Dalamud.Game.ClientState.Objects
/// <summary> /// <summary>
/// Gets or sets the current target. /// Gets or sets the current target.
/// </summary> /// </summary>
[CanBeNull] public GameObject? Target
public GameObject Target
{ {
get => Service<ObjectTable>.Get().CreateObjectReference((IntPtr)Struct->Target); get => Service<ObjectTable>.Get().CreateObjectReference((IntPtr)Struct->Target);
set => this.SetTarget(value); set => this.SetTarget(value);
@ -43,8 +42,7 @@ namespace Dalamud.Game.ClientState.Objects
/// <summary> /// <summary>
/// Gets or sets the mouseover target. /// Gets or sets the mouseover target.
/// </summary> /// </summary>
[CanBeNull] public GameObject? MouseOverTarget
public GameObject MouseOverTarget
{ {
get => Service<ObjectTable>.Get().CreateObjectReference((IntPtr)Struct->MouseOverTarget); get => Service<ObjectTable>.Get().CreateObjectReference((IntPtr)Struct->MouseOverTarget);
set => this.SetMouseOverTarget(value); set => this.SetMouseOverTarget(value);
@ -53,8 +51,7 @@ namespace Dalamud.Game.ClientState.Objects
/// <summary> /// <summary>
/// Gets or sets the focus target. /// Gets or sets the focus target.
/// </summary> /// </summary>
[CanBeNull] public GameObject? FocusTarget
public GameObject FocusTarget
{ {
get => Service<ObjectTable>.Get().CreateObjectReference((IntPtr)Struct->FocusTarget); get => Service<ObjectTable>.Get().CreateObjectReference((IntPtr)Struct->FocusTarget);
set => this.SetFocusTarget(value); set => this.SetFocusTarget(value);
@ -63,8 +60,7 @@ namespace Dalamud.Game.ClientState.Objects
/// <summary> /// <summary>
/// Gets or sets the previous target. /// Gets or sets the previous target.
/// </summary> /// </summary>
[CanBeNull] public GameObject? PreviousTarget
public GameObject PreviousTarget
{ {
get => Service<ObjectTable>.Get().CreateObjectReference((IntPtr)Struct->PreviousTarget); get => Service<ObjectTable>.Get().CreateObjectReference((IntPtr)Struct->PreviousTarget);
set => this.SetPreviousTarget(value); set => this.SetPreviousTarget(value);
@ -73,8 +69,7 @@ namespace Dalamud.Game.ClientState.Objects
/// <summary> /// <summary>
/// Gets or sets the soft target. /// Gets or sets the soft target.
/// </summary> /// </summary>
[CanBeNull] public GameObject? SoftTarget
public GameObject SoftTarget
{ {
get => Service<ObjectTable>.Get().CreateObjectReference((IntPtr)Struct->SoftTarget); get => Service<ObjectTable>.Get().CreateObjectReference((IntPtr)Struct->SoftTarget);
set => this.SetSoftTarget(value); set => this.SetSoftTarget(value);
@ -86,31 +81,31 @@ namespace Dalamud.Game.ClientState.Objects
/// Sets the current target. /// Sets the current target.
/// </summary> /// </summary>
/// <param name="actor">Actor to target.</param> /// <param name="actor">Actor to target.</param>
public void SetTarget(GameObject actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero); public void SetTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero);
/// <summary> /// <summary>
/// Sets the mouseover target. /// Sets the mouseover target.
/// </summary> /// </summary>
/// <param name="actor">Actor to target.</param> /// <param name="actor">Actor to target.</param>
public void SetMouseOverTarget(GameObject actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero); public void SetMouseOverTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero);
/// <summary> /// <summary>
/// Sets the focus target. /// Sets the focus target.
/// </summary> /// </summary>
/// <param name="actor">Actor to target.</param> /// <param name="actor">Actor to target.</param>
public void SetFocusTarget(GameObject actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero); public void SetFocusTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero);
/// <summary> /// <summary>
/// Sets the previous target. /// Sets the previous target.
/// </summary> /// </summary>
/// <param name="actor">Actor to target.</param> /// <param name="actor">Actor to target.</param>
public void SetPreviousTarget(GameObject actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero); public void SetPreviousTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero);
/// <summary> /// <summary>
/// Sets the soft target. /// Sets the soft target.
/// </summary> /// </summary>
/// <param name="actor">Actor to target.</param> /// <param name="actor">Actor to target.</param>
public void SetSoftTarget(GameObject actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero); public void SetSoftTarget(GameObject? actor) => this.SetTarget(actor?.Address ?? IntPtr.Zero);
/// <summary> /// <summary>
/// Sets the current target. /// Sets the current target.

View file

@ -157,8 +157,7 @@ namespace Dalamud.Game.ClientState.Objects.Types
/// <remarks> /// <remarks>
/// This iterates the actor table, it should be used with care. /// This iterates the actor table, it should be used with care.
/// </remarks> /// </remarks>
[CanBeNull] public virtual GameObject? TargetObject => Service<ObjectTable>.Get().SearchByID(this.TargetObjectId);
public virtual GameObject TargetObject => Service<ObjectTable>.Get().SearchByID(this.TargetObjectId);
/// <summary> /// <summary>
/// Gets the underlying structure. /// Gets the underlying structure.

View file

@ -72,8 +72,7 @@ namespace Dalamud.Game.ClientState.Party
/// </summary> /// </summary>
/// <param name="index">Spawn index.</param> /// <param name="index">Spawn index.</param>
/// <returns>A <see cref="PartyMember"/> at the specified spawn index.</returns> /// <returns>A <see cref="PartyMember"/> at the specified spawn index.</returns>
[CanBeNull] public PartyMember? this[int index]
public PartyMember this[int index]
{ {
get get
{ {
@ -112,8 +111,7 @@ namespace Dalamud.Game.ClientState.Party
/// </summary> /// </summary>
/// <param name="address">The address of the party member in memory.</param> /// <param name="address">The address of the party member in memory.</param>
/// <returns>The party member object containing the requested data.</returns> /// <returns>The party member object containing the requested data.</returns>
[CanBeNull] public PartyMember? CreatePartyMemberReference(IntPtr address)
public PartyMember CreatePartyMemberReference(IntPtr address)
{ {
var clientState = Service<ClientState>.Get(); var clientState = Service<ClientState>.Get();
@ -144,8 +142,7 @@ namespace Dalamud.Game.ClientState.Party
/// </summary> /// </summary>
/// <param name="address">The address of the alliance member in memory.</param> /// <param name="address">The address of the alliance member in memory.</param>
/// <returns>The party member object containing the requested data.</returns> /// <returns>The party member object containing the requested data.</returns>
[CanBeNull] public PartyMember? CreateAllianceMemberReference(IntPtr address)
public PartyMember CreateAllianceMemberReference(IntPtr address)
{ {
var clientState = Service<ClientState>.Get(); var clientState = Service<ClientState>.Get();

View file

@ -56,8 +56,7 @@ namespace Dalamud.Game.ClientState.Party
/// <remarks> /// <remarks>
/// This iterates the actor table, it should be used with care. /// This iterates the actor table, it should be used with care.
/// </remarks> /// </remarks>
[CanBeNull] public GameObject? GameObject => Service<ObjectTable>.Get().SearchByID(this.ObjectId);
public GameObject GameObject => Service<ObjectTable>.Get().SearchByID(this.ObjectId);
/// <summary> /// <summary>
/// Gets the current HP of this party member. /// Gets the current HP of this party member.

View file

@ -62,8 +62,7 @@ namespace Dalamud.Game.ClientState.Statuses
/// <remarks> /// <remarks>
/// This iterates the actor table, it should be used with care. /// This iterates the actor table, it should be used with care.
/// </remarks> /// </remarks>
[CanBeNull] public GameObject? SourceObject => Service<ObjectTable>.Get().SearchByID(this.SourceID);
public GameObject SourceObject => Service<ObjectTable>.Get().SearchByID(this.SourceID);
private FFXIVClientStructs.FFXIV.Client.Game.Status* Struct => (FFXIVClientStructs.FFXIV.Client.Game.Status*)this.Address; private FFXIVClientStructs.FFXIV.Client.Game.Status* Struct => (FFXIVClientStructs.FFXIV.Client.Game.Status*)this.Address;
} }

View file

@ -65,8 +65,7 @@ namespace Dalamud.Game.ClientState.Statuses
/// </summary> /// </summary>
/// <param name="index">Status Index.</param> /// <param name="index">Status Index.</param>
/// <returns>The status at the specified index.</returns> /// <returns>The status at the specified index.</returns>
[CanBeNull] public Status? this[int index]
public Status this[int index]
{ {
get get
{ {
@ -96,8 +95,7 @@ namespace Dalamud.Game.ClientState.Statuses
/// </summary> /// </summary>
/// <param name="address">The address of the status effect in memory.</param> /// <param name="address">The address of the status effect in memory.</param>
/// <returns>The status object containing the requested data.</returns> /// <returns>The status object containing the requested data.</returns>
[CanBeNull] public Status? CreateStatusReference(IntPtr address)
public Status CreateStatusReference(IntPtr address)
{ {
var clientState = Service<ClientState>.Get(); var clientState = Service<ClientState>.Get();

View file

@ -702,7 +702,6 @@ namespace Dalamud.Plugin.Internal
/// <param name="notify">Whether to notify that installed plugins have changed afterwards.</param> /// <param name="notify">Whether to notify that installed plugins have changed afterwards.</param>
/// <param name="dryRun">Whether or not to actually perform the update, or just indicate success.</param> /// <param name="dryRun">Whether or not to actually perform the update, or just indicate success.</param>
/// <returns>The status of the update.</returns> /// <returns>The status of the update.</returns>
[CanBeNull]
public async Task<PluginUpdateStatus?> UpdateSinglePluginAsync(AvailablePluginUpdate metadata, bool notify, bool dryRun) public async Task<PluginUpdateStatus?> UpdateSinglePluginAsync(AvailablePluginUpdate metadata, bool notify, bool dryRun)
{ {
var plugin = metadata.InstalledPlugin; var plugin = metadata.InstalledPlugin;

View file

@ -75,8 +75,7 @@ namespace Dalamud
/// <param name="address">The address to read from.</param> /// <param name="address">The address to read from.</param>
/// <param name="count">The length of the array.</param> /// <param name="count">The length of the array.</param>
/// <returns>An array of the read objects, or null if any entry of the array failed to read.</returns> /// <returns>An array of the read objects, or null if any entry of the array failed to read.</returns>
[CanBeNull] public static T[]? Read<T>(IntPtr address, int count) where T : struct
public static T[] Read<T>(IntPtr address, int count) where T : struct
{ {
var size = SizeOf<T>(); var size = SizeOf<T>();
if (!ReadBytes(address, count * size, out var buffer)) if (!ReadBytes(address, count * size, out var buffer))
@ -132,8 +131,7 @@ namespace Dalamud
/// <param name="address">The address to read from.</param> /// <param name="address">The address to read from.</param>
/// <param name="maxLength">The maximum length of the string.</param> /// <param name="maxLength">The maximum length of the string.</param>
/// <returns>The read string, or null in case the read was not successful.</returns> /// <returns>The read string, or null in case the read was not successful.</returns>
[CanBeNull] public static string? ReadString(IntPtr address, int maxLength = 256)
public static string ReadString(IntPtr address, int maxLength = 256)
{ {
return ReadString(address, Encoding.UTF8, maxLength); return ReadString(address, Encoding.UTF8, maxLength);
} }
@ -150,8 +148,7 @@ namespace Dalamud
/// <param name="encoding">The encoding to use to decode the string.</param> /// <param name="encoding">The encoding to use to decode the string.</param>
/// <param name="maxLength">The maximum length of the string.</param> /// <param name="maxLength">The maximum length of the string.</param>
/// <returns>The read string, or null in case the read was not successful.</returns> /// <returns>The read string, or null in case the read was not successful.</returns>
[CanBeNull] public static string? ReadString(IntPtr address, Encoding encoding, int maxLength = 256)
public static string ReadString(IntPtr address, Encoding encoding, int maxLength = 256)
{ {
if (!ReadBytes(address, maxLength, out var buffer)) if (!ReadBytes(address, maxLength, out var buffer))
return null; return null;