Skip to content

Commit

Permalink
Move non-UI analyzer code to ILSpyX
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwille committed Mar 29, 2024
1 parent 3ebeb7d commit 8acd117
Show file tree
Hide file tree
Showing 37 changed files with 68 additions and 33 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
3 changes: 3 additions & 0 deletions ICSharpCode.ILSpyX/Abstractions/ILanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

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.
Expand All @@ -42,7 +42,7 @@ public class AnalyzerContext
/// <summary>
/// Currently used language.
/// </summary>
public Language Language { get; internal set; }
public ILanguage Language { get; internal set; }

Check failure on line 45 in ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Language' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check failure on line 45 in ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Non-nullable property 'Language' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check failure on line 45 in ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Non-nullable property 'Language' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

/// <summary>
/// Allows the analyzer to control whether the tree nodes will be sorted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.ILSpy.Analyzers
namespace ICSharpCode.ILSpyX.Analyzers
{
internal static class AnalyzerHelpers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
using ICSharpCode.Decompiler.Util;
using ICSharpCode.ILSpyX;

namespace ICSharpCode.ILSpy.Analyzers
namespace ICSharpCode.ILSpyX.Analyzers
{
using ICSharpCode.Decompiler.TypeSystem;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows events that implement an interface event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows events that override an event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

using ILOpCode = System.Reflection.Metadata.ILOpCode;

namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Finds methods where this field is read.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
public enum TokenSearchResult : byte
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows methods that implement an interface method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows methods that override a method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows properties that implement an interface property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Shows properties that override a property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
using System.Threading.Tasks;


namespace ICSharpCode.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
using ICSharpCode.Decompiler.TypeSystem;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
using System.Collections.Generic;
// 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.ILSpy.Analyzers.Builtin
namespace ICSharpCode.ILSpyX.Analyzers.Builtin
{
/// <summary>
/// Finds all extension methods defined for a type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using System;
using System.ComponentModel.Composition;

namespace ICSharpCode.ILSpy.Analyzers
namespace ICSharpCode.ILSpyX.Analyzers
{
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

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
Expand Down
1 change: 1 addition & 0 deletions ICSharpCode.ILSpyX/ICSharpCode.ILSpyX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
2 changes: 1 addition & 1 deletion ILSpy.Tests/Analyzers/AnalyzerScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
using ICSharpCode.Decompiler.CSharp.Resolver;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.Analyzers;
using ICSharpCode.ILSpyX.Analyzers;

using NUnit.Framework;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
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;

Expand Down
4 changes: 2 additions & 2 deletions ILSpy.Tests/Analyzers/MethodUsesAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
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;

Expand Down
4 changes: 2 additions & 2 deletions ILSpy.Tests/Analyzers/TypeUsedByAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions ILSpy/Analyzers/AnalyzerSearchTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using ICSharpCode.ILSpy.Analyzers.TreeNodes;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpyX;
using ICSharpCode.ILSpyX.Analyzers;

namespace ICSharpCode.ILSpy.Analyzers
{
Expand Down
1 change: 1 addition & 0 deletions ILSpy/Analyzers/TreeNodes/AnalyzedEventTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpyX.Analyzers;

internal sealed class AnalyzedEventTreeNode : AnalyzerEntityTreeNode
{
Expand Down
1 change: 1 addition & 0 deletions ILSpy/Analyzers/TreeNodes/AnalyzedFieldTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpyX.Analyzers;

namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{
Expand Down
1 change: 1 addition & 0 deletions ILSpy/Analyzers/TreeNodes/AnalyzedMethodTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpyX.Analyzers;

namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{
Expand Down
1 change: 1 addition & 0 deletions ILSpy/Analyzers/TreeNodes/AnalyzedModuleTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Windows;

using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpyX.Analyzers;

namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{
Expand Down
1 change: 1 addition & 0 deletions ILSpy/Analyzers/TreeNodes/AnalyzedPropertyTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpyX.Analyzers;

namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{
Expand Down
1 change: 1 addition & 0 deletions ILSpy/Analyzers/TreeNodes/AnalyzedTypeTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpyX.Analyzers;

namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{
Expand Down
7 changes: 6 additions & 1 deletion ILSpy/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using System.Windows.Threading;

using ICSharpCode.ILSpy.Options;
using ICSharpCode.ILSpyX.Analyzers;
using ICSharpCode.ILSpyX.Settings;

using Microsoft.VisualStudio.Composition;
Expand Down Expand Up @@ -131,9 +132,13 @@ private static async Task InitializeMef()
}
}
}
// 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();
Expand Down

0 comments on commit 8acd117

Please sign in to comment.