Skip to content

Commit 074c8f0

Browse files
author
Nicolas Musset
committed
[Core.Design] Annotate elements with nullability attributes.
# Original commit: '5755478a1df64dc6bb91d1fb30c09bd6a37e0c70'
1 parent 73625a8 commit 074c8f0

File tree

73 files changed

+620
-492
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+620
-492
lines changed

sources/common/core/SiliconStudio.Core.Design/Collections/HybridDictionary.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Collections;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using SiliconStudio.Core.Annotations;
8+
using SiliconStudio.Core.Extensions;
79

810
namespace SiliconStudio.Core.Collections
911
{
@@ -29,7 +31,7 @@ public HybridDictionary(IEqualityComparer<TKey> comparer) : this(0, comparer)
2931
{
3032
}
3133

32-
public HybridDictionary(IDictionary<TKey, TValue> dictionary) : this(dictionary, null)
34+
public HybridDictionary([NotNull] IDictionary<TKey, TValue> dictionary) : this(dictionary, null)
3335
{
3436
}
3537

@@ -46,10 +48,10 @@ public HybridDictionary(int capacity, IEqualityComparer<TKey> comparer)
4648
list = new List<KeyValuePair<TKey, TValue>>(capacity);
4749
}
4850
}
49-
public HybridDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer) : this(dictionary?.Count ?? 0, comparer)
51+
public HybridDictionary([NotNull] IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer)
52+
: this(dictionary.SafeArgument(nameof(dictionary)).Count, comparer)
5053
{
51-
if (dictionary == null) throw new ArgumentNullException(nameof(dictionary));
52-
foreach (KeyValuePair<TKey, TValue> keyValuePair in dictionary)
54+
foreach (var keyValuePair in dictionary)
5355
InternalAdd(keyValuePair);
5456
}
5557

@@ -194,7 +196,7 @@ public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
194196
}
195197
}
196198

