mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
The "resolve assembly -> entity handle -> uncached DecompilerTypeSystem -> ResolveEntity" sequence was copy-pasted in the code-view hover navigation and the assembly-tree node finder. Move it onto EntityReference as a Resolve(AssemblyList) member so both call sites just supply the list they already have, and the uncached-per-call decision lives in one place. Assisted-by: Claude:claude-opus-4-8:Claude Codepull/3755/head
4 changed files with 89 additions and 18 deletions
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// 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.Threading.Tasks; |
||||
|
||||
using Avalonia.Headless.NUnit; |
||||
|
||||
using AwesomeAssertions; |
||||
|
||||
using ICSharpCode.Decompiler.TypeSystem; |
||||
|
||||
using ILSpy; |
||||
using ILSpy.TreeNodes; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.ILSpy.Tests; |
||||
|
||||
/// <summary>
|
||||
/// EntityReference.Resolve turns an unresolved (module, handle) reference into the live IEntity,
|
||||
/// the shared resolution used by code-view hover navigation and the assembly-tree node finder.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class EntityReferenceResolveTests |
||||
{ |
||||
[AvaloniaTest] |
||||
public async Task Resolve_Returns_The_Entity_For_A_Module_Handle_Reference() |
||||
{ |
||||
var (_, vm) = await TestHarness.BootAsync(); |
||||
var typeNode = vm.AssemblyTreeModel.FindNode<TypeTreeNode>( |
||||
"System.Linq", "System.Linq", "System.Linq.Enumerable"); |
||||
var entity = (IEntity)typeNode.Member!; |
||||
var module = entity.ParentModule!.MetadataFile!; |
||||
|
||||
var reference = new EntityReference(module, entity.MetadataToken); |
||||
var resolved = reference.Resolve(vm.AssemblyTreeModel.AssemblyList!); |
||||
|
||||
resolved.Should().NotBeNull("the (module, handle) pair resolves back to its entity"); |
||||
resolved!.FullName.Should().Be(entity.FullName); |
||||
} |
||||
|
||||
[AvaloniaTest] |
||||
public async Task Resolve_Returns_Null_For_An_Unknown_Module() |
||||
{ |
||||
var (_, vm) = await TestHarness.BootAsync(); |
||||
// A module path that isn't in the list can't be resolved -> null, not a throw.
|
||||
var reference = new EntityReference("X:/does/not/exist.dll", |
||||
System.Reflection.Metadata.Ecma335.MetadataTokens.TypeDefinitionHandle(2)); |
||||
reference.Resolve(vm.AssemblyTreeModel.AssemblyList!).Should().BeNull(); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue