Skip to content

Commit

Permalink
Add PathReference and ProvidesContext annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Emik03 committed Nov 30, 2022
1 parent ed5f50b commit 771223e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion wawa.Editors/Source/Internals/WawaEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sealed class WawaEditor : Editor
#pragma warning restore CA1812
{
/// <summary>The name of this library.</summary>
[NotNull]
[NotNull, ProvidesContext]
internal const string This = $"{Wawa}Editors";

[NotNull]
Expand Down
1 change: 1 addition & 0 deletions wawa.Extensions/Source/KMExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Wawa.Extensions;
[CLSCompliant(false), PublicAPI]
public static class KMExtensions
{
[ProvidesContext]
static readonly bool s_isKtane = !Application.isEditor;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion wawa.IO/Source/Config{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Config([NotNull] string fileName)
public bool HasRead { [Pure] get; internal set; }

/// <summary>Gets the path of the file to read and write.</summary>
[JsonIgnore, NotNull]
[JsonIgnore, NotNull, ProvidesContext]
public string FilePath { [Pure] get; }

/// <summary>Determines whether both instances are both <see langword="null"/> or both instances.</summary>
Expand Down
5 changes: 3 additions & 2 deletions wawa.IO/Source/ModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ left is null
/// <param name="right">The right-hand side.</param>
/// <returns>The value <see langword="true"/> if both instances do not contain the same values.</returns>
[Pure]
public static bool operator !=([AllowNull, CanBeNull] ModInfo left, [AllowNull, CanBeNull] ModInfo right) => !(left == right);
public static bool operator !=([AllowNull, CanBeNull] ModInfo left, [AllowNull, CanBeNull] ModInfo right) =>
!(left == right);

/// <summary>Tries to deserialize the parameter as <see cref="ModInfo"/>.</summary>
/// <param name="contents">The contents to a modInfo.json.</param>
Expand All @@ -82,7 +83,7 @@ public static Maybe<ModInfo> Deserialize([AllowNull, CanBeNull] string contents)
/// of <see cref="ModInfo"/> which has the information of the file if the serialization is successful,
/// or no value if the file couldn't be read/located.
/// </returns>
public static Maybe<ModInfo> ReadThenDeserialize([AllowNull, CanBeNull] string path) =>
public static Maybe<ModInfo> ReadThenDeserialize([AllowNull, CanBeNull, PathReference] string path) =>
File.Exists(path)
? path?.SuppressIO(File.ReadAllText, true)?.SuppressIO(JsonConvert.DeserializeObject<ModInfo>, true)
: default;
Expand Down
18 changes: 12 additions & 6 deletions wawa.IO/Source/PathFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ public static Maybe<string> GetDirectory([AllowNull, CanBeNull] string assembly
/// A <see cref="Maybe{T}" />, consisting of either folder <see cref="string" /> of the absolute directory
/// of the file if the mod directory and file were found, or <see langword="default" />.
/// </returns>
public static Maybe<string> GetFile([NotNull] string file, [AllowNull, CanBeNull] string assembly = null) =>
public static Maybe<string> GetFile(
[NotNull, PathReference] string file,
[AllowNull, CanBeNull] string assembly = null
) =>
new
{
file,
Expand Down Expand Up @@ -108,7 +111,10 @@ public static Maybe<ModInfo> GetModInfo([AllowNull, CanBeNull] string assembly =
/// from the assets in the file specified, or <see langword="default" /> in the event of an error.
/// </returns>
[CLSCompliant(false)]
public static Maybe<T[]> GetAssets<T>([NotNull] string file, [AllowNull, CanBeNull] string assembly = null)
public static Maybe<T[]> GetAssets<T>(
[NotNull, PathReference] string file,
[AllowNull, CanBeNull] string assembly = null
)
where T : Object =>
new
{
Expand All @@ -132,7 +138,7 @@ public static Maybe<T[]> GetAssets<T>([NotNull] string file, [AllowNull, CanBeNu
/// The value <see langword="true" /> if copying the file was successful, otherwise <see langword="false" />.
/// </returns>
public static Maybe<T> GetUnmanaged<T>(
[NotNull] string file,
[NotNull, PathReference] string file,
[NotNull] string method,
[AllowNull, CanBeNull] string assembly = null
)
Expand All @@ -150,12 +156,12 @@ public static Maybe<T> GetUnmanaged<T>(
);

[NotNull]
static string Join([NotNull] this string dir, [NotNull] in string folder) =>
static string Join([NotNull, PathReference] this string dir, [NotNull, PathReference] in string folder) =>
Path.Combine(dir, folder) is var first && Directory.Exists(first) ? first : dir;

[CanBeNull]
[return: AllowNull]
static string FindLibrary([NotNull] this string file, [NotNull] in string dir)
static string FindLibrary([NotNull, PathReference] this string file, [NotNull, PathReference] in string dir)
{
var architecture = Application.platform switch
{
Expand Down Expand Up @@ -238,7 +244,7 @@ [NotNull] in Type[] parameters

[CanBeNull]
[return: AllowNull]
static T CreateUnmanagedMethod<T>([NotNull] this string dllName, [NotNull] in string name)
static T CreateUnmanagedMethod<T>([NotNull, PathReference] this string dllName, [NotNull] in string name)
where T : Delegate
{
if (typeof(T).GetMethod(nameof(Action<T>.Invoke)) is not { } invoke)
Expand Down
2 changes: 1 addition & 1 deletion wawa.Optionals/Source/Maybe{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public bool IsNone
public bool IsSome { [Pure] get; }

/// <summary>Gets the value that is encapsulated. This value returned may be <see langword="null" />.</summary>
[AllowNull, CanBeNull]
[AllowNull, CanBeNull, ProvidesContext]
public T Value { [Pure] get; }

/// <summary>Converts the <typeparamref name="T" /> to a <see langword="new" /> <see cref="Maybe{T}" />.</summary>
Expand Down
2 changes: 1 addition & 1 deletion wawa.TwitchPlays/Source/Twitch{TMod}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const string
[CanBeNull]
static string s_autoImplementedHelp;

[CanBeNull]
[CanBeNull, ProvidesContext]
static IEnumerable<CommandInfo> s_commands;

bool _isPrintingYields;
Expand Down
2 changes: 1 addition & 1 deletion wawa.Unity/Source/CachedBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Wawa.Unity;
[CLSCompliant(false), PublicAPI]
public abstract class CachedBehaviour : MonoBehaviour
{
[NotNull]
[NotNull, ProvidesContext]
readonly Dictionary<Type, object> _cache = new();

/// <summary>Clears the cache.</summary>
Expand Down

0 comments on commit 771223e

Please sign in to comment.