Skip to content

Commit

Permalink
Add nullability annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed Jul 9, 2019
1 parent 4338762 commit 8f73d75
Show file tree
Hide file tree
Showing 158 changed files with 311 additions and 590 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

using System;

#nullable disable

namespace Microsoft.VisualStudio
{
/// <summary>
Expand Down Expand Up @@ -91,4 +89,4 @@ public static bool IsEarlierThanOrEqualTo(this IComparable source, IComparable c
return source.CompareTo(comparable) <= 0;
}
}
}
}
2 changes: 0 additions & 2 deletions src/Microsoft.VisualStudio.ProjectSystem.Managed/Delimiter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable disable

namespace Microsoft.VisualStudio
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;

#nullable disable
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.VisualStudio
{
Expand Down Expand Up @@ -41,6 +40,7 @@ internal static class ImmutableCollectionLinqExtensions
return false;
}

[return: MaybeNull]
public static T FirstOrDefault<T, TArg>(this ImmutableArray<T> immutableArray, Func<T, TArg, bool> predicate, TArg arg)
{
foreach (T obj in immutableArray)
Expand All @@ -49,7 +49,7 @@ internal static class ImmutableCollectionLinqExtensions
return obj;
}

return default;
return default!;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;

#nullable disable

namespace Microsoft.VisualStudio
{
internal static class LinqExtensions
{
[Pure]
[return: MaybeNull]
public static T FirstOrDefault<T, TArg>(this IEnumerable<T> source, Func<T, TArg, bool> predicate, TArg arg)
{
foreach (T obj in source)
Expand All @@ -19,10 +19,11 @@ internal static class LinqExtensions
return obj;
}

return default;
return default!;
}

[Pure]
[return: MaybeNull]
public static T SingleOrDefault<T, TArg>(this IEnumerable<T> source, Func<T, TArg, bool> predicate, TArg arg)
{
using (IEnumerator<T> enumerator = source.GetEnumerator())
Expand All @@ -47,7 +48,7 @@ internal static class LinqExtensions
}
}

return default;
return default!;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

using Microsoft.VisualStudio.Threading;

#nullable disable

