Browse Source

Move non-UI analyzer code to ILSpyX

pull/3186/head
Christoph Wille 1 year ago
parent
commit
8acd117f91
  1. 1
      Directory.Packages.props
  2. 3
      ICSharpCode.ILSpyX/Abstractions/ILanguage.cs
  3. 6
      ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs
  4. 2
      ICSharpCode.ILSpyX/Analyzers/AnalyzerHelpers.cs
  5. 2
      ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs
  6. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/AttributeAppliedToAnalyzer.cs
  7. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/EventImplementedByAnalyzer.cs
  8. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/EventOverriddenByAnalyzer.cs
  9. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/FieldAccessAnalyzer.cs
  10. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/FindTypeInAttributeDecoder.cs
  11. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs
  12. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/MethodImplementedByAnalyzer.cs
  13. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs
  14. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsedByAnalyzer.cs
  15. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsesAnalyzer.cs
  16. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs
  17. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs
  18. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs
  19. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExposedByAnalyzer.cs
  20. 64
      ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs
  21. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs
  22. 2
      ICSharpCode.ILSpyX/Analyzers/Builtin/TypeUsedByAnalyzer.cs
  23. 2
      ICSharpCode.ILSpyX/Analyzers/ExportAnalyzerAttribute.cs
  24. 2
      ICSharpCode.ILSpyX/Analyzers/IAnalyzer.cs
  25. 1
      ICSharpCode.ILSpyX/ICSharpCode.ILSpyX.csproj
  26. 2
      ILSpy.Tests/Analyzers/AnalyzerScopeTests.cs
  27. 4
      ILSpy.Tests/Analyzers/MemberImplementsInterfaceAnalyzerTests.cs
  28. 4
      ILSpy.Tests/Analyzers/MethodUsesAnalyzerTests.cs
  29. 4
      ILSpy.Tests/Analyzers/TypeUsedByAnalyzerTests.cs
  30. 1
      ILSpy/Analyzers/AnalyzerSearchTreeNode.cs
  31. 46
      ILSpy/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs
  32. 1
      ILSpy/Analyzers/TreeNodes/AnalyzedEventTreeNode.cs
  33. 1
      ILSpy/Analyzers/TreeNodes/AnalyzedFieldTreeNode.cs
  34. 1
      ILSpy/Analyzers/TreeNodes/AnalyzedMethodTreeNode.cs
  35. 1
      ILSpy/Analyzers/TreeNodes/AnalyzedModuleTreeNode.cs
  36. 1
      ILSpy/Analyzers/TreeNodes/AnalyzedPropertyTreeNode.cs
  37. 1
      ILSpy/Analyzers/TreeNodes/AnalyzedTypeTreeNode.cs
  38. 7
      ILSpy/App.xaml.cs

1
Directory.Packages.props

@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
<PackageVersion Include="NuGet.Protocol" Version="6.9.1" />
<PackageVersion Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.ComponentModel.Composition" Version="8.0.0" />
<PackageVersion Include="System.Composition" Version="8.0.0" />
<PackageVersion Include="System.Memory" Version="4.5.5" />
<PackageVersion Include="System.Reflection.Metadata" Version="8.0.0" />

