Skip to content

Commit

Permalink
Annotate Microsoft.VisualStudio.ProjectSystem.Managed.dll for nullabi…
Browse files Browse the repository at this point in the history
…lity
  • Loading branch information
Pilchie committed Dec 17, 2018
1 parent 3ab58bd commit e7bb224
Show file tree
Hide file tree
Showing 83 changed files with 428 additions and 332 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
<LangVersion>8.0</LangVersion>
<Features>strict</Features>
<NullableReferenceTypes>true</NullableReferenceTypes>
<!--<NullableReferenceTypes Condition="'$(IsTestProject)' != 'true'">true</NullableReferenceTypes>-->
<WarningsNotAsErrors>$(WarningsNotAsErrors);8600;8601;8602;8603;8604;8618;8619;8620;8622;8625;8626;8629</WarningsNotAsErrors>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static ProjectPropertyElement GetProperty(ProjectRootElement project, str
/// <returns>Collection of individual values in the property.</returns>
public static IEnumerable<string> GetPropertyValues(string propertyValue, char delimiter = ';')
{
HashSet<string> seen = null;
HashSet<string>? seen = null;

// We need to ensure that we return values in the specified order.
foreach (string value in new LazyStringSplit(propertyValue, delimiter))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ internal static IEnumerable<T> ExtensionValues<T>(this OrderPrecedenceImportColl
}
}

public static T FirstOrDefaultValue<T>(this OrderPrecedenceImportCollection<T> imports, Func<T, bool> predicate)
public static T? FirstOrDefaultValue<T>(this OrderPrecedenceImportCollection<T> imports, Func<T, bool> predicate)
where T : class
{
Requires.NotNull(imports, nameof(imports));

Expand All @@ -72,7 +73,8 @@ public static T FirstOrDefaultValue<T>(this OrderPrecedenceImportCollection<T> i
return default;
}

public static TImport FirstOrDefaultValue<TImport, TArg>(this OrderPrecedenceImportCollection<TImport> imports, Func<TImport, TArg, bool> predicate, TArg arg)
public static TImport? FirstOrDefaultValue<TImport, TArg>(this OrderPrecedenceImportCollection<TImport> imports, Func<TImport, TArg, bool> predicate, TArg arg)
where TImport : class
{
Requires.NotNull(imports, nameof(imports));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Microsoft.VisualStudio.IO
/// </summary>
internal sealed class SimpleFileWatcher : IDisposable
{
private FileSystemWatcher FileWatcher { get; set; }
private FileSystemEventHandler _handler;
private RenamedEventHandler _renameHandler;
private FileSystemWatcher? FileWatcher { get; set; }
private FileSystemEventHandler? _handler;
private RenamedEventHandler? _renameHandler;

// For unit tests
public SimpleFileWatcher()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public static bool Any<TKey, TValue>(this ImmutableDictionary<TKey, TValue> immu
return false;
}

public static T FirstOrDefault<T, TArg>(this ImmutableArray<T> immutableArray, Func<T, TArg, bool> predicate, TArg arg)
public static T? FirstOrDefault<T, TArg>(this ImmutableArray<T> immutableArray, Func<T, TArg, bool> predicate, TArg arg)
where T : class
{
foreach (T obj in immutableArray)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ public static T FirstOrDefault<T, TArg>(this IEnumerable<T> source, Func<T, TArg
return obj;
}

return default;
return default!;
}

[Pure]
public static T SingleOrDefault<T, TArg>(this IEnumerable<T> source, Func<T, TArg, bool> predicate, TArg arg)
public static T? SingleOrDefault<T, TArg>(this IEnumerable<T> source, Func<T, TArg, bool> predicate, TArg arg)
where T : class
{
using (IEnumerator<T> enumerator = source.GetEnumerator())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Summary>Microsoft VisualStudio Managed Project System</Summary>
<PackageTags>Roslyn Managed Project System VisualStudio</PackageTags>
<NoWarn>$(NoWarn);NU5125</NoWarn>
<NullableReferenceTypes>true</NullableReferenceTypes>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="Microsoft.VisualStudio.ProjectSystem.Managed.VS" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private struct Element

// Storage for the pool objects. The first item is stored in a dedicated field because we
// expect to be able to satisfy most requests from it.
private T _firstItem;
private T? _firstItem;
private readonly Element[] _items;

// factory is stored for the lifetime of the pool. We will call this only when pool needs to
Expand Down Expand Up @@ -72,7 +72,7 @@ internal T Allocate()
// Note that the initial read is optimistically not synchronized. That is intentional.
// We will interlock only when we have a candidate. in a worst case we may miss some
// recently returned objects. Not a big deal.
T inst = _firstItem;
T? inst = _firstItem;
if (inst == null || inst != Interlocked.CompareExchange(ref _firstItem, null, inst))
{
inst = AllocateSlow();
Expand All @@ -93,7 +93,9 @@ private T AllocateSlow()
T inst = items[i].Value;
if (inst != null)
{
#pragma warning disable CS8625 // Workaround https://github.com/dotnet/roslyn/issues/31865
if (inst == Interlocked.CompareExchange(ref items[i].Value, null, inst))
#pragma warning restore CS8625
{
return inst;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public void Dispose()
{
}

#pragma warning disable CS8603 // Workaround https://github.com/dotnet/roslyn/issues/31867
object System.Collections.IEnumerator.Current => Current;
#pragma warning restore CS8603

public void Reset() => _index = -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal sealed partial class PooledArray<T> : IReadOnlyCollection<T>, IReadOnly
{
private readonly ImmutableArray<T>.Builder _builder;

private readonly ObjectPool<PooledArray<T>> _pool;
private readonly ObjectPool<PooledArray<T>>? _pool;

public PooledArray(int size)
{
Expand Down Expand Up @@ -71,7 +71,9 @@ public void SetItem(int index, T value)
{
while (index > _builder.Count)
{
#pragma warning disable CS8625 // Workaround https://github.com/dotnet/roslyn/issues/31865
_builder.Add(default);
#pragma warning restore CS8625
}

if (index == _builder.Count)
Expand Down Expand Up @@ -177,7 +179,10 @@ public ImmutableArray<U> ToDowncastedImmutable<U>()
var tmp = PooledArray<U>.GetInstance(Count);
foreach (T i in this)
{
#pragma warning disable CS8600,CS8604 // Workaround for https://github.com/dotnet/roslyn/issues/31866
tmp.Add((U)i);
#pragma warning restore CS8600,CS8604

}

return tmp.ToImmutableAndFree();
Expand Down Expand Up @@ -213,7 +218,7 @@ public T[] ToArrayAndFree()
// 1) Expose Freeing primitive.
public void Free()
{
ObjectPool<PooledArray<T>> pool = _pool;
ObjectPool<PooledArray<T>>? pool = _pool;
if (pool != null)
{
// We do not want to retain (potentially indefinitely) very large builders
Expand Down Expand Up @@ -274,7 +279,7 @@ public static ObjectPool<PooledArray<T>> CreatePool()

public static ObjectPool<PooledArray<T>> CreatePool(int size)
{
ObjectPool<PooledArray<T>> pool = null;
ObjectPool<PooledArray<T>>? pool = null;
pool = new ObjectPool<PooledArray<T>>(() => new PooledArray<T>(pool), size);
return pool;
}
Expand All @@ -284,7 +289,9 @@ public Enumerator GetEnumerator()
return new Enumerator(this);
}

#pragma warning disable CS8616 // Workaround https://github.com/dotnet/roslyn/issues/31862
IEnumerator<T> IEnumerable<T>.GetEnumerator()
#pragma warning restore CS8616
{
return GetEnumerator();
}
Expand All @@ -294,7 +301,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
return GetEnumerator();
}

internal Dictionary<K, ImmutableArray<T>> ToDictionary<K>(Func<T, K> keySelector, IEqualityComparer<K> comparer = null)
internal Dictionary<K, ImmutableArray<T>> ToDictionary<K>(Func<T, K> keySelector, IEqualityComparer<K>? comparer = null)
{
if (Count == 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Free()
// if someone needs to create a pool;
public static ObjectPool<PooledDictionary<K, V>> CreatePool()
{
ObjectPool<PooledDictionary<K, V>> pool = null;
ObjectPool<PooledDictionary<K, V>>? pool = null;
pool = new ObjectPool<PooledDictionary<K, V>>(() => new PooledDictionary<K, V>(pool), 128);
return pool;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Free()
// if someone needs to create a pool;
public static ObjectPool<PooledHashSet<T>> CreatePool()
{
ObjectPool<PooledHashSet<T>> pool = null;
ObjectPool<PooledHashSet<T>>? pool = null;
pool = new ObjectPool<PooledHashSet<T>>(() => new PooledHashSet<T>(pool), 128);
return pool;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public string ToStringAndFree(int startIndex, int length)
/// <returns></returns>
public static ObjectPool<PooledStringBuilder> CreatePool(int size = 32)
{
ObjectPool<PooledStringBuilder> pool = null;
ObjectPool<PooledStringBuilder>? pool = null;
pool = new ObjectPool<PooledStringBuilder>(() => new PooledStringBuilder(pool), size);
return pool;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ internal abstract class AbstractMultiLifetimeComponent : OnceInitializedOnceDisp
{
private readonly object _lock = new object();
private TaskCompletionSource<object> _loadedSource = new TaskCompletionSource<object>();
private IMultiLifetimeInstance _instance;
private IMultiLifetimeInstance? _instance;

protected AbstractMultiLifetimeComponent(JoinableTaskContextNode joinableTaskContextNode)
: base(joinableTaskContextNode)
{
}

public IMultiLifetimeInstance Instance
public IMultiLifetimeInstance? Instance
{
get { return _instance; }
}
Expand All @@ -49,7 +49,7 @@ public async Task LoadAsync()

private async Task LoadCoreAsync()
{
TaskCompletionSource<object> loadedSource = null;
TaskCompletionSource<object>? loadedSource = null;
IMultiLifetimeInstance instance;
lock (_lock)
{
Expand All @@ -65,12 +65,12 @@ private async Task LoadCoreAsync()
// While all callers should wait on InitializeAsync,
// only one should complete the completion source
await instance.InitializeAsync();
loadedSource?.SetResult(null);
loadedSource?.SetResult(null!);
}

public Task UnloadAsync()
{
IMultiLifetimeInstance instance = null;
IMultiLifetimeInstance? instance = null;

lock (_lock)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void ApplySpecialFolderProperties(IProjectTreeCustomizablePropertyValues
propertyValues.Flags = propertyValues.Flags.Union(FolderFlags);

// Avoid overwriting icon if the image provider didn't provide one
ProjectImageMoniker icon = _imageProvider.GetProjectImage(FolderImageKey);
ProjectImageMoniker? icon = _imageProvider.GetProjectImage(FolderImageKey);
if (icon != null)
{
propertyValues.Icon = icon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class ActiveConfiguredProjectsLoader : OnceInitializedOnceDisposed
private readonly IActiveConfigurationGroupService _activeConfigurationGroupService;
private readonly IUnconfiguredProjectTasksService _tasksService;
private readonly ITargetBlock<IProjectVersionedValue<IConfigurationGroup<ProjectConfiguration>>> _targetBlock;
private IDisposable _subscription;
private IDisposable? _subscription;

[ImportingConstructor]
public ActiveConfiguredProjectsLoader(UnconfiguredProject project, IActiveConfigurationGroupService activeConfigurationGroupService, IUnconfiguredProjectTasksService tasksService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,31 @@ public async Task<ImmutableDictionary<string, ConfiguredProject>> GetActiveConfi
{
var builder = PooledDictionary<string, ConfiguredProject>.GetInstance();

ActiveConfiguredObjects<ConfiguredProject> projects = await GetActiveConfiguredProjectsAsync();
ActiveConfiguredObjects<ConfiguredProject>? projects = await GetActiveConfiguredProjectsAsync();

bool isCrossTargeting = projects.Objects.All(project => project.ProjectConfiguration.IsCrossTargeting());
if (isCrossTargeting)
if (projects != null)
{
foreach (ConfiguredProject project in projects.Objects)
bool isCrossTargeting = projects.Objects.All(project => project.ProjectConfiguration.IsCrossTargeting());
if (isCrossTargeting)
{
string targetFramework = project.ProjectConfiguration.Dimensions[ConfigurationGeneral.TargetFrameworkProperty];
builder.Add(targetFramework, project);
foreach (ConfiguredProject project in projects.Objects)
{
string targetFramework = project.ProjectConfiguration.Dimensions[ConfigurationGeneral.TargetFrameworkProperty];
builder.Add(targetFramework, project);
}
}
else
{
builder.Add(string.Empty, projects.Objects[0]);
}
}
else
{
builder.Add(string.Empty, projects.Objects[0]);
}

return builder.ToImmutableDictionaryAndFree();
}

public async Task<ActiveConfiguredObjects<ConfiguredProject>> GetActiveConfiguredProjectsAsync()
public async Task<ActiveConfiguredObjects<ConfiguredProject>?> GetActiveConfiguredProjectsAsync()
{
ActiveConfiguredObjects<ProjectConfiguration> configurations = await GetActiveProjectConfigurationsAsync();
ActiveConfiguredObjects<ProjectConfiguration>? configurations = await GetActiveProjectConfigurationsAsync();
if (configurations == null)
return null;

Expand All @@ -113,7 +116,7 @@ public async Task<ActiveConfiguredObjects<ConfiguredProject>> GetActiveConfigure
return new ActiveConfiguredObjects<ConfiguredProject>(builder.MoveToImmutable(), configurations.DimensionNames);
}

public async Task<ActiveConfiguredObjects<ProjectConfiguration>> GetActiveProjectConfigurationsAsync()
public async Task<ActiveConfiguredObjects<ProjectConfiguration>?> GetActiveProjectConfigurationsAsync()
{
ProjectConfiguration activeSolutionConfiguration = _services.ActiveConfiguredProjectProvider.ActiveProjectConfiguration;
if (activeSolutionConfiguration == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public void UpdateProjectTreeSettings(IImmutableDictionary<string, IProjectRuleS
//
// TODO: Read these default values from the rules themselves
// See: https://github.com/dotnet/roslyn-project-system/issues/209
string folderName = ruleSnapshots.GetPropertyOrDefault(AppDesigner.SchemaName, AppDesigner.FolderNameProperty, "Properties");
string contextsVisibleOnlyInShowAllFiles = ruleSnapshots.GetPropertyOrDefault(AppDesigner.SchemaName, AppDesigner.ContentsVisibleOnlyInShowAllFilesProperty, "false");
string? folderName = ruleSnapshots.GetPropertyOrDefault(AppDesigner.SchemaName, AppDesigner.FolderNameProperty, "Properties");
string? contextsVisibleOnlyInShowAllFiles = ruleSnapshots.GetPropertyOrDefault(AppDesigner.SchemaName, AppDesigner.ContentsVisibleOnlyInShowAllFilesProperty, "false");

projectTreeSettings = projectTreeSettings.SetItem(AppDesigner.FolderNameProperty, folderName);
projectTreeSettings = projectTreeSettings.SetItem(AppDesigner.ContentsVisibleOnlyInShowAllFilesProperty, contextsVisibleOnlyInShowAllFiles);
projectTreeSettings = projectTreeSettings.SetItem(AppDesigner.FolderNameProperty, folderName!);
projectTreeSettings = projectTreeSettings.SetItem(AppDesigner.ContentsVisibleOnlyInShowAllFilesProperty, contextsVisibleOnlyInShowAllFiles!);
}

protected sealed override bool IsCandidateSpecialFolder(IProjectTreeCustomizablePropertyContext propertyContext, ProjectTreeFlags flags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private Task GetLatestActivationTask()
}
else if (nowActive)
{
_activationTask.TrySetResult(null);
_activationTask.TrySetResult(null!);
}

return _activationTask.Task;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal abstract class BaseProjectConfigurationDimensionProvider : IProjectConf
/// <param name="dimensionName">Name of the dimension.</param>
/// <param name="propertyName">Name of the project property containing the dimension values.</param>
/// <param name="dimensionDefaultValue">The default value of the dimension, for example "AnyCPU".</param>
protected BaseProjectConfigurationDimensionProvider(IProjectAccessor projectAccessor, string dimensionName, string propertyName, string dimensionDefaultValue = null)
protected BaseProjectConfigurationDimensionProvider(IProjectAccessor projectAccessor, string dimensionName, string propertyName, string? dimensionDefaultValue = null)
{
Requires.NotNull(projectAccessor, nameof(projectAccessor));

Expand All @@ -44,7 +44,7 @@ public string PropertyName
get;
}

public string DimensionDefaultValue
public string? DimensionDefaultValue
{
get;
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public virtual async Task<IEnumerable<KeyValuePair<string, IEnumerable<string>>>

public async Task<IEnumerable<KeyValuePair<string, string>>> GetBestGuessDefaultValuesForDimensionsAsync(UnconfiguredProject project)
{
string defaultValue = await FindDefaultValueFromDimensionPropertyAsync(project) ?? DimensionDefaultValue;
string? defaultValue = await FindDefaultValueFromDimensionPropertyAsync(project) ?? DimensionDefaultValue;
if (defaultValue != null)
return new[] { new KeyValuePair<string, string>(DimensionName, defaultValue) };

Expand All @@ -158,7 +158,7 @@ public async Task<IEnumerable<KeyValuePair<string, string>>> GetBestGuessDefault
/// <remarks>
/// This needs to get the evaluated property in order to get inherited properties defines in props or targets.
/// </remarks>
protected async Task<string> GetPropertyValue(UnconfiguredProject project, string propertyName = null)
protected async Task<string> GetPropertyValue(UnconfiguredProject project, string? propertyName = null)
{
ConfiguredProject configuredProject = await project.GetSuggestedConfiguredProjectAsync();

Expand All @@ -168,7 +168,7 @@ protected async Task<string> GetPropertyValue(UnconfiguredProject project, strin
});
}

private async Task<string> FindDefaultValueFromDimensionPropertyAsync(UnconfiguredProject project)
private async Task<string?> FindDefaultValueFromDimensionPropertyAsync(UnconfiguredProject project)
{
string values = await FindDimensionPropertyAsync(project);
if (string.IsNullOrEmpty(values))
Expand Down
Loading

0 comments on commit e7bb224

Please sign in to comment.