197-
public bool ContainsKey(TKey key)
199+
public bool ContainsKey([NotNull] TKey key)
198200
{
199201
if (key == null) throw new ArgumentNullException(nameof(key));
200202
if (list != null)
@@ -257,7 +259,7 @@ private void Update(TKey key, TValue value)
257259
valueCollection = null;
258260
if (list != null)
259261
{
260-
for (int i = 0; i < list.Count; i++)
262+
for (var i = 0; i < list.Count; i++)
261263
{
262264
var kvp = list[i];
263265
if (keyComparer.Equals(kvp.Key, key))

sources/common/core/SiliconStudio.Core.Design/Extensions/AnonymousEqualityComparer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public AnonymousEqualityComparer([NotNull] Func<T, T, bool> equals, [NotNull] Fu
2828
this.equals = equals;
2929
this.getHashCode = getHashCode;
3030
}
31-
31+
3232
/// <summary>
3333
/// Initializes a new instance of the <see cref="AnonymousEqualityComparer{T}"/> class using the default <see cref="object.GetHashCode"/> method to get hash codes.
3434
/// </summary>

sources/common/core/SiliconStudio.Core.Design/Extensions/ExceptionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static void ExtractStackTrace([NotNull] StringBuilder sb, [NotNull] Exce
106106
{
107107
if (exception.StackTrace == null)
108108
return;
109-
109+
110110
var indentString = "".PadLeft(indent);
111111
var stackTraceArray = exception.StackTrace.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
112112
foreach (var line in maxLines > 0 ? stackTraceArray.Take(maxLines) : stackTraceArray)

sources/common/core/SiliconStudio.Core.Design/Extensions/ProcessExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using System;
2-
using System.Collections.Generic;
1+
// Copyright (c) 2014-2017 Silicon Studio Corp. All rights reserved. (https://www.siliconstudio.co.jp)
2+
// See LICENSE.md for full license information.
3+
using System;
34
using System.Diagnostics;
4-
using System.Linq;
5-
using System.Text;
65
using System.Threading;
76
using System.Threading.Tasks;
7+
using SiliconStudio.Core.Annotations;
88

99
namespace SiliconStudio.Core.Extensions
1010
{
@@ -17,7 +17,7 @@ public static class ProcessExtensions
1717
/// <param name="cancellationToken">A cancellation token. If invoked, the task will return
1818
/// immediately as cancelled.</param>
1919
/// <returns>A Task representing waiting for the process to end.</returns>
20-
public static Task WaitForExitAsync(this Process process, CancellationToken cancellationToken = default(CancellationToken))
20+
public static Task WaitForExitAsync([NotNull] this Process process, CancellationToken cancellationToken = default(CancellationToken))
2121
{
2222
// Source: https://stackoverflow.com/questions/139593/processstartinfo-hanging-on-waitforexit-why/39872058#39872058
2323
process.EnableRaisingEvents = true;

sources/common/core/SiliconStudio.Core.Design/IDestroyable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace SiliconStudio.Core
88
/// </summary>
99
/// <remarks>
1010
/// Class implementing both <see cref="IDestroyable"/> and <see cref="System.IDisposable"/> should call <see cref="Destroy"/>
11-
/// from the <see cref="System.IDisposable.Dispose"/> method when appropriate.
11+
/// from the <see cref="System.IDisposable.Dispose"/> method when appropriate.
1212
/// </remarks>
1313
public interface IDestroyable
1414
{

sources/common/core/SiliconStudio.Core.Design/IO/UDirectory.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// See LICENSE.md for full license information.
33
using System;
44
using System.ComponentModel;
5+
using SiliconStudio.Core.Annotations;
56

67
namespace SiliconStudio.Core.IO
78
{
@@ -30,14 +31,15 @@ public UDirectory(string directoryPath) : base(directoryPath, true)
3031
{
3132
}
3233

33-
internal UDirectory(string fullPath, StringSpan driveSpan, StringSpan directorySpan) : base(fullPath, driveSpan, directorySpan)
34+
internal UDirectory([NotNull] string fullPath, StringSpan driveSpan, StringSpan directorySpan) : base(fullPath, driveSpan, directorySpan)
3435
{
3536
}
3637

3738
/// <summary>
3839
/// Gets the name of the directory.
3940
/// </summary>
4041
/// <returns>The name of the directory.</returns>
42+
[NotNull]
4143
public string GetDirectoryName()
4244
{
4345
var index = FullPath.IndexOfReverse(DirectorySeparatorChar);
@@ -49,7 +51,7 @@ public string GetDirectoryName()
4951
/// </summary>
5052
/// <param name="anchorDirectory">The anchor directory.</param>
5153
/// <returns>A relative path of this instance to the anchor directory.</returns>
52-
public new UDirectory MakeRelative(UDirectory anchorDirectory)
54+
public new UDirectory MakeRelative([NotNull] UDirectory anchorDirectory)
5355
{
5456
return (UDirectory)base.MakeRelative(anchorDirectory);
5557
}
@@ -59,6 +61,7 @@ public string GetDirectoryName()
5961
/// </summary>
6062
/// <param name="fullPath">The full path.</param>
6163
/// <returns>The result of the conversion.</returns>
64+
[CanBeNull]
6265
public static implicit operator UDirectory(string fullPath)
6366
{
6467
return fullPath != null ? new UDirectory(fullPath) : null;
@@ -70,7 +73,8 @@ public static implicit operator UDirectory(string fullPath)
7073
/// <param name="leftPath">The left path.</param>
7174
/// <param name="rightPath">The right path.</param>
7275
/// <returns>The combination of both paths.</returns>
73-
public static UDirectory Combine(UDirectory leftPath, UDirectory rightPath)
76+
[NotNull]
77+
public static UDirectory Combine([NotNull] UDirectory leftPath, [NotNull] UDirectory rightPath)
7478
{
7579
return UPath.Combine(leftPath, rightPath);
7680
}
@@ -80,7 +84,7 @@ public static UDirectory Combine(UDirectory leftPath, UDirectory rightPath)
8084
/// </summary>
8185
/// <param name="path">The path.</param>
8286
/// <returns><c>true</c> if this directory contains the specified path; otherwise, <c>false</c>.</returns>
83-
public bool Contains(UPath path)
87+
public bool Contains([NotNull] UPath path)
8488
{
8589
if (path == null) throw new ArgumentNullException(nameof(path));
8690
return path.FullPath.StartsWith(FullPath, StringComparison.OrdinalIgnoreCase) && path.FullPath.Length > FullPath.Length && path.FullPath[FullPath.Length] == DirectorySeparatorChar;

sources/common/core/SiliconStudio.Core.Design/IO/UFile.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// See LICENSE.md for full license information.
33
using System;
44
using System.ComponentModel;
5+
using SiliconStudio.Core.Annotations;
56

67
namespace SiliconStudio.Core.IO
78
{
@@ -25,6 +26,7 @@ public UFile(string filePath)
2526
/// Gets the name of the file with its extension. Can be null.
2627
/// </summary>
2728
/// <returns>The name.</returns>
29+
[CanBeNull]
2830
public string GetFileName()
2931
{
3032
var span = NameSpan;
@@ -34,13 +36,14 @@ public string GetFileName()
3436
}
3537
return span.IsValid ? FullPath.Substring(span) : null;
3638

37-
39+
3840
}
3941

4042
/// <summary>
4143
/// Gets the name of the file without its extension.
4244
/// </summary>
4345
/// <value>The name of file.</value>
46+
[CanBeNull]
4447
public string GetFileNameWithoutExtension()
4548
{
4649
return NameSpan.IsValid ? FullPath.Substring(NameSpan) : null;
@@ -50,6 +53,7 @@ public string GetFileNameWithoutExtension()
5053
/// Gets the file path (<see cref="UPath.GetDirectory()"/> + '/' + <see cref="UFile.GetFileName()"/>) with the extension or drive. Can be an null if no filepath.
5154
/// </summary>
5255
/// <returns>The path.</returns>
56+
[CanBeNull]
5357
public string GetDirectoryAndFileName()
5458
{
5559
var span = DirectorySpan;
@@ -68,6 +72,7 @@ public string GetDirectoryAndFileName()
6872
/// Gets the file path (<see cref="UPath.GetDirectory()"/> + '/' + <see cref="UFile.GetFileName()"/>) without the extension or drive. Can be an null if no filepath.
6973
/// </summary>
7074
/// <returns>The path.</returns>
75+
[CanBeNull]
7176
public string GetDirectoryAndFileNameWithoutExtension()
7277
{
7378
var span = DirectorySpan;
@@ -82,6 +87,7 @@ public string GetDirectoryAndFileNameWithoutExtension()
8287
/// Gets the extension of the file. Can be null.
8388
/// </summary>
8489
/// <returns>The extension.</returns>
90+
[CanBeNull]
8591
public string GetFileExtension()
8692
{
8793
return ExtensionSpan.IsValid ? FullPath.Substring(ExtensionSpan) : null;
@@ -91,6 +97,7 @@ public string GetFileExtension()
9197
/// Gets the name of the file with its extension.
9298
/// </summary>
9399
/// <value>The name of file.</value>
100+
[CanBeNull]
94101
public string GetFullPathWithoutExtension()
95102
{
96103
var span = new StringSpan(0, FullPath.Length);
@@ -107,7 +114,8 @@ public string GetFullPathWithoutExtension()
107114
/// <param name="leftPath">The left path.</param>
108115
/// <param name="rightPath">The right path.</param>
109116
/// <returns>The combination of both paths.</returns>
110-
public static UFile Combine(UDirectory leftPath, UFile rightPath)
117+
[NotNull]
118+
public static UFile Combine([NotNull] UDirectory leftPath, [NotNull] UFile rightPath)
111119
{
112120
return UPath.Combine(leftPath, rightPath);
113121
}
@@ -117,7 +125,7 @@ public static UFile Combine(UDirectory leftPath, UFile rightPath)
117125
/// </summary>
118126
/// <param name="anchorDirectory">The anchor directory.</param>
119127
/// <returns>A relative path of this instance to the anchor directory.</returns>
120-
public new UFile MakeRelative(UDirectory anchorDirectory)
128+
public new UFile MakeRelative([NotNull] UDirectory anchorDirectory)
121129
{
122130
return (UFile)base.MakeRelative(anchorDirectory);
123131
}
@@ -127,9 +135,9 @@ public static UFile Combine(UDirectory leftPath, UFile rightPath)
127135
/// </summary>
128136
/// <param name="path">The path.</param>
129137
/// <returns><c>true</c> if the specified path is a valid <see cref="UFile"/>; otherwise, <c>false</c>.</returns>
130-
public new static bool IsValid(string path)
138+
public new static bool IsValid([NotNull] string path)
131139
{
132-
if (path == null) throw new ArgumentNullException("path");
140+
if (path == null) throw new ArgumentNullException(nameof(path));
133141
if (!UPath.IsValid(path))
134142
{
135143
return false;
@@ -146,6 +154,7 @@ public static UFile Combine(UDirectory leftPath, UFile rightPath)
146154
/// </summary>
147155
/// <param name="fullPath">The full path.</param>
148156
/// <returns>The result of the conversion.</returns>
157+
[CanBeNull]
149158
public static implicit operator UFile(string fullPath)
150159
{
151160
return fullPath != null ? new UFile(fullPath) : null;

sources/common/core/SiliconStudio.Core.Design/IO/UPath.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected UPath([NotNull] string fullPath, StringSpan driveSpan, StringSpan dire
8787
public string FullPath { get; }
8888

8989
/// <summary>
90-
/// Gets a value indicating whether this instance has a <see cref="Drive"/> != null.
90+
/// Gets a value indicating whether this instance has a <see cref="GetDrive"/> != null.
9191
/// </summary>
9292
/// <value><c>true</c> if this instance has drive; otherwise, <c>false</c>.</value>
9393
public bool HasDrive => DriveSpan.IsValid;
@@ -136,6 +136,7 @@ public static bool IsNullOrEmpty(UPath path)
136136
/// Gets the drive (contains the ':' if any), can be null.
137137
/// </summary>
138138
/// <returns>The drive.</returns>
139+
[CanBeNull]
139140
public string GetDrive()
140141
{
141142
return DriveSpan.IsValid ? FullPath.Substring(DriveSpan) : null;
@@ -145,6 +146,7 @@ public string GetDrive()
145146
/// Gets the directory. Can be null. It won't contain the drive if one is specified.
146147
/// </summary>
147148
/// <returns>The directory.</returns>
149+
[CanBeNull]
148150
[Obsolete("This method is obsolete. Use GetFullDirectory")]
149151
public string GetDirectory()
150152
{
@@ -155,19 +157,13 @@ public string GetDirectory()
155157
{
156158
return FullPath.Substring(DirectorySpan);
157159
}
158-
else
159-
{
160-
return FullPath.Substring(DirectorySpan.Start, DirectorySpan.Length - 1);
161-
}
160+
return FullPath.Substring(DirectorySpan.Start, DirectorySpan.Length - 1);
162161
}
163-
else if (DriveSpan.IsValid & (NameSpan.IsValid || ExtensionSpan.IsValid))
162+
if (DriveSpan.IsValid & (NameSpan.IsValid || ExtensionSpan.IsValid))
164163
{
165164
return "/";
166165
}
167-
else
168-
{
169-
return null;
170-
}
166+
return null;
171167
}
172168

173169
/// <summary>
@@ -197,6 +193,7 @@ public UDirectory GetParent()
197193
/// the directories and the filename (including its extension).
198194
/// </summary>
199195
/// <returns>An IEnumerable of all the components of this instance.</returns>
196+
[NotNull]
200197
public IReadOnlyCollection<string> GetComponents()
201198
{
202199
var list = new List<string>(FullPath.Count(pathItem => pathItem == DirectorySeparatorChar) + 1);
@@ -269,7 +266,7 @@ public override int GetHashCode()
269266
return hashCode;
270267
}
271268

272-
private static int ComputeStringHashCodeCaseInsensitive(string text)
269+
private static int ComputeStringHashCodeCaseInsensitive([NotNull] string text)
273270
{
274271
return text.Aggregate(0, (current, t) => (current*397) ^ char.ToLowerInvariant(t));
275272
}
@@ -292,6 +289,7 @@ public override string ToString()
292289
/// Converts this path to a Windows path (/ replaced by \)
293290
/// </summary>
294291
/// <returns>A string representation of this path in windows form.</returns>
292+
[NotNull]
295293
public string ToWindowsPath()
296294
{
297295
return FullPath.Replace('/', '\\');
@@ -347,7 +345,7 @@ public static T Combine<T>([NotNull] UDirectory leftPath, [NotNull] T rightPath)
347345
/// </summary>
348346
/// <param name="anchorDirectory">The anchor directory.</param>
349347
/// <returns>A relative path of this instance to the anchor directory.</returns>
350-
public UPath MakeRelative(UDirectory anchorDirectory)
348+
public UPath MakeRelative([NotNull] UDirectory anchorDirectory)
351349
{
352350
if (anchorDirectory == null) throw new ArgumentNullException(nameof(anchorDirectory));
353351

@@ -433,6 +431,7 @@ public UPath MakeRelative(UDirectory anchorDirectory)
433431
/// </summary>
434432
/// <param name="url">The URL.</param>
435433
/// <returns>The result of the conversion.</returns>
434+
[CanBeNull]
436435
public static implicit operator string(UPath url)
437436
{
438437
return url?.FullPath;
@@ -467,6 +466,7 @@ public static bool IsValid(string path)
467466
/// <returns>A normalized path.</returns>
468467
/// <exception cref="System.ArgumentException">If path is invalid</exception>
469468
/// <remarks>Unlike <see cref="System.IO.Path" /> , this doesn't make a path absolute to the actual file system.</remarks>
469+
[NotNull]
470470
public static string Normalize(string pathToNormalize)
471471
{
472472
string error;
@@ -485,6 +485,7 @@ public static string Normalize(string pathToNormalize)
485485
/// <param name="error">The error or null if no errors.</param>
486486
/// <returns>A normalized path or null if there is an error.</returns>
487487
/// <remarks>Unlike <see cref="System.IO.Path" /> , this doesn't make a path absolute to the actual file system.</remarks>
488+
[CanBeNull]
488489
public static StringBuilder Normalize(string pathToNormalize, out string error)
489490
{
490491
StringSpan drive;
@@ -515,6 +516,7 @@ private enum NormalizationState
515516
/// <param name="error">The error or null if no errors.</param>
516517
/// <returns>A normalized path or null if there is an error.</returns>
517518
/// <remarks>Unlike <see cref="System.IO.Path" /> , this doesn't make a path absolute to the actual file system.</remarks>
519+
[CanBeNull]
518520
public static unsafe StringBuilder Normalize(string pathToNormalize, out StringSpan drive, out StringSpan directoryOrFileName, out StringSpan fileName, out string error)
519521
{
520522
drive = new StringSpan();
@@ -605,7 +607,7 @@ public static unsafe StringBuilder Normalize(string pathToNormalize, out StringS
605607
error = @"Path must contain a separator '/' or '\' after the volume separator ':'";
606608
return null;
607609
}
608-
else if ((state == NormalizationState.StartComponent) || (state == NormalizationState.DirectorySeparator))
610+
if ((state == NormalizationState.StartComponent) || (state == NormalizationState.DirectorySeparator))
609611
{
610612
// We are starting a new component. Check if previous one is either '..' or '.', in which case
611613
// we can simplify
@@ -768,6 +770,7 @@ private static unsafe void TrimParentAndSelfPath(StringBuilder builder, ref int
768770
}
769771
}
770772

773+
[NotNull]
771774
private static string Decode(string pathToNormalize, bool isPathDirectory, out StringSpan drive, out StringSpan directory, out StringSpan fileName, out StringSpan fileExtension)
772775
{
773776
drive = new StringSpan();

0 commit comments

Comments
 (0)