Browse Source

Fix JumpToReference/ReferenceSegment tuple mess.

pull/1994/head
Siegfried Pammer 6 years ago
parent
commit
ab89581eab
  1. 32
      ILSpy/Commands/DecompileCommand.cs
  2. 45
      ILSpy/EntityReference.cs
  3. 1
      ILSpy/ILSpy.csproj
  4. 12
      ILSpy/MainWindow.xaml.cs
  5. 2
      ILSpy/TextView/AvalonEditTextOutput.cs
  6. 6
      ILSpy/TextView/DecompilerTextView.cs

32
ILSpy/Commands/DecompileCommand.cs

@ -1,20 +1,28 @@
using System; // Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
using System.Collections.Generic; //
using System.Diagnostics; // Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335; using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.Analyzers;
using ICSharpCode.ILSpy.Controls;
using ICSharpCode.ILSpy.Metadata; using ICSharpCode.ILSpy.Metadata;
using ICSharpCode.ILSpy.TreeNodes; using ICSharpCode.ILSpy.TreeNodes;
@ -66,7 +74,7 @@ namespace ICSharpCode.ILSpy.Commands
public void Execute(TextViewContext context) public void Execute(TextViewContext context)
{ {
int token = GetSelectedToken(context.DataGrid, out PEFile module).Value; int token = GetSelectedToken(context.DataGrid, out PEFile module).Value;
MainWindow.Instance.JumpToReference(("metadata", module, MetadataTokens.Handle(token))); MainWindow.Instance.JumpToReference(new EntityReference("metadata", module, MetadataTokens.Handle(token)));
} }
public bool IsEnabled(TextViewContext context) public bool IsEnabled(TextViewContext context)

45
ILSpy/EntityReference.cs

@ -0,0 +1,45 @@
// Copyright (c) 2018 Siegfried Pammer
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Diagnostics;
using System.Reflection.Metadata;
using ICSharpCode.Decompiler.Metadata;
namespace ICSharpCode.ILSpy
{
[DebuggerDisplay("EntityReference Module={Module}, Handle={Handle}, Protocol={Protocol}")]
public class EntityReference
{
public PEFile Module { get; }
public Handle Handle { get; }
public string Protocol { get; }
public EntityReference(PEFile module, Handle handle)
{
this.Module = module ?? throw new ArgumentNullException(nameof(module));
this.Handle = handle;
}
public EntityReference(string protocol, PEFile module, Handle handle)
: this(module, handle)
{
this.Protocol = protocol ?? "decompile";
}
}
}

1
ILSpy/ILSpy.csproj

@ -138,6 +138,7 @@
<Compile Include="Controls\SearchBox.cs" /> <Compile Include="Controls\SearchBox.cs" />
<Compile Include="Controls\SortableGridViewColumn.cs" /> <Compile Include="Controls\SortableGridViewColumn.cs" />
<Compile Include="Controls\XamlResourceExtension.cs" /> <Compile Include="Controls\XamlResourceExtension.cs" />
<Compile Include="EntityReference.cs" />
<Compile Include="Metadata\CorTables\FieldRVATableTreeNode.cs"> <Compile Include="Metadata\CorTables\FieldRVATableTreeNode.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>

12
ILSpy/MainWindow.xaml.cs

@ -885,22 +885,22 @@ namespace ICSharpCode.ILSpy
case Decompiler.Disassembler.OpCodeInfo opCode: case Decompiler.Disassembler.OpCodeInfo opCode:
OpenLink(opCode.Link); OpenLink(opCode.Link);
break; break;
case ValueTuple<string, PEFile, Handle> unresolvedEntity: case EntityReference unresolvedEntity:
string protocol = unresolvedEntity.Item1 ?? "decompile"; string protocol = unresolvedEntity.Protocol ?? "decompile";
PEFile file = unresolvedEntity.Item2; PEFile file = unresolvedEntity.Module;
if (protocol != "decompile") { if (protocol != "decompile") {
var protocolHandlers = App.ExportProvider.GetExports<IProtocolHandler>(); var protocolHandlers = App.ExportProvider.GetExports<IProtocolHandler>();
foreach (var handler in protocolHandlers) { foreach (var handler in protocolHandlers) {
var node = handler.Value.Resolve(protocol, file, unresolvedEntity.Item3, out bool newTabPage); var node = handler.Value.Resolve(protocol, file, unresolvedEntity.Handle, out bool newTabPage);
if (node != null) { if (node != null) {
SelectNode(node, newTabPage); SelectNode(node, newTabPage);
return decompilationTask; return decompilationTask;
} }
} }
} }
if (MetadataTokenHelpers.TryAsEntityHandle(MetadataTokens.GetToken(unresolvedEntity.Item3)) != null) { if (MetadataTokenHelpers.TryAsEntityHandle(MetadataTokens.GetToken(unresolvedEntity.Handle)) != null) {
var typeSystem = new DecompilerTypeSystem(file, file.GetAssemblyResolver(), TypeSystemOptions.Default | TypeSystemOptions.Uncached); var typeSystem = new DecompilerTypeSystem(file, file.GetAssemblyResolver(), TypeSystemOptions.Default | TypeSystemOptions.Uncached);
reference = typeSystem.MainModule.ResolveEntity((EntityHandle)unresolvedEntity.Item3); reference = typeSystem.MainModule.ResolveEntity((EntityHandle)unresolvedEntity.Handle);
goto default; goto default;
} }
break; break;

2
ILSpy/TextView/AvalonEditTextOutput.cs

@ -245,7 +245,7 @@ namespace ICSharpCode.ILSpy.TextView
if (isDefinition) { if (isDefinition) {
this.DefinitionLookup.AddDefinition((module, handle), this.TextLength); this.DefinitionLookup.AddDefinition((module, handle), this.TextLength);
} }
references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = (protocol, module, handle), IsDefinition = isDefinition }); references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = new EntityReference(protocol, module, handle), IsDefinition = isDefinition });
} }
public void WriteReference(IType type, string text, bool isDefinition = false) public void WriteReference(IType type, string text, bool isDefinition = false)

6
ILSpy/TextView/DecompilerTextView.cs

@ -362,10 +362,10 @@ namespace ICSharpCode.ILSpy.TextView
if (document == null) if (document == null)
return null; return null;
return new FlowDocumentTooltip(document); return new FlowDocumentTooltip(document);
} else if (segment.Reference is ValueTuple<PEFile, System.Reflection.Metadata.EntityHandle> unresolvedEntity) { } else if (segment.Reference is EntityReference unresolvedEntity) {
var typeSystem = new DecompilerTypeSystem(unresolvedEntity.Item1, unresolvedEntity.Item1.GetAssemblyResolver(), TypeSystemOptions.Default | TypeSystemOptions.Uncached); var typeSystem = new DecompilerTypeSystem(unresolvedEntity.Module, unresolvedEntity.Module.GetAssemblyResolver(), TypeSystemOptions.Default | TypeSystemOptions.Uncached);
try { try {
IEntity resolved = typeSystem.MainModule.ResolveEntity(unresolvedEntity.Item2); IEntity resolved = typeSystem.MainModule.ResolveEntity(unresolvedEntity.Handle);
if (resolved == null) if (resolved == null)
return null; return null;
var document = CreateTooltipForEntity(resolved); var document = CreateTooltipForEntity(resolved);

Loading…
Cancel
Save