Skip to content

Commit

Permalink
Null annotate most of the SolutionExplorer extension code
Browse files Browse the repository at this point in the history
Easy to do while I'm here.
  • Loading branch information
jasonmalinowski committed Oct 22, 2020
1 parent 481895b commit 7fa2c96
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
Expand All @@ -23,10 +21,10 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplore
internal class AnalyzerItemsTracker : IVsSelectionEvents
{
private readonly IServiceProvider _serviceProvider;
private IVsMonitorSelection _vsMonitorSelection = null;
private IVsMonitorSelection? _vsMonitorSelection = null;
private uint _selectionEventsCookie = 0;

public event EventHandler SelectedHierarchyItemChanged;
public event EventHandler? SelectedHierarchyItemChanged;

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
Expand Down Expand Up @@ -56,9 +54,9 @@ public void Unregister()
}
}

public IVsHierarchy SelectedHierarchy { get; private set; }
public IVsHierarchy? SelectedHierarchy { get; private set; }
public uint SelectedItemId { get; private set; } = VSConstants.VSITEMID_NIL;
public AnalyzersFolderItem SelectedFolder { get; private set; }
public AnalyzersFolderItem? SelectedFolder { get; private set; }
public ImmutableArray<AnalyzerItem> SelectedAnalyzerItems { get; private set; } = ImmutableArray<AnalyzerItem>.Empty;
public ImmutableArray<BaseDiagnosticItem> SelectedDiagnosticItems { get; private set; } = ImmutableArray<BaseDiagnosticItem>.Empty;

Expand Down Expand Up @@ -114,7 +112,7 @@ int IVsSelectionEvents.OnSelectionChanged(
return VSConstants.S_OK;
}

