Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Group 1] Enable nullable annotations for Microsoft.Extensions.FileSystemGlobbing #57398

Merged
merged 25 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
279767c
Annotate src
maxkoshevoi Aug 14, 2021
a71ba2e
Annotate ref
maxkoshevoi Aug 14, 2021
12c2daa
Merge branch 'main' into mk/43605-FileSystemGlobbing
maxkoshevoi Aug 25, 2021
9c9df2d
Code review
maxkoshevoi Aug 25, 2021
18a47f6
Null check for directoryInfo
maxkoshevoi Aug 25, 2021
78d75be
Nullcheck for PatternMatchingResult.Files
maxkoshevoi Aug 25, 2021
562da4c
ParentDirectory cannot be null
maxkoshevoi Aug 25, 2021
28d19a7
Update PatternBuilder.cs
maxkoshevoi Aug 25, 2021
dfe6394
More null checks
maxkoshevoi Aug 25, 2021
4833ebe
Use expression body in segments
maxkoshevoi Aug 25, 2021
78c094b
One more null check
maxkoshevoi Aug 25, 2021
fd64580
Update ref
maxkoshevoi Aug 25, 2021
bf212ab
DisableImplicitAssemblyReferences
maxkoshevoi Aug 26, 2021
99ef5a0
Fix doc
maxkoshevoi Aug 26, 2021
bcb0420
TestMatchingGroup nonnull
maxkoshevoi Aug 26, 2021
399c8ac
ParentDirectory can be null
maxkoshevoi Aug 26, 2021
2f2fd3f
Fix TestGetHashCodeWithNull
maxkoshevoi Aug 26, 2021
0049981
Merge branch 'main' into mk/43605-FileSystemGlobbing
maxkoshevoi Aug 26, 2021
0d309d7
Revert "Fix TestGetHashCodeWithNull"
maxkoshevoi Aug 27, 2021
6be30d4
Update TestGetHashCodeWithNull
maxkoshevoi Aug 27, 2021
5267cc3
Update FilePatternMatchTests.cs
maxkoshevoi Aug 27, 2021
afb6ac8
Update FilePatternMatchTests.cs
maxkoshevoi Sep 8, 2021
af3bebf
Merge branch 'main' into mk/43605-FileSystemGlobbing
maxkoshevoi Sep 8, 2021
28f11bc
Remove TestGetHashCodeWithNull
maxkoshevoi Oct 5, 2021
2e705b0
InMemoryFileInfo.ParentDirectory is not null
maxkoshevoi Oct 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ public partial struct FilePatternMatch : System.IEquatable<Microsoft.Extensions.
{
private object _dummy;
private int _dummyPrimitive;
public FilePatternMatch(string path, string stem) { throw null; }
public FilePatternMatch(string path, string? stem) { throw null; }
public readonly string Path { get { throw null; } }
public readonly string Stem { get { throw null; } }
public readonly string? Stem { get { throw null; } }
public bool Equals(Microsoft.Extensions.FileSystemGlobbing.FilePatternMatch other) { throw null; }
public override bool Equals(object obj) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
public override int GetHashCode() { throw null; }
}
public partial class InMemoryDirectoryInfo : Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase
{
public InMemoryDirectoryInfo(string rootDir, System.Collections.Generic.IEnumerable<string> files) { }
public InMemoryDirectoryInfo(string rootDir, System.Collections.Generic.IEnumerable<string>? files) { }
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
public override string FullName { get { throw null; } }
public override string Name { get { throw null; } }
public override Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase ParentDirectory { get { throw null; } }
public override Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase? ParentDirectory { get { throw null; } }
public override System.Collections.Generic.IEnumerable<Microsoft.Extensions.FileSystemGlobbing.Abstractions.FileSystemInfoBase> EnumerateFileSystemInfos() { throw null; }
public override Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase GetDirectory(string path) { throw null; }
public override Microsoft.Extensions.FileSystemGlobbing.Abstractions.FileInfoBase GetFile(string path) { throw null; }
public override Microsoft.Extensions.FileSystemGlobbing.Abstractions.FileInfoBase? GetFile(string path) { throw null; }
}
public partial class Matcher
{
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -40,9 +40,9 @@ public static partial class MatcherExtensions
public static void AddExcludePatterns(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, params System.Collections.Generic.IEnumerable<string>[] excludePatternsGroups) { }
public static void AddIncludePatterns(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, params System.Collections.Generic.IEnumerable<string>[] includePatternsGroups) { }
public static System.Collections.Generic.IEnumerable<string> GetResultsInFullPath(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, string directoryPath) { throw null; }
public static Microsoft.Extensions.FileSystemGlobbing.PatternMatchingResult Match(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, System.Collections.Generic.IEnumerable<string> files) { throw null; }
public static Microsoft.Extensions.FileSystemGlobbing.PatternMatchingResult Match(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, System.Collections.Generic.IEnumerable<string>? files) { throw null; }
public static Microsoft.Extensions.FileSystemGlobbing.PatternMatchingResult Match(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, string file) { throw null; }
public static Microsoft.Extensions.FileSystemGlobbing.PatternMatchingResult Match(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, string rootDir, System.Collections.Generic.IEnumerable<string> files) { throw null; }
public static Microsoft.Extensions.FileSystemGlobbing.PatternMatchingResult Match(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, string rootDir, System.Collections.Generic.IEnumerable<string>? files) { throw null; }
public static Microsoft.Extensions.FileSystemGlobbing.PatternMatchingResult Match(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, string rootDir, string file) { throw null; }
}
public partial class PatternMatchingResult
Expand All @@ -59,17 +59,17 @@ public abstract partial class DirectoryInfoBase : Microsoft.Extensions.FileSyste
{
protected DirectoryInfoBase() { }
public abstract System.Collections.Generic.IEnumerable<Microsoft.Extensions.FileSystemGlobbing.Abstractions.FileSystemInfoBase> EnumerateFileSystemInfos();
public abstract Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase GetDirectory(string path);
public abstract Microsoft.Extensions.FileSystemGlobbing.Abstractions.FileInfoBase GetFile(string path);
public abstract Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase? GetDirectory(string path);
public abstract Microsoft.Extensions.FileSystemGlobbing.Abstractions.FileInfoBase? GetFile(string path);
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
}
public partial class DirectoryInfoWrapper : Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase
{
public DirectoryInfoWrapper(System.IO.DirectoryInfo directoryInfo) { }
public override string FullName { get { throw null; } }
public override string Name { get { throw null; } }
public override Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase ParentDirectory { get { throw null; } }
public override Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase? ParentDirectory { get { throw null; } }
public override System.Collections.Generic.IEnumerable<Microsoft.Extensions.FileSystemGlobbing.Abstractions.FileSystemInfoBase> EnumerateFileSystemInfos() { throw null; }
public override Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase GetDirectory(string name) { throw null; }
public override Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase? GetDirectory(string name) { throw null; }
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
public override Microsoft.Extensions.FileSystemGlobbing.Abstractions.FileInfoBase GetFile(string name) { throw null; }
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
}
public abstract partial class FileInfoBase : Microsoft.Extensions.FileSystemGlobbing.Abstractions.FileSystemInfoBase
Expand All @@ -81,14 +81,14 @@ public partial class FileInfoWrapper : Microsoft.Extensions.FileSystemGlobbing.A
public FileInfoWrapper(System.IO.FileInfo fileInfo) { }
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
public override string FullName { get { throw null; } }
public override string Name { get { throw null; } }
public override Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase ParentDirectory { get { throw null; } }
public override Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase? ParentDirectory { get { throw null; } }
}
public abstract partial class FileSystemInfoBase
{
protected FileSystemInfoBase() { }
public abstract string FullName { get; }
public abstract string Name { get; }
public abstract Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase ParentDirectory { get; }
public abstract Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase? ParentDirectory { get; }
}
}
namespace Microsoft.Extensions.FileSystemGlobbing.Internal
Expand Down Expand Up @@ -133,8 +133,8 @@ public partial struct PatternTestResult
private int _dummyPrimitive;
public static readonly Microsoft.Extensions.FileSystemGlobbing.Internal.PatternTestResult Failed;
public readonly bool IsSuccessful { get { throw null; } }
public readonly string Stem { get { throw null; } }
public static Microsoft.Extensions.FileSystemGlobbing.Internal.PatternTestResult Success(string stem) { throw null; }
public readonly string? Stem { get { throw null; } }
public static Microsoft.Extensions.FileSystemGlobbing.Internal.PatternTestResult Success(string? stem) { throw null; }
}
}
namespace Microsoft.Extensions.FileSystemGlobbing.Internal.PathSegments
Expand All @@ -150,7 +150,7 @@ public partial class LiteralPathSegment : Microsoft.Extensions.FileSystemGlobbin
public LiteralPathSegment(string value, System.StringComparison comparisonType) { }
public bool CanProduceStem { get { throw null; } }
public string Value { get { throw null; } }
public override bool Equals(object obj) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
public override int GetHashCode() { throw null; }
public bool Match(string value) { throw null; }
}
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -195,7 +195,7 @@ public partial struct FrameData
public bool InStem;
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
public bool IsNotApplicable;
public int SegmentIndex;
public string Stem { get { throw null; } }
public string? Stem { get { throw null; } }
public System.Collections.Generic.IList<string> StemItems { get { throw null; } }
}
}
Expand Down Expand Up @@ -232,7 +232,7 @@ public partial struct FrameData
public System.Collections.Generic.IList<Microsoft.Extensions.FileSystemGlobbing.Internal.IPathSegment> SegmentGroup;
public int SegmentGroupIndex;
public int SegmentIndex;
public string Stem { get { throw null; } }
public string? Stem { get { throw null; } }
public System.Collections.Generic.IList<string> StemItems { get { throw null; } }
}
}
Expand All @@ -249,12 +249,12 @@ public override void Declare(System.Action<Microsoft.Extensions.FileSystemGlobbi
}
public abstract partial class PatternContext<TFrame> : Microsoft.Extensions.FileSystemGlobbing.Internal.IPatternContext
{
protected TFrame Frame;
protected TFrame? Frame;
protected PatternContext() { }
public virtual void Declare(System.Action<Microsoft.Extensions.FileSystemGlobbing.Internal.IPathSegment, bool> declare) { }
protected bool IsStackEmpty() { throw null; }
public virtual void PopDirectory() { }
protected void PushDataFrame(TFrame frame) { }
protected void PushDataFrame(TFrame? frame) { }
public abstract void PushDirectory(Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase directory);
public abstract bool Test(Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoBase directory);
public abstract Microsoft.Extensions.FileSystemGlobbing.Internal.PatternTestResult Test(Microsoft.Extensions.FileSystemGlobbing.Abstractions.FileInfoBase file);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="Microsoft.Extensions.FileSystemGlobbing.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public abstract class DirectoryInfoBase : FileSystemInfoBase
/// </summary>
/// <param name="path">The directory name</param>
/// <returns>Instance of <see cref="DirectoryInfoBase" /> even if directory does not exist</returns>
public abstract DirectoryInfoBase GetDirectory(string path);
public abstract DirectoryInfoBase? GetDirectory(string path);

/// <summary>
/// Returns an instance of <see cref="FileInfoBase" /> that represents a file in the directory
/// </summary>
/// <param name="path">The file name</param>
/// <returns>Instance of <see cref="FileInfoBase" /> even if file does not exist</returns>
public abstract FileInfoBase GetFile(string path);
public abstract FileInfoBase? GetFile(string path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public override IEnumerable<FileSystemInfoBase> EnumerateFileSystemInfos()

foreach (FileSystemInfo fileSystemInfo in fileSystemInfos)
{
var directoryInfo = fileSystemInfo as DirectoryInfo;
if (directoryInfo != null)
if (fileSystemInfo is DirectoryInfo directoryInfo)
{
yield return new DirectoryInfoWrapper(directoryInfo);
}
Expand All @@ -68,7 +67,7 @@ public override IEnumerable<FileSystemInfoBase> EnumerateFileSystemInfos()
/// </remarks>
/// <param name="name">The directory name</param>
/// <returns>The directory</returns>
public override DirectoryInfoBase GetDirectory(string name)
public override DirectoryInfoBase? GetDirectory(string name)
{
bool isParentPath = string.Equals(name, "..", StringComparison.Ordinal);

Expand Down Expand Up @@ -120,7 +119,7 @@ public override FileInfoBase GetFile(string name)
/// <remarks>
/// Equals the value of <seealso cref="System.IO.DirectoryInfo.Parent" />.
/// </remarks>
public override DirectoryInfoBase ParentDirectory
=> new DirectoryInfoWrapper(_directoryInfo.Parent);
public override DirectoryInfoBase? ParentDirectory
=> new DirectoryInfoWrapper(_directoryInfo.Parent!);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;

namespace Microsoft.Extensions.FileSystemGlobbing.Abstractions
Expand All @@ -18,7 +19,7 @@ public class FileInfoWrapper : FileInfoBase
/// <param name="fileInfo">The <see cref="System.IO.FileInfo" /></param>
public FileInfoWrapper(FileInfo fileInfo)
{
_fileInfo = fileInfo;
_fileInfo = fileInfo ?? throw new ArgumentNullException(nameof(fileInfo));
}

/// <summary>
Expand All @@ -43,6 +44,7 @@ public FileInfoWrapper(FileInfo fileInfo)
/// <remarks>
/// Equals the value of <see cref="System.IO.FileInfo.Directory" />.
/// </remarks>
public override DirectoryInfoBase ParentDirectory => new DirectoryInfoWrapper(_fileInfo.Directory);
public override DirectoryInfoBase? ParentDirectory
=> new DirectoryInfoWrapper(_fileInfo.Directory!);
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public abstract class FileSystemInfoBase
/// <summary>
/// The parent directory for the current file or directory
/// </summary>
public abstract DirectoryInfoBase ParentDirectory { get; }
public abstract DirectoryInfoBase? ParentDirectory { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Numerics.Hashing;

namespace Microsoft.Extensions.FileSystemGlobbing
Expand All @@ -27,16 +28,16 @@ public struct FilePatternMatch : IEquatable<FilePatternMatch>
/// If the matcher searched for "src/Project/**/*.cs" and the pattern matcher found "src/Project/Interfaces/IFile.cs",
/// then <see cref="Stem" /> = "Interfaces/IFile.cs" and <see cref="Path" /> = "src/Project/Interfaces/IFile.cs".
/// </remarks>
public string Stem { get; }
public string? Stem { get; }

/// <summary>
/// Initializes new instance of <see cref="FilePatternMatch" />
/// </summary>
/// <param name="path">The path to the file matched, relative to the beginning of the matching search pattern.</param>
/// <param name="stem">The subpath to the file matched, relative to the first wildcard in the matching search pattern.</param>
public FilePatternMatch(string path, string stem)
public FilePatternMatch(string path, string? stem)
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
{
Path = path;
Path = path ?? throw new ArgumentNullException(nameof(path));
Stem = stem;
}

Expand All @@ -56,10 +57,8 @@ public bool Equals(FilePatternMatch other)
/// </summary>
/// <param name="obj">The object to be compared</param>
/// <returns>True when <see cref="Equals(FilePatternMatch)" /></returns>
public override bool Equals(object obj)
{
return Equals((FilePatternMatch) obj);
}
public override bool Equals([NotNullWhen(true)] object? obj) =>
obj is FilePatternMatch match && Equals(match);

/// <summary>
/// Gets a hash for the file pattern match.
Expand All @@ -68,7 +67,7 @@ public override bool Equals(object obj)
public override int GetHashCode() =>
HashHelpers.Combine(GetHashCode(Path), GetHashCode(Stem));

private static int GetHashCode(string value) =>
private static int GetHashCode(string? value) =>
value != null ? StringComparer.OrdinalIgnoreCase.GetHashCode(value) : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,19 @@ public class InMemoryDirectoryInfo : DirectoryInfoBase
/// </summary>
/// <param name="rootDir">The root directory that this FileSystem will use.</param>
/// <param name="files">Collection of file names. If relative paths <paramref name="rootDir"/> will be prepended to the paths.</param>
public InMemoryDirectoryInfo(string rootDir, IEnumerable<string> files)
public InMemoryDirectoryInfo(string rootDir, IEnumerable<string>? files)
: this(rootDir, files, false)
{
}

private InMemoryDirectoryInfo(string rootDir, IEnumerable<string> files, bool normalized)
private InMemoryDirectoryInfo(string rootDir, IEnumerable<string>? files, bool normalized)
{
if (string.IsNullOrEmpty(rootDir))
{
throw new ArgumentNullException(nameof(rootDir));
}

if (files == null)
{
files = new List<string>();
}
files ??= new List<string>();

Name = Path.GetFileName(rootDir);
if (normalized)
Expand Down Expand Up @@ -69,13 +66,8 @@ private InMemoryDirectoryInfo(string rootDir, IEnumerable<string> files, bool no
public override string Name { get; }

/// <inheritdoc />
public override DirectoryInfoBase ParentDirectory
{
get
{
return new InMemoryDirectoryInfo(Path.GetDirectoryName(FullName), _files, true);
}
}
public override DirectoryInfoBase? ParentDirectory =>
new InMemoryDirectoryInfo(Path.GetDirectoryName(FullName)!, _files, true);
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved

/// <inheritdoc />
public override IEnumerable<FileSystemInfoBase> EnumerateFileSystemInfos()
Expand All @@ -99,8 +91,7 @@ public override IEnumerable<FileSystemInfoBase> EnumerateFileSystemInfos()
else
{
string name = file.Substring(0, endSegment);
List<string> list;
if (!dict.TryGetValue(name, out list))
if (!dict.TryGetValue(name, out List<string>? list))
{
dict[name] = new List<string> { file };
}
Expand Down Expand Up @@ -145,7 +136,7 @@ public override DirectoryInfoBase GetDirectory(string path)
/// </summary>
/// <param name="path">The filename.</param>
/// <returns>Instance of <see cref="FileInfoBase"/> if the file exists, null otherwise.</returns>
public override FileInfoBase GetFile(string path)
public override FileInfoBase? GetFile(string path)
{
string normPath = Path.GetFullPath(path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar));
foreach (string file in _files)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ public InMemoryFileInfo(string file, InMemoryDirectoryInfo parent)

public override string Name { get; }

public override DirectoryInfoBase ParentDirectory
{
get
{
return _parent;
}
}
public override DirectoryInfoBase ParentDirectory => _parent;
}
}
Loading