namespace Microsoft.VisualStudio.ProjectSystem
{
/// <summary>
Expand Down Expand Up @@ -86,7 +84,7 @@ public async Task LoadCoreAsync()

public Task UnloadAsync()
{
T instance = null;
T? instance = null;
lock (_lock)
{
if (_instanceTaskSource.Task.IsCompleted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System.Collections.Generic;
using System.Collections.Immutable;

#nullable disable

namespace Microsoft.VisualStudio.ProjectSystem
{
/// <summary>
Expand Down Expand Up @@ -42,6 +40,7 @@ public ActiveConfiguredObjects(IReadOnlyList<T> objects, IImmutableSet<string> d
{
Requires.NotNull(dimensionNames, nameof(dimensionNames));
Requires.NotNull(objects, nameof(objects));

if (objects.Count == 0)
throw new ArgumentException(null, nameof(objects));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;

#nullable disable

namespace Microsoft.VisualStudio.ProjectSystem
{
/// <summary>
Expand All @@ -19,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 Expand Up @@ -67,7 +65,6 @@ private async Task OnActiveConfigurationsChanged(IProjectVersionedValue<IConfigu
await _tasksService.LoadedProjectAsync(() =>
{
return _project.LoadConfiguredProjectAsync(configuration);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

using Microsoft.VisualStudio.Threading.Tasks;

#nullable disable

namespace Microsoft.VisualStudio.ProjectSystem
{
/// <summary>
Expand All @@ -25,8 +23,8 @@ internal class ConfiguredProjectImplicitActivationTracking : OnceInitializedOnce
private readonly IProjectAsynchronousTasksService _tasksService;
private readonly IActiveConfigurationGroupService _activeConfigurationGroupService;
private readonly ITargetBlock<IProjectVersionedValue<IConfigurationGroup<ProjectConfiguration>>> _targetBlock;
private TaskCompletionSource<object> _isImplicitlyActiveSource = new TaskCompletionSource<object>();
private IDisposable _subscription;
private TaskCompletionSource<object?> _isImplicitlyActiveSource = new TaskCompletionSource<object?>();
private IDisposable? _subscription;

[ImportingConstructor]
public ConfiguredProjectImplicitActivationTracking(ConfiguredProject project, IActiveConfigurationGroupService activeConfigurationGroupService, [Import(ExportContractNames.Scopes.ConfiguredProject)]IProjectAsynchronousTasksService tasksService)
Expand Down Expand Up @@ -133,7 +131,7 @@ private Task OnImplicitlyActivated()

private Task OnImplicitlyDeactivated()
{
var source = new TaskCompletionSource<object>();
var source = new TaskCompletionSource<object?>();

// Make sure the writes in constructor don't
// move to after we publish the value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable disable

namespace Microsoft.VisualStudio.ProjectSystem
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;

#nullable disable

namespace Microsoft.VisualStudio.ProjectSystem
{
/// <summary>
Expand Down Expand Up @@ -40,7 +38,11 @@ internal static class DataflowUtilities
/// </para>
/// <paramref name="target"/> is <see langword="null"/>.
/// </exception>
public static IDisposable LinkToAction(this ISourceBlock<IProjectVersionedValue<IProjectSubscriptionUpdate>> source, Action<IProjectVersionedValue<IProjectSubscriptionUpdate>> target, bool suppressVersionOnlyUpdates = true, params string[] ruleNames)
public static IDisposable LinkToAction(
this ISourceBlock<IProjectVersionedValue<IProjectSubscriptionUpdate>> source,
Action<IProjectVersionedValue<IProjectSubscriptionUpdate>> target,
bool suppressVersionOnlyUpdates = true,
params string[] ruleNames)
{
Requires.NotNull(source, nameof(source));
Requires.NotNull(target, nameof(target));
Expand Down Expand Up @@ -77,7 +79,11 @@ public static IDisposable LinkToAction(this ISourceBlock<IProjectVersionedValue<
/// </para>
/// <paramref name="target"/> is <see langword="null"/>.
/// </exception>
public static IDisposable LinkToAction(this ISourceBlock<IProjectVersionedValue<IProjectSubscriptionUpdate>> source, Action<IProjectVersionedValue<IProjectSubscriptionUpdate>> target, bool suppressVersionOnlyUpdates = true, IEnumerable<string> ruleNames = null)
public static IDisposable LinkToAction(
this ISourceBlock<IProjectVersionedValue<IProjectSubscriptionUpdate>> source,
Action<IProjectVersionedValue<IProjectSubscriptionUpdate>> target,
bool suppressVersionOnlyUpdates = true,
IEnumerable<string>? ruleNames = null)
{
Requires.NotNull(source, nameof(source));
Requires.NotNull(target, nameof(target));
Expand Down Expand Up @@ -114,7 +120,11 @@ public static IDisposable LinkToAction(this ISourceBlock<IProjectVersionedValue<
/// </para>
/// <paramref name="target"/> is <see langword="null"/>.
/// </exception>
public static IDisposable LinkToAsyncAction(this ISourceBlock<IProjectVersionedValue<IProjectSubscriptionUpdate>> source, Func<IProjectVersionedValue<IProjectSubscriptionUpdate>, Task> target, bool suppressVersionOnlyUpdates = true, params string[] ruleNames)
public static IDisposable LinkToAsyncAction(
this ISourceBlock<IProjectVersionedValue<IProjectSubscriptionUpdate>> source,
Func<IProjectVersionedValue<IProjectSubscriptionUpdate>, Task> target,
bool suppressVersionOnlyUpdates = true,
params string[] ruleNames)
{
Requires.NotNull(source, nameof(source));
Requires.NotNull(target, nameof(target));
Expand Down Expand Up @@ -151,7 +161,11 @@ public static IDisposable LinkToAsyncAction(this ISourceBlock<IProjectVersionedV
/// </para>
/// <paramref name="target"/> is <see langword="null"/>.
/// </exception>
public static IDisposable LinkToAsyncAction(this ISourceBlock<IProjectVersionedValue<IProjectSubscriptionUpdate>> source, Func<IProjectVersionedValue<IProjectSubscriptionUpdate>, Task> target, bool suppressVersionOnlyUpdates = true, IEnumerable<string> ruleNames = null)
public static IDisposable LinkToAsyncAction(
this ISourceBlock<IProjectVersionedValue<IProjectSubscriptionUpdate>> source,
Func<IProjectVersionedValue<IProjectSubscriptionUpdate>, Task> target,
bool suppressVersionOnlyUpdates = true,
IEnumerable<string>? ruleNames = null)
{
Requires.NotNull(source, nameof(source));
Requires.NotNull(target, nameof(target));
Expand Down Expand Up @@ -232,7 +246,9 @@ public static IDisposable LinkToAsyncAction<T>(this ISourceBlock<T> source, Func
/// </para>
/// <paramref name="transform"/> is <see langword="null"/>.
/// </exception>
public static DisposableValue<ISourceBlock<TOut>> Transform<TInput, TOut>(this ISourceBlock<IProjectVersionedValue<TInput>> source, Func<IProjectVersionedValue<TInput>, TOut> transform)
public static DisposableValue<ISourceBlock<TOut>> Transform<TInput, TOut>(
this ISourceBlock<IProjectVersionedValue<TInput>> source,
Func<IProjectVersionedValue<TInput>, TOut> transform)
{
Requires.NotNull(source, nameof(source));
Requires.NotNull(transform, nameof(transform));
Expand Down Expand Up @@ -271,7 +287,9 @@ public static IDisposable LinkToAsyncAction<T>(this ISourceBlock<T> source, Func
/// </para>
/// <paramref name="transform"/> is <see langword="null"/>.
/// </exception>
public static DisposableValue<ISourceBlock<TOut>> TransformWithNoDelta<TInput, TOut>(this ISourceBlock<IProjectVersionedValue<TInput>> source, Func<IProjectVersionedValue<TInput>, TOut> transform)
public static DisposableValue<ISourceBlock<TOut>> TransformWithNoDelta<TInput, TOut>(
this ISourceBlock<IProjectVersionedValue<TInput>> source,
Func<IProjectVersionedValue<TInput>, TOut> transform)
{
Requires.NotNull(source, nameof(source));
Requires.NotNull(transform, nameof(transform));
Expand Down Expand Up @@ -314,7 +332,11 @@ public static IDisposable LinkToAsyncAction<T>(this ISourceBlock<T> source, Func
/// </para>
/// <paramref name="transform"/> is <see langword="null"/>.
/// </exception>
public static DisposableValue<ISourceBlock<TOut>> TransformWithNoDelta<TOut>(this ISourceBlock<IProjectVersionedValue<IProjectSubscriptionUpdate>> source, Func<IProjectVersionedValue<IProjectSubscriptionUpdate>, TOut> transform, bool suppressVersionOnlyUpdates, IEnumerable<string> ruleNames = null)
public static DisposableValue<ISourceBlock<TOut>> TransformWithNoDelta<TOut>(
this ISourceBlock<IProjectVersionedValue<IProjectSubscriptionUpdate>> source,
Func<IProjectVersionedValue<IProjectSubscriptionUpdate>, TOut> transform,
bool suppressVersionOnlyUpdates,
IEnumerable<string>? ruleNames = null)
{
Requires.NotNull(source, nameof(source));
Requires.NotNull(transform, nameof(transform));
Expand Down Expand Up @@ -351,7 +373,7 @@ public static DisposableValue<ISourceBlock<TOut>> TransformWithNoDelta<TOut>(thi
{
SynchronizationContext currentSynchronizationContext = SynchronizationContext.Current;
using ExecutionContext copy = context.CreateCopy();
Task result = null;
Task? result = null;
ExecutionContext.Run(
copy,
state =>
Expand All @@ -360,7 +382,7 @@ public static DisposableValue<ISourceBlock<TOut>> TransformWithNoDelta<TOut>(thi
result = function(input);
},
null);
return result;
return result!;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

using Microsoft.VisualStudio.ProjectSystem.Properties;

#nullable disable

namespace Microsoft.VisualStudio.ProjectSystem
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System;
using System.Threading.Tasks.Dataflow;

#nullable disable

namespace Microsoft.VisualStudio.ProjectSystem
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using System.Collections.Immutable;
using System.Threading.Tasks;

#nullable disable

namespace Microsoft.VisualStudio.ProjectSystem
{
/// <summary>
Expand Down Expand Up @@ -37,7 +35,7 @@ internal static class FaultExtensions
/// <param name="project">
/// The project related to the failure, if applicable. Can be <see langword="null"/>.
/// </param>
public static Task ReportFaultAsync(this IProjectFaultHandlerService faultHandlerService, Exception ex, UnconfiguredProject project, ProjectFaultSeverity severity = ProjectFaultSeverity.Recoverable)
public static Task ReportFaultAsync(this IProjectFaultHandlerService faultHandlerService, Exception ex, UnconfiguredProject? project, ProjectFaultSeverity severity = ProjectFaultSeverity.Recoverable)
{
Requires.NotNull(faultHandlerService, nameof(faultHandlerService));

Expand All @@ -60,7 +58,7 @@ public static Task ReportFaultAsync(this IProjectFaultHandlerService faultHandle
/// <param name="severity">
/// The severity of the failure.
/// </param>
public static void Forget(this IProjectFaultHandlerService faultHandlerService, Task task, UnconfiguredProject project, ProjectFaultSeverity severity = ProjectFaultSeverity.Recoverable)
public static void Forget(this IProjectFaultHandlerService faultHandlerService, Task task, UnconfiguredProject? project, ProjectFaultSeverity severity = ProjectFaultSeverity.Recoverable)
{
Requires.NotNull(faultHandlerService, nameof(faultHandlerService));

Expand All @@ -83,7 +81,7 @@ public static void Forget(this IProjectFaultHandlerService faultHandlerService,
/// <param name="severity">
/// The severity of the failure.
/// </param>
public static void Forget<TResult>(this IProjectFaultHandlerService faultHandlerService, Task<TResult> task, UnconfiguredProject project, ProjectFaultSeverity severity = ProjectFaultSeverity.Recoverable)
public static void Forget<TResult>(this IProjectFaultHandlerService faultHandlerService, Task<TResult> task, UnconfiguredProject? project, ProjectFaultSeverity severity = ProjectFaultSeverity.Recoverable)
{
Requires.NotNull(faultHandlerService, nameof(faultHandlerService));

Expand All @@ -109,7 +107,7 @@ public static void Forget<TResult>(this IProjectFaultHandlerService faultHandler
/// <param name="options">
/// Influences the environment in which the delegate is executed.
/// </param>
public static void RunAndForget(this IProjectThreadingService threadingService, Func<Task> asyncAction, UnconfiguredProject unconfiguredProject, ProjectFaultSeverity faultSeverity = ProjectFaultSeverity.Recoverable, ForkOptions options = ForkOptions.Default)
public static void RunAndForget(this IProjectThreadingService threadingService, Func<Task> asyncAction, UnconfiguredProject? unconfiguredProject, ProjectFaultSeverity faultSeverity = ProjectFaultSeverity.Recoverable, ForkOptions options = ForkOptions.Default)
{
Requires.NotNull(threadingService, nameof(threadingService));

Expand Down Expand Up @@ -141,7 +139,7 @@ public static void RunAndForget(this IProjectThreadingService threadingService,
/// <param name="options">
/// Influences the environment in which the delegate is executed.
/// </param>
public static void RunAndForget(this IProjectThreadingService threadingService, Func<Task> asyncAction, ConfiguredProject configuredProject, ProjectFaultSeverity faultSeverity = ProjectFaultSeverity.Recoverable, ForkOptions options = ForkOptions.Default)
public static void RunAndForget(this IProjectThreadingService threadingService, Func<Task> asyncAction, ConfiguredProject? configuredProject, ProjectFaultSeverity faultSeverity = ProjectFaultSeverity.Recoverable, ForkOptions options = ForkOptions.Default)
{
Requires.NotNull(threadingService, nameof(threadingService));

Expand Down

0 comments on commit 8f73d75

Please sign in to comment.