private object[] GetSelectedObjects(ISelectionContainer selectionContainer)
private object[] GetSelectedObjects(ISelectionContainer? selectionContainer)
{
if (selectionContainer == null)
{
Expand All @@ -135,7 +133,7 @@ private object[] GetSelectedObjects(ISelectionContainer selectionContainer)
return selectedObjects;
}

private IVsMonitorSelection GetMonitorSelection()
private IVsMonitorSelection? GetMonitorSelection()
{
if (_vsMonitorSelection == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Design;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.ComponentModel.Composition;
using System.Diagnostics;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Roslyn.Utilities;
using VSLangProj140;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplorer
Expand All @@ -23,17 +22,17 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplore
internal class AnalyzerReferenceManager : IVsReferenceManagerUser
{
private readonly IServiceProvider _serviceProvider;
private IVsReferenceManager _referenceManager;

[Import]
private readonly AnalyzerItemsTracker _tracker = null;
private IVsReferenceManager? _referenceManager;
private readonly AnalyzerItemsTracker _tracker;

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public AnalyzerReferenceManager(
[Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
[Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
AnalyzerItemsTracker analyzerItemsTracker)
{
_serviceProvider = serviceProvider;
_tracker = analyzerItemsTracker;
}

/// <summary>
Expand Down Expand Up @@ -62,7 +61,7 @@ public void ChangeReferences(uint operation, IVsReferenceProviderContext changed

// The items selected in Solution Explorer should correspond to exactly one
// IVsHierarchy, otherwise we shouldn't have even tried to show the dialog.
Debug.Assert(_tracker.SelectedHierarchy != null);
Contract.ThrowIfNull(_tracker.SelectedHierarchy);
if (_tracker.SelectedHierarchy.TryGetProject(out var project))
{

Expand Down Expand Up @@ -94,7 +93,7 @@ public void ChangeReferences(uint operation, IVsReferenceProviderContext changed
public Array GetProviderContexts()
{
// Return just the File provider context so that just the browse tab shows up.
var context = GetReferenceManager().CreateProviderContext(VSConstants.FileReferenceProvider_Guid) as IVsFileReferenceProviderContext;
var context = (IVsFileReferenceProviderContext)GetReferenceManager().CreateProviderContext(VSConstants.FileReferenceProvider_Guid);
context.BrowseFilter = string.Format("{0} (*.dll)\0*.dll\0", SolutionExplorerShim.Analyzer_Files);
return new[] { context };
}
Expand All @@ -104,6 +103,7 @@ private IVsReferenceManager GetReferenceManager()
if (_referenceManager == null)
{
_referenceManager = _serviceProvider.GetService(typeof(SVsReferenceManager)) as IVsReferenceManager;
Assumes.Present(_referenceManager);
}

return _referenceManager;
Expand Down
165 changes: 27 additions & 138 deletions src/VisualStudio/Core/Impl/SolutionExplorer/BaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down Expand Up @@ -44,111 +42,30 @@ public BaseItem(string name)
_name = name;
}

public IEnumerable<string> Children
{
get
{
return SpecializedCollections.EmptyEnumerable<string>();
}
}

public bool IsExpandable
{
get
{
return true;
}
}

public FontStyle FontStyle
{
get { return FontStyles.Normal; }
}

public FontWeight FontWeight
{
get { return FontWeights.Normal; }
}

public virtual ImageSource Icon
{
get { return null; }
}

public virtual ImageMoniker IconMoniker
{
get { return default; }
}

public virtual ImageSource ExpandedIcon
{
get { return null; }
}

public virtual ImageMoniker ExpandedIconMoniker
{
get { return default; }
}

public bool AllowIconTheming
{
get { return true; }
}
public IEnumerable<string> Children => SpecializedCollections.EmptyEnumerable<string>();

public bool AllowExpandedIconTheming
{
get { return true; }
}
public bool IsExpandable => true;

public bool IsCut
{
get { return false; }
}
public FontStyle FontStyle => FontStyles.Normal;
public FontWeight FontWeight => FontWeights.Normal;

public ImageSource OverlayIcon
{
get { return null; }
}
public virtual ImageSource? Icon => null;
public virtual ImageMoniker IconMoniker => default;
public virtual ImageSource? ExpandedIcon => null;
public virtual ImageMoniker ExpandedIconMoniker => default;

public virtual ImageMoniker OverlayIconMoniker
{
get { return default; }
}

public ImageSource StateIcon
{
get { return null; }
}

public virtual ImageMoniker StateIconMoniker
{
get { return default; }
}

public string StateToolTipText
{
get { return null; }
}

public override string ToString()
{
return Text;
}

public string Text
{
get { return _name; }
}

public object ToolTipContent
{
get { return null; }
}

public string ToolTipText
{
get { return _name; }
}
public bool AllowIconTheming => true;
public bool AllowExpandedIconTheming => true;
public bool IsCut => false;
public ImageSource? OverlayIcon => null;
public virtual ImageMoniker OverlayIconMoniker => default;
public ImageSource? StateIcon => null;
public virtual ImageMoniker StateIconMoniker => default;
public string? StateToolTipText => null;
public override string ToString() => Text;
public string Text => _name;
public object? ToolTipContent => null;
public string ToolTipText => _name;

private static readonly HashSet<Type> s_supportedPatterns = new HashSet<Type>()
{
Expand All @@ -163,7 +80,7 @@ public string ToolTipText
typeof(ISupportDisposalNotification)
};

public TPattern GetPattern<TPattern>() where TPattern : class
public TPattern? GetPattern<TPattern>() where TPattern : class
{
if (!IsDisposed)
{
Expand All @@ -188,49 +105,21 @@ public TPattern GetPattern<TPattern>() where TPattern : class
return null;
}

public bool CanPreview
{
get { return false; }
}
public bool CanPreview => false;

public virtual IInvocationController InvocationController
{
get
{
return null;
}
}
public virtual IInvocationController? InvocationController => null;

public virtual IContextMenuController ContextMenuController
{
get
{
return null;
}
}
public virtual IContextMenuController? ContextMenuController => null;

public IDragDropSourceController DragDropSourceController
{
get
{
return null;
}
}
public IDragDropSourceController? DragDropSourceController => null;

public virtual object GetBrowseObject()
{
return this;
}

public bool IsDisposed
{
get { return false; }
}

public int Priority
{
get { return 0; }
}
public bool IsDisposed => false;
public int Priority => 0;

public int CompareTo(object obj)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.ComponentModel;
using System.Globalization;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.ComponentModel;
using System.Globalization;
Expand Down Expand Up @@ -51,7 +49,7 @@ public string Description
}

[BrowseObjectDisplayName(nameof(SolutionExplorerShim.Help_link))]
public string HelpLink
public string? HelpLink
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.ComponentModel;
using System.Threading;
Expand All @@ -24,7 +22,7 @@ internal abstract partial class BaseDiagnosticItem : BaseItem
public DiagnosticDescriptor Descriptor { get; }
public ReportDiagnostic EffectiveSeverity { get; private set; }

public override event PropertyChangedEventHandler PropertyChanged;
public override event PropertyChangedEventHandler? PropertyChanged;

public BaseDiagnosticItem(DiagnosticDescriptor descriptor, ReportDiagnostic effectiveSeverity, string language)
: base(descriptor.Id + ": " + descriptor.Title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down
Loading

0 comments on commit 7fa2c96

Please sign in to comment.