Browse Source

#enable nullable in AssemblyList + DecompilerTextView

pull/2412/head
Daniel Grunwald 4 years ago
parent
commit
46e9f633ca
  1. 13
      ILSpy/AssemblyList.cs
  2. 4
      ILSpy/LoadedAssembly.cs
  3. 70
      ILSpy/TextView/DecompilerTextView.cs

13
ILSpy/AssemblyList.cs

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -257,7 +258,7 @@ namespace ICSharpCode.ILSpy @@ -257,7 +258,7 @@ namespace ICSharpCode.ILSpy
/// <summary>
/// Find an assembly that was previously opened.
/// </summary>
public LoadedAssembly FindAssembly(string file)
public LoadedAssembly? FindAssembly(string file)
{
file = Path.GetFullPath(file);
lock (lockObj)
@ -295,7 +296,7 @@ namespace ICSharpCode.ILSpy @@ -295,7 +296,7 @@ namespace ICSharpCode.ILSpy
/// <summary>
/// Opens an assembly from a stream.
/// </summary>
public LoadedAssembly OpenAssembly(string file, Stream stream, bool isAutoLoaded = false)
public LoadedAssembly OpenAssembly(string file, Stream? stream, bool isAutoLoaded = false)
{
file = Path.GetFullPath(file);
return OpenAssembly(file, () => {
@ -339,7 +340,7 @@ namespace ICSharpCode.ILSpy @@ -339,7 +340,7 @@ namespace ICSharpCode.ILSpy
/// Replace the assembly object model from a crafted stream, without disk I/O
/// Returns null if it is not already loaded.
/// </summary>
public LoadedAssembly HotReplaceAssembly(string file, Stream stream)
public LoadedAssembly? HotReplaceAssembly(string file, Stream stream)
{
App.Current.Dispatcher.VerifyAccess();
file = Path.GetFullPath(file);
@ -351,7 +352,7 @@ namespace ICSharpCode.ILSpy @@ -351,7 +352,7 @@ namespace ICSharpCode.ILSpy
if (index < 0)
return null;
var newAsm = new LoadedAssembly(this, file, stream: Task.FromResult(stream));
var newAsm = new LoadedAssembly(this, file, stream: Task.FromResult<Stream?>(stream));
newAsm.IsAutoLoaded = target.IsAutoLoaded;
Debug.Assert(newAsm.FileName == file);
@ -361,7 +362,7 @@ namespace ICSharpCode.ILSpy @@ -361,7 +362,7 @@ namespace ICSharpCode.ILSpy
}
}
public LoadedAssembly ReloadAssembly(string file)
public LoadedAssembly? ReloadAssembly(string file)
{
App.Current.Dispatcher.VerifyAccess();
file = Path.GetFullPath(file);
@ -373,7 +374,7 @@ namespace ICSharpCode.ILSpy @@ -373,7 +374,7 @@ namespace ICSharpCode.ILSpy
return ReloadAssembly(target);
}
public LoadedAssembly ReloadAssembly(LoadedAssembly target)
public LoadedAssembly? ReloadAssembly(LoadedAssembly target)
{
App.Current.Dispatcher.VerifyAccess();
var index = this.assemblies.IndexOf(target);

4
ILSpy/LoadedAssembly.cs

@ -478,7 +478,7 @@ namespace ICSharpCode.ILSpy @@ -478,7 +478,7 @@ namespace ICSharpCode.ILSpy
if (file != null)
{
// Load assembly from disk
LoadedAssembly asm;
LoadedAssembly? asm;
if (loadOnDemand)
{
asm = assemblyList.OpenAssembly(file, isAutoLoaded: true);
@ -576,7 +576,7 @@ namespace ICSharpCode.ILSpy @@ -576,7 +576,7 @@ namespace ICSharpCode.ILSpy
if (File.Exists(file))
{
// Load module from disk
LoadedAssembly asm;
LoadedAssembly? asm;
if (loadOnDemand)
{
asm = assemblyList.OpenAssembly(file, isAutoLoaded: true);

70
ILSpy/TextView/DecompilerTextView.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -70,17 +72,17 @@ namespace ICSharpCode.ILSpy.TextView @@ -70,17 +72,17 @@ namespace ICSharpCode.ILSpy.TextView
{
readonly ReferenceElementGenerator referenceElementGenerator;
readonly UIElementGenerator uiElementGenerator;
readonly List<VisualLineElementGenerator> activeCustomElementGenerators = new List<VisualLineElementGenerator>();
RichTextColorizer activeRichTextColorizer;
BracketHighlightRenderer bracketHighlightRenderer;
FoldingManager foldingManager;
ILSpyTreeNode[] decompiledNodes;
Uri currentAddress;
string currentTitle;
DefinitionLookup definitionLookup;
TextSegmentCollection<ReferenceSegment> references;
CancellationTokenSource currentCancellationTokenSource;
readonly List<VisualLineElementGenerator?> activeCustomElementGenerators = new List<VisualLineElementGenerator?>();
readonly BracketHighlightRenderer bracketHighlightRenderer;
RichTextColorizer? activeRichTextColorizer;
FoldingManager? foldingManager;
ILSpyTreeNode[]? decompiledNodes;
Uri? currentAddress;
string? currentTitle;
DefinitionLookup? definitionLookup;
TextSegmentCollection<ReferenceSegment>? references;
CancellationTokenSource? currentCancellationTokenSource;
readonly TextMarkerService textMarkerService;
readonly List<ITextMarker> localReferenceMarks = new List<ITextMarker>();
@ -198,8 +200,8 @@ namespace ICSharpCode.ILSpy.TextView @@ -198,8 +200,8 @@ namespace ICSharpCode.ILSpy.TextView
#endregion
#region Tooltip support
ToolTip toolTip;
Popup popupToolTip;
ToolTip? toolTip;
Popup? popupToolTip;
void TextViewMouseHover(object sender, MouseEventArgs e)
{
@ -216,7 +218,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -216,7 +218,7 @@ namespace ICSharpCode.ILSpy.TextView
ReferenceSegment seg = referenceElementGenerator.References.FindSegmentsContaining(offset).FirstOrDefault();
if (seg == null)
return;
object content = GenerateTooltip(seg);
object? content = GenerateTooltip(seg);
if (content != null)
{
@ -329,7 +331,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -329,7 +331,7 @@ namespace ICSharpCode.ILSpy.TextView
double GetDistanceToPopup(MouseEventArgs e)
{
Point p = popupToolTip.Child.PointFromScreen(PointToScreen(e.GetPosition(this)));
Point p = popupToolTip!.Child.PointFromScreen(PointToScreen(e.GetPosition(this)));
Size size = popupToolTip.Child.RenderSize;
double x = 0;
if (p.X < 0)
@ -375,7 +377,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -375,7 +377,7 @@ namespace ICSharpCode.ILSpy.TextView
}
}
object GenerateTooltip(ReferenceSegment segment)
object? GenerateTooltip(ReferenceSegment segment)
{
if (segment.Reference is ICSharpCode.Decompiler.Disassembler.OpCodeInfo code)
{
@ -428,7 +430,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -428,7 +430,7 @@ namespace ICSharpCode.ILSpy.TextView
return null;
}
static FlowDocument CreateTooltipForEntity(IEntity resolved)
static FlowDocument? CreateTooltipForEntity(IEntity resolved)
{
Language currentLanguage = MainWindow.Instance.CurrentLanguage;
DocumentationUIBuilder renderer = new DocumentationUIBuilder(new CSharpAmbience(), currentLanguage.SyntaxHighlighting);
@ -454,7 +456,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -454,7 +456,7 @@ namespace ICSharpCode.ILSpy.TextView
}
return renderer.CreateDocument();
IEntity ResolveReference(string idString)
IEntity? ResolveReference(string idString)
{
return MainWindow.FindEntityInRelevantAssemblies(idString, MainWindow.Instance.CurrentAssemblyList.GetAssemblies());
}
@ -561,7 +563,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -561,7 +563,7 @@ namespace ICSharpCode.ILSpy.TextView
taskBar.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Indeterminate;
}
}
CancellationTokenSource previousCancellationTokenSource = currentCancellationTokenSource;
CancellationTokenSource? previousCancellationTokenSource = currentCancellationTokenSource;
var myCancellationTokenSource = new CancellationTokenSource();
currentCancellationTokenSource = myCancellationTokenSource;
// cancel the previous only after current was set to the new one (avoid that the old one still finishes successfully)
@ -633,7 +635,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -633,7 +635,7 @@ namespace ICSharpCode.ILSpy.TextView
ShowNodes(textOutput, null);
}
public void ShowNode(AvalonEditTextOutput textOutput, ILSpyTreeNode node, IHighlightingDefinition highlighting = null)
public void ShowNode(AvalonEditTextOutput textOutput, ILSpyTreeNode node, IHighlightingDefinition? highlighting = null)
{
ShowNodes(textOutput, new[] { node }, highlighting);
}
@ -642,7 +644,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -642,7 +644,7 @@ namespace ICSharpCode.ILSpy.TextView
/// Shows the given output in the text view.
/// Cancels any currently running decompilation tasks.
/// </summary>
public void ShowNodes(AvalonEditTextOutput textOutput, ILSpyTreeNode[] nodes, IHighlightingDefinition highlighting = null)
public void ShowNodes(AvalonEditTextOutput textOutput, ILSpyTreeNode[]? nodes, IHighlightingDefinition? highlighting = null)
{
// Cancel the decompilation task:
if (currentCancellationTokenSource != null)
@ -669,7 +671,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -669,7 +671,7 @@ namespace ICSharpCode.ILSpy.TextView
/// <summary>
/// Shows the given output in the text view.
/// </summary>
void ShowOutput(AvalonEditTextOutput textOutput, IHighlightingDefinition highlighting = null, DecompilerTextViewState state = null)
void ShowOutput(AvalonEditTextOutput textOutput, IHighlightingDefinition? highlighting = null, DecompilerTextViewState? state = null)
{
Debug.WriteLine("Showing {0} characters of output", textOutput.TextLength);
Stopwatch w = Stopwatch.StartNew();
@ -753,7 +755,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -753,7 +755,7 @@ namespace ICSharpCode.ILSpy.TextView
// more than 75M characters can get us into trouble with memory usage
public const int ExtendedOutputLengthLimit = 75000000;
DecompilationContext nextDecompilationRun;
DecompilationContext? nextDecompilationRun;
[Obsolete("Use DecompileAsync() instead")]
public void Decompile(ILSpy.Language language, IEnumerable<ILSpyTreeNode> treeNodes, DecompilationOptions options)
@ -797,7 +799,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -797,7 +799,7 @@ namespace ICSharpCode.ILSpy.TextView
public readonly ILSpy.Language Language;
public readonly ILSpyTreeNode[] TreeNodes;
public readonly DecompilationOptions Options;
public readonly TaskCompletionSource<object> TaskCompletionSource = new TaskCompletionSource<object>();
public readonly TaskCompletionSource<object?> TaskCompletionSource = new TaskCompletionSource<object?>();
public DecompilationContext(ILSpy.Language language, ILSpyTreeNode[] treeNodes, DecompilationOptions options)
{
@ -1139,7 +1141,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -1139,7 +1141,7 @@ namespace ICSharpCode.ILSpy.TextView
}
#endregion
internal ReferenceSegment GetReferenceSegmentAtMousePosition()
internal ReferenceSegment? GetReferenceSegmentAtMousePosition()
{
if (referenceElementGenerator.References == null)
return null;
@ -1161,7 +1163,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -1161,7 +1163,7 @@ namespace ICSharpCode.ILSpy.TextView
return position;
}
public DecompilerTextViewState GetState()
public DecompilerTextViewState? GetState()
{
if (decompiledNodes == null && currentAddress == null)
return null;
@ -1176,7 +1178,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -1176,7 +1178,7 @@ namespace ICSharpCode.ILSpy.TextView
return state;
}
ViewState IHaveState.GetState() => GetState();
ViewState? IHaveState.GetState() => GetState();
public static void RegisterHighlighting()
{
@ -1197,6 +1199,8 @@ namespace ICSharpCode.ILSpy.TextView @@ -1197,6 +1199,8 @@ namespace ICSharpCode.ILSpy.TextView
{
if (lineNumber <= 0 || lineNumber > textEditor.Document.LineCount)
return;
if (foldingManager == null)
return;
var line = textEditor.Document.GetLineByNumber(lineNumber);
@ -1216,7 +1220,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -1216,7 +1220,7 @@ namespace ICSharpCode.ILSpy.TextView
textEditor.ScrollTo(lineNumber, 0);
}
public FoldingManager FoldingManager {
public FoldingManager? FoldingManager {
get {
return foldingManager;
}
@ -1227,10 +1231,10 @@ namespace ICSharpCode.ILSpy.TextView @@ -1227,10 +1231,10 @@ namespace ICSharpCode.ILSpy.TextView
[DebuggerDisplay("Nodes = {DecompiledNodes}, ViewedUri = {ViewedUri}")]
public class ViewState : IEquatable<ViewState>
{
public HashSet<ILSpyTreeNode> DecompiledNodes;
public Uri ViewedUri;
public HashSet<ILSpyTreeNode>? DecompiledNodes;
public Uri? ViewedUri;
public virtual bool Equals(ViewState other)
public virtual bool Equals(ViewState? other)
{
return other != null
&& ViewedUri == other.ViewedUri
@ -1240,7 +1244,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -1240,7 +1244,7 @@ namespace ICSharpCode.ILSpy.TextView
public class DecompilerTextViewState : ViewState
{
private List<Tuple<int, int>> ExpandedFoldings;
private List<Tuple<int, int>>? ExpandedFoldings;
private int FoldingsChecksum;
public double VerticalOffset;
public double HorizontalOffset;
@ -1259,7 +1263,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -1259,7 +1263,7 @@ namespace ICSharpCode.ILSpy.TextView
folding.DefaultClosed = !ExpandedFoldings.Any(f => f.Item1 == folding.StartOffset && f.Item2 == folding.EndOffset);
}
public override bool Equals(ViewState other)
public override bool Equals(ViewState? other)
{
if (other is DecompilerTextViewState vs)
{

Loading…
Cancel
Save