3
ICSharpCode.ILSpyX/Abstractions/ILanguage.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.
using System.Reflection.Metadata;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
@ -24,6 +26,7 @@ namespace ICSharpCode.ILSpyX.Abstractions @@ -24,6 +26,7 @@ namespace ICSharpCode.ILSpyX.Abstractions
public interface ILanguage
{
bool ShowMember(IEntity member);
CodeMappingInfo GetCodeMappingInfo(MetadataFile module, EntityHandle member);
string GetEntityName(MetadataFile module, System.Reflection.Metadata.EntityHandle handle, bool fullName, bool omitGenerics);
string GetTooltip(IEntity entity);

6
ILSpy/Analyzers/AnalyzerContext.cs → ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs

@ -23,9 +23,9 @@ using System.Threading; @@ -23,9 +23,9 @@ using System.Threading;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpyX;
using ICSharpCode.ILSpyX.Abstractions;
namespace ICSharpCode.ILSpy.Analyzers
namespace ICSharpCode.ILSpyX.Analyzers
{
/// <summary>
/// Provides additional context for analyzers.
@ -42,7 +42,7 @@ namespace ICSharpCode.ILSpy.Analyzers @@ -42,7 +42,7 @@ namespace ICSharpCode.ILSpy.Analyzers
/// <summary>
/// Currently used language.
/// </summary>
public Language Language { get; internal set; }
public ILanguage Language { get; internal set; }
/// <summary>
/// Allows the analyzer to control whether the tree nodes will be sorted.

2
ILSpy/Analyzers/AnalyzerHelpers.cs → ICSharpCode.ILSpyX/Analyzers/AnalyzerHelpers.cs

@ -21,7 +21,7 @@ using System.Reflection.Metadata; @@ -21,7 +21,7 @@ using System.Reflection.Metadata;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers
namespace ICSharpCode.ILSpyX.Analyzers
{
internal static class AnalyzerHelpers
{

2
ILSpy/Analyzers/AnalyzerScope.cs → ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs

@ -26,7 +26,7 @@ using ICSharpCode.Decompiler.Metadata; @@ -26,7 +26,7 @@ using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Util;
using ICSharpCode.ILSpyX;
namespace ICSharpCode.ILSpy.Analyzers
namespace ICSharpCode.ILSpyX.Analyzers
{
using ICSharpCode.Decompiler.TypeSystem;

2
ILSpy/Analyzers/Builtin/AttributeAppliedToAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/AttributeAppliedToAnalyzer.cs

@ -26,7 +26,7 @@ using ICSharpCode.Decompiler.Metadata; @@ -26,7 +26,7 @@ using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
[ExportAnalyzer(Header = "Applied To", Order = 10)]
class AttributeAppliedToAnalyzer : IAnalyzer

2
ILSpy/Analyzers/Builtin/EventImplementedByAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/EventImplementedByAnalyzer.cs

@ -23,7 +23,7 @@ using System.Linq; @@ -23,7 +23,7 @@ using System.Linq;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows events that implement an interface event.

2
ILSpy/Analyzers/Builtin/EventOverriddenByAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/EventOverriddenByAnalyzer.cs

@ -23,7 +23,7 @@ using System.Linq; @@ -23,7 +23,7 @@ using System.Linq;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows events that override an event.

2
ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/FieldAccessAnalyzer.cs

@ -29,7 +29,7 @@ using ICSharpCode.Decompiler.TypeSystem; @@ -29,7 +29,7 @@ using ICSharpCode.Decompiler.TypeSystem;
using ILOpCode = System.Reflection.Metadata.ILOpCode;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Finds methods where this field is read.

2
ILSpy/Analyzers/Builtin/FindTypeInAttributeDecoder.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/FindTypeInAttributeDecoder.cs

@ -25,7 +25,7 @@ using ICSharpCode.Decompiler; @@ -25,7 +25,7 @@ using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
public enum TokenSearchResult : byte
{

2
ILSpy/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs

@ -22,7 +22,7 @@ using System.Linq; @@ -22,7 +22,7 @@ using System.Linq;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows members from all corresponding interfaces the selected member implements.

2
ILSpy/Analyzers/Builtin/MethodImplementedByAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/MethodImplementedByAnalyzer.cs

@ -26,7 +26,7 @@ using System.Threading.Tasks; @@ -26,7 +26,7 @@ using System.Threading.Tasks;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows methods that implement an interface method.

2
ILSpy/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs

@ -23,7 +23,7 @@ using System.Linq; @@ -23,7 +23,7 @@ using System.Linq;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows methods that override a method.

2
ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsedByAnalyzer.cs

@ -28,7 +28,7 @@ using ICSharpCode.Decompiler.Disassembler; @@ -28,7 +28,7 @@ using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows entities that are used by a method.

2
ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsesAnalyzer.cs

@ -26,7 +26,7 @@ using ICSharpCode.Decompiler.Disassembler; @@ -26,7 +26,7 @@ using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows entities that are used by a method.

2
ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs

@ -25,7 +25,7 @@ using ICSharpCode.Decompiler.Disassembler; @@ -25,7 +25,7 @@ using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows entities that are used by a method.

2
ILSpy/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs

@ -23,7 +23,7 @@ using System.Linq; @@ -23,7 +23,7 @@ using System.Linq;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows properties that implement an interface property.

2
ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs

@ -26,7 +26,7 @@ using System.Threading.Tasks; @@ -26,7 +26,7 @@ using System.Threading.Tasks;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows properties that override a property.

2
ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExposedByAnalyzer.cs

@ -25,7 +25,7 @@ using System.Text; @@ -25,7 +25,7 @@ using System.Text;
using System.Threading.Tasks;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
using ICSharpCode.Decompiler.TypeSystem;

64
ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs

@ -0,0 +1,64 @@ @@ -0,0 +1,64 @@
// 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.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Finds all extension methods defined for a type.
/// </summary>
[ExportAnalyzer(Header = "Extension Methods", Order = 50)]
class TypeExtensionMethodsAnalyzer : IAnalyzer
{
public bool Show(ISymbol symbol) => symbol is ITypeDefinition entity && !entity.IsStatic;
public IEnumerable<ISymbol> Analyze(ISymbol analyzedSymbol, AnalyzerContext context)
{
Debug.Assert(analyzedSymbol is ITypeDefinition);
var scope = context.GetScopeOf((ITypeDefinition)analyzedSymbol);
foreach (var type in scope.GetTypesInScope(context.CancellationToken))
{
foreach (var result in ScanType((ITypeDefinition)analyzedSymbol, type, context))
yield return result;
}
}
IEnumerable<IEntity> ScanType(ITypeDefinition analyzedType, ITypeDefinition type, AnalyzerContext context)
{
if (!type.HasExtensionMethods)
yield break;
foreach (IMethod method in type.Methods)
{
if (!method.IsExtensionMethod)
continue;
var firstParamType = method.Parameters[0].Type.GetDefinition();
if (firstParamType != null &&
firstParamType.MetadataToken == analyzedType.MetadataToken &&
firstParamType.ParentModule.MetadataFile == analyzedType.ParentModule.MetadataFile)
yield return method;
}
}
}
}

2
ILSpy/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs

@ -30,7 +30,7 @@ using ICSharpCode.Decompiler.Disassembler; @@ -30,7 +30,7 @@ using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows methods that instantiate a type.

2
ILSpy/Analyzers/Builtin/TypeUsedByAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/Builtin/TypeUsedByAnalyzer.cs

@ -28,7 +28,7 @@ using ICSharpCode.Decompiler.Disassembler; @@ -28,7 +28,7 @@ using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows entities that use a type.

2
ILSpy/Analyzers/ExportAnalyzerAttribute.cs → ICSharpCode.ILSpyX/Analyzers/ExportAnalyzerAttribute.cs

@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
using System;
using System.ComponentModel.Composition;
namespace ICSharpCode.ILSpy.Analyzers
namespace ICSharpCode.ILSpyX.Analyzers
{
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]

2
ILSpy/Analyzers/IAnalyzer.cs → ICSharpCode.ILSpyX/Analyzers/IAnalyzer.cs

@ -20,7 +20,7 @@ using System.Collections.Generic; @@ -20,7 +20,7 @@ using System.Collections.Generic;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers
namespace ICSharpCode.ILSpyX.Analyzers
{
/// <summary>
/// Base interface for all analyzers. You can register an analyzer for any <see cref="ISymbol"/> by implementing

1
ICSharpCode.ILSpyX/ICSharpCode.ILSpyX.csproj

@ -62,6 +62,7 @@ @@ -62,6 +62,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ComponentModel.Composition" />
<PackageReference Include="System.Reflection.Metadata" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" />
<PackageReference Include="System.Composition" />

2
ILSpy.Tests/Analyzers/AnalyzerScopeTests.cs

@ -23,7 +23,7 @@ using ICSharpCode.Decompiler; @@ -23,7 +23,7 @@ using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp.Resolver;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.Analyzers;
using ICSharpCode.ILSpyX.Analyzers;
using NUnit.Framework;

4
ILSpy.Tests/Analyzers/MemberImplementsInterfaceAnalyzerTests.cs

@ -25,8 +25,8 @@ using System.Reflection.PortableExecutable; @@ -25,8 +25,8 @@ using System.Reflection.PortableExecutable;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation;
using ICSharpCode.ILSpy.Analyzers;
using ICSharpCode.ILSpy.Analyzers.Builtin;
using ICSharpCode.ILSpyX.Analyzers;
using ICSharpCode.ILSpyX.Analyzers.Builtin;
using NSubstitute;

4
ILSpy.Tests/Analyzers/MethodUsesAnalyzerTests.cs

@ -6,9 +6,9 @@ using System.Threading.Tasks; @@ -6,9 +6,9 @@ using System.Threading.Tasks;
using System.Windows;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.Analyzers;
using ICSharpCode.ILSpy.Analyzers.Builtin;
using ICSharpCode.ILSpyX;
using ICSharpCode.ILSpyX.Analyzers;
using ICSharpCode.ILSpyX.Analyzers.Builtin;
using NUnit.Framework;

4
ILSpy.Tests/Analyzers/TypeUsedByAnalyzerTests.cs

@ -19,9 +19,9 @@ @@ -19,9 +19,9 @@
using System.Linq;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.Analyzers;
using ICSharpCode.ILSpy.Analyzers.Builtin;
using ICSharpCode.ILSpyX;
using ICSharpCode.ILSpyX.Analyzers;
using ICSharpCode.ILSpyX.Analyzers.Builtin;
using NUnit.Framework;

1
ILSpy/Analyzers/AnalyzerSearchTreeNode.cs

@ -25,6 +25,7 @@ using ICSharpCode.Decompiler.TypeSystem; @@ -25,6 +25,7 @@ using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.Analyzers.TreeNodes;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpyX;
using ICSharpCode.ILSpyX.Analyzers;
namespace ICSharpCode.ILSpy.Analyzers
{

46
ILSpy/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs

@ -1,46 +0,0 @@ @@ -1,46 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
{
/// <summary>
/// Finds all extension methods defined for a type.
/// </summary>
[ExportAnalyzer(Header = "Extension Methods", Order = 50)]
class TypeExtensionMethodsAnalyzer : IAnalyzer
{
public bool Show(ISymbol symbol) => symbol is ITypeDefinition entity && !entity.IsStatic;
public IEnumerable<ISymbol> Analyze(ISymbol analyzedSymbol, AnalyzerContext context)
{
Debug.Assert(analyzedSymbol is ITypeDefinition);
var scope = context.GetScopeOf((ITypeDefinition)analyzedSymbol);
foreach (var type in scope.GetTypesInScope(context.CancellationToken))
{
foreach (var result in ScanType((ITypeDefinition)analyzedSymbol, type, context))
yield return result;
}
}
IEnumerable<IEntity> ScanType(ITypeDefinition analyzedType, ITypeDefinition type, AnalyzerContext context)
{
if (!type.HasExtensionMethods)
yield break;
foreach (IMethod method in type.Methods)
{
if (!method.IsExtensionMethod)
continue;
var firstParamType = method.Parameters[0].Type.GetDefinition();
if (firstParamType != null &&
firstParamType.MetadataToken == analyzedType.MetadataToken &&
firstParamType.ParentModule.MetadataFile == analyzedType.ParentModule.MetadataFile)
yield return method;
}
}
}
}

1
ILSpy/Analyzers/TreeNodes/AnalyzedEventTreeNode.cs

@ -24,6 +24,7 @@ using ICSharpCode.ILSpy.TreeNodes; @@ -24,6 +24,7 @@ using ICSharpCode.ILSpy.TreeNodes;
namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpyX.Analyzers;
internal sealed class AnalyzedEventTreeNode : AnalyzerEntityTreeNode
{

1
ILSpy/Analyzers/TreeNodes/AnalyzedFieldTreeNode.cs

@ -21,6 +21,7 @@ using System.Linq; @@ -21,6 +21,7 @@ using System.Linq;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpyX.Analyzers;
namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{

1
ILSpy/Analyzers/TreeNodes/AnalyzedMethodTreeNode.cs

@ -21,6 +21,7 @@ using System.Linq; @@ -21,6 +21,7 @@ using System.Linq;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpyX.Analyzers;
namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{

1
ILSpy/Analyzers/TreeNodes/AnalyzedModuleTreeNode.cs

@ -21,6 +21,7 @@ using System.Linq; @@ -21,6 +21,7 @@ using System.Linq;
using System.Windows;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpyX.Analyzers;
namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{

1
ILSpy/Analyzers/TreeNodes/AnalyzedPropertyTreeNode.cs

@ -21,6 +21,7 @@ using System.Linq; @@ -21,6 +21,7 @@ using System.Linq;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpyX.Analyzers;
namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{

1
ILSpy/Analyzers/TreeNodes/AnalyzedTypeTreeNode.cs

@ -21,6 +21,7 @@ using System.Linq; @@ -21,6 +21,7 @@ using System.Linq;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpyX.Analyzers;
namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{

7
ILSpy/App.xaml.cs

@ -31,6 +31,7 @@ using System.Windows.Navigation; @@ -31,6 +31,7 @@ using System.Windows.Navigation;
using System.Windows.Threading;
using ICSharpCode.ILSpy.Options;
using ICSharpCode.ILSpyX.Analyzers;
using ICSharpCode.ILSpyX.Settings;
using Microsoft.VisualStudio.Composition;
@ -131,9 +132,13 @@ namespace ICSharpCode.ILSpy @@ -131,9 +132,13 @@ namespace ICSharpCode.ILSpy
}
}
}
// Add the built-in parts
// Add the built-in parts: First, from ILSpyX
var xParts = await discovery.CreatePartsAsync(typeof(IAnalyzer).Assembly);
catalog = catalog.AddParts(xParts);
// Then from ILSpy itself
var createdParts = await discovery.CreatePartsAsync(Assembly.GetExecutingAssembly());
catalog = catalog.AddParts(createdParts);
// If/When the project switches to .NET Standard/Core, this will be needed to allow metadata interfaces (as opposed
// to metadata classes). When running on .NET Framework, it's automatic.
// catalog.WithDesktopSupport();

Loading…
Cancel
Save