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

4
ILSpy/LoadedAssembly.cs

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

70
ILSpy/TextView/DecompilerTextView.cs

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

Loading…
Cancel
Save