From 34641c7785d37336fb92075043c37eac6818988a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 9 Jul 2018 17:50:26 +0200 Subject: [PATCH] Move Analyzer types to correct namespaces. --- ILSpy/Analyzers/AnalyzeContextMenuEntry.cs | 2 +- ILSpy/Analyzers/AnalyzerSearchTreeNode.cs | 22 +++++++++---------- ILSpy/Analyzers/AnalyzerTreeView.cs | 1 - .../Analyzers/Builtin/FieldAccessAnalyzer.cs | 2 +- .../Analyzers/Builtin/MethodUsedByAnalyzer.cs | 11 ---------- ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs | 20 ++++++++++++++--- ILSpy/Analyzers/ScopedWhereUsedAnalyzer.cs | 4 ++-- 7 files changed, 32 insertions(+), 30 deletions(-) diff --git a/ILSpy/Analyzers/AnalyzeContextMenuEntry.cs b/ILSpy/Analyzers/AnalyzeContextMenuEntry.cs index 7d2d638dd..221ad2748 100644 --- a/ILSpy/Analyzers/AnalyzeContextMenuEntry.cs +++ b/ILSpy/Analyzers/AnalyzeContextMenuEntry.cs @@ -19,8 +19,8 @@ using System; using System.Linq; using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.ILSpy.Analyzers.TreeNodes; using ICSharpCode.ILSpy.TreeNodes; -using ICSharpCode.ILSpy.TreeNodes.Analyzer; namespace ICSharpCode.ILSpy.Analyzers { diff --git a/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs b/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs index 7899d068f..802d56403 100644 --- a/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs +++ b/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs @@ -20,8 +20,8 @@ using System; using System.Collections.Generic; using System.Threading; using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.ILSpy.Analyzers.TreeNodes; using ICSharpCode.ILSpy.TreeNodes; -using ICSharpCode.ILSpy.TreeNodes.Analyzer; namespace ICSharpCode.ILSpy.Analyzers { @@ -46,7 +46,7 @@ namespace ICSharpCode.ILSpy.Analyzers { threading.LoadChildren(this, FetchChildren); } - + protected IEnumerable FetchChildren(CancellationToken ct) { if (analyzer is IEntityAnalyzer entityAnalyzer) { @@ -81,14 +81,14 @@ namespace ICSharpCode.ILSpy.Analyzers return new AnalyzedMethodTreeNode(md) { Language = this.Language }; - //case IProperty pd: - // return new AnalyzedPropertyTreeNode(pd) { - //Language = this.Language - //}; - //case IEvent ed: - // return new AnalyzedEventTreeNode(ed) { - //Language = this.Language - //}; + case IProperty pd: + return new AnalyzedPropertyTreeNode(pd) { + Language = this.Language + }; + case IEvent ed: + return new AnalyzedEventTreeNode(ed) { + Language = this.Language + }; default: throw new NotSupportedException(); } @@ -103,7 +103,7 @@ namespace ICSharpCode.ILSpy.Analyzers this.Children.Clear(); } } - + public override bool HandleAssemblyListChanged(ICollection removedAssemblies, ICollection addedAssemblies) { // only cancel a running analysis if user has manually added/removed assemblies diff --git a/ILSpy/Analyzers/AnalyzerTreeView.cs b/ILSpy/Analyzers/AnalyzerTreeView.cs index c9236775e..1849cb52b 100644 --- a/ILSpy/Analyzers/AnalyzerTreeView.cs +++ b/ILSpy/Analyzers/AnalyzerTreeView.cs @@ -20,7 +20,6 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Windows; -using ICSharpCode.ILSpy.TreeNodes.Analyzer; using ICSharpCode.TreeView; namespace ICSharpCode.ILSpy.Analyzers diff --git a/ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs b/ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs index 98adfb21f..f2bbe9d6d 100644 --- a/ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs @@ -31,7 +31,7 @@ using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.ILSpy.Analyzers; using ILOpCode = System.Reflection.Metadata.ILOpCode; -namespace ICSharpCode.ILSpy.TreeNodes.Analyzer +namespace ICSharpCode.ILSpy.Analyzers.Builtin { /// /// Finds methods where this field is read. diff --git a/ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs b/ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs index 7344bf800..845c01b9c 100644 --- a/ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs @@ -51,16 +51,5 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin } } } - - - - bool ScanMethodBody(PEFile module, int rva) - { - var blob = module.Reader.GetMethodBody(rva).GetILReader(); - while (blob.RemainingBytes > 0) { - } - - return false; - } } } diff --git a/ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs b/ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs index be53583ad..56d629017 100644 --- a/ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs @@ -35,6 +35,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin if (!md.HasBody()) yield break; var blob = module.Reader.GetMethodBody(md.RelativeVirtualAddress).GetILReader(); + var visitor = new TypeDefinitionCollector(); while (blob.RemainingBytes > 0) { var opCode = blob.DecodeOpCode(); @@ -52,9 +53,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin case HandleKind.TypeDefinition: case HandleKind.TypeReference: case HandleKind.TypeSpecification: - var type = context.TypeSystem.ResolveAsType(member).GetDefinition(); - if (type != null) - yield return type; + context.TypeSystem.ResolveAsType(member).AcceptVisitor(visitor); break; case HandleKind.MethodDefinition: case HandleKind.MethodSpecification: @@ -71,6 +70,21 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin break; } } + + foreach (var type in visitor.UsedTypes) { + yield return type; + } + } + + class TypeDefinitionCollector : TypeVisitor + { + public readonly List UsedTypes = new List(); + + public override IType VisitTypeDefinition(ITypeDefinition type) + { + UsedTypes.Add(type); + return base.VisitTypeDefinition(type); + } } } } diff --git a/ILSpy/Analyzers/ScopedWhereUsedAnalyzer.cs b/ILSpy/Analyzers/ScopedWhereUsedAnalyzer.cs index d405addba..e346de9a5 100644 --- a/ILSpy/Analyzers/ScopedWhereUsedAnalyzer.cs +++ b/ILSpy/Analyzers/ScopedWhereUsedAnalyzer.cs @@ -28,7 +28,7 @@ using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.Util; using ICSharpCode.ILSpy.Analyzers; -namespace ICSharpCode.ILSpy.TreeNodes.Analyzer +namespace ICSharpCode.ILSpy.Analyzers { /// /// Determines the accessibility domain of a member for where-used analysis. @@ -48,7 +48,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer { this.language = language ?? throw new ArgumentNullException(nameof(language)); this.analyzer = analyzer ?? throw new ArgumentNullException(nameof(analyzer)); - this.analyzedEntity = analyzedEntity ; + this.analyzedEntity = analyzedEntity; this.assemblyScope = analyzedEntity.ParentAssembly; if (analyzedEntity is ITypeDefinition type) { this.typeScope = type;