Browse Source

Fixed some bugs in "Used by" analyzers.

pull/131/head
Artur Zgodziński 14 years ago
parent
commit
46838a6a72
  1. 5
      ILSpy/ILSpy.csproj
  2. 3
      ILSpy/TreeNodes/Analyzer/AnalyzedFieldAccessNode.cs
  3. 3
      ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsedByTreeNode.cs
  4. 36
      ILSpy/TreeNodes/Analyzer/Helpers.cs

5
ILSpy/ILSpy.csproj

@ -130,6 +130,7 @@ @@ -130,6 +130,7 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzeContextMenuEntry.cs" />
<Compile Include="TreeNodes\Analyzer\Helpers.cs" />
<Compile Include="TreeNodes\IMemberTreeNode.cs" />
<Compile Include="TreeNodes\XamlResourceNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedPropertyAccessorsTreeNode.cs" />
@ -268,8 +269,6 @@ @@ -268,8 +269,6 @@
<Name>ICSharpCode.TreeView</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="XmlDoc" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

3
ILSpy/TreeNodes/Analyzer/AnalyzedFieldAccessNode.cs

@ -67,7 +67,6 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -67,7 +67,6 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
IEnumerable<SharpTreeNode> FindReferences(LoadedAssembly asm, CancellationToken ct)
{
string name = analyzedField.Name;
string declTypeName = analyzedField.DeclaringType.FullName;
foreach (TypeDefinition type in TreeTraversal.PreOrder(asm.AssemblyDefinition.MainModule.Types, t => t.NestedTypes)) {
ct.ThrowIfCancellationRequested();
foreach (MethodDefinition method in type.Methods) {
@ -78,7 +77,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -78,7 +77,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
foreach (Instruction instr in method.Body.Instructions) {
if (CanBeReference(instr.OpCode.Code)) {
FieldReference fr = instr.Operand as FieldReference;
if (fr != null && fr.Name == name && fr.DeclaringType.FullName == declTypeName && fr.Resolve() == analyzedField) {
if (fr != null && fr.Name == name && Helpers.IsReferencedBy(analyzedField.DeclaringType, fr.DeclaringType) && fr.Resolve() == analyzedField) {
found = true;
break;
}

3
ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsedByTreeNode.cs

@ -80,7 +80,6 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -80,7 +80,6 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
IEnumerable<SharpTreeNode> FindReferences(LoadedAssembly asm, CancellationToken ct)
{
string name = analyzedMethod.Name;
string declTypeName = analyzedMethod.DeclaringType.FullName;
foreach (TypeDefinition type in TreeTraversal.PreOrder(asm.AssemblyDefinition.MainModule.Types, t => t.NestedTypes)) {
ct.ThrowIfCancellationRequested();
foreach (MethodDefinition method in type.Methods) {
@ -90,7 +89,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -90,7 +89,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
continue;
foreach (Instruction instr in method.Body.Instructions) {
MethodReference mr = instr.Operand as MethodReference;
if (mr != null && mr.Name == name && mr.DeclaringType.FullName == declTypeName && mr.Resolve() == analyzedMethod) {
if (mr != null && mr.Name == name && Helpers.IsReferencedBy(analyzedMethod.DeclaringType, mr.DeclaringType) && mr.Resolve() == analyzedMethod) {
found = true;
break;
}

36
ILSpy/TreeNodes/Analyzer/Helpers.cs

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{
static class Helpers
{
public static bool IsReferencedBy(TypeDefinition type, TypeReference typeRef)
{
// TODO: move it to a better place after adding support for more cases.
if (type == null)
throw new ArgumentNullException("type");
if (typeRef == null)
throw new ArgumentNullException("typeRef");
if (type == typeRef)
return true;
if (type.Name != typeRef.Name)
return false;
if (type.Namespace != typeRef.Namespace)
return false;
if (type.DeclaringType != null || typeRef.DeclaringType != null) {
if (type.DeclaringType == null || typeRef.DeclaringType == null)
return false;
if (!IsReferencedBy(type.DeclaringType, typeRef.DeclaringType))
return false;
}
return true;
}
}
}
Loading…
Cancel
Save