mirror of https://github.com/icsharpcode/ILSpy.git
29 changed files with 1096 additions and 246 deletions
@ -0,0 +1,105 @@
@@ -0,0 +1,105 @@
|
||||
// Copyright (c) 2011 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; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
using ICSharpCode.Decompiler.Ast; |
||||
using ICSharpCode.TreeView; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer |
||||
{ |
||||
internal sealed class AnalyzedInterfaceEventImplementedByTreeNode : AnalyzerTreeNode |
||||
{ |
||||
private readonly EventDefinition analyzedEvent; |
||||
private readonly MethodDefinition analyzedMethod; |
||||
private readonly ThreadingSupport threading; |
||||
|
||||
public AnalyzedInterfaceEventImplementedByTreeNode(EventDefinition analyzedEvent) |
||||
{ |
||||
if (analyzedEvent == null) |
||||
throw new ArgumentNullException("analyzedEvent"); |
||||
|
||||
this.analyzedEvent = analyzedEvent; |
||||
this.analyzedMethod = this.analyzedEvent.AddMethod ?? this.analyzedEvent.RemoveMethod; |
||||
this.threading = new ThreadingSupport(); |
||||
this.LazyLoading = true; |
||||
} |
||||
|
||||
public override object Text |
||||
{ |
||||
get { return "Implemented By"; } |
||||
} |
||||
|
||||
public override object Icon |
||||
{ |
||||
get { return Images.Search; } |
||||
} |
||||
|
||||
protected override void LoadChildren() |
||||
{ |
||||
threading.LoadChildren(this, FetchChildren); |
||||
} |
||||
|
||||
protected override void OnCollapsing() |
||||
{ |
||||
if (threading.IsRunning) { |
||||
this.LazyLoading = true; |
||||
threading.Cancel(); |
||||
this.Children.Clear(); |
||||
} |
||||
} |
||||
|
||||
private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) |
||||
{ |
||||
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; |
||||
analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType); |
||||
return analyzer.PerformAnalysis(ct); |
||||
} |
||||
|
||||
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) |
||||
{ |
||||
if (!type.HasInterfaces) |
||||
yield break; |
||||
TypeReference implementedInterfaceRef = type.Interfaces.FirstOrDefault(i => i.Resolve() == analyzedMethod.DeclaringType); |
||||
if (implementedInterfaceRef == null) |
||||
yield break; |
||||
|
||||
foreach (EventDefinition ev in type.Events.Where(e => e.Name == analyzedEvent.Name)) { |
||||
MethodDefinition accessor = ev.AddMethod ?? ev.RemoveMethod; |
||||
if (TypesHierarchyHelpers.MatchInterfaceMethod(accessor, analyzedMethod, implementedInterfaceRef)) |
||||
yield return new AnalyzedEventTreeNode(ev); |
||||
yield break; |
||||
} |
||||
|
||||
foreach (EventDefinition ev in type.Events.Where(e => e.Name.EndsWith(analyzedEvent.Name))) { |
||||
MethodDefinition accessor = ev.AddMethod ?? ev.RemoveMethod; |
||||
if (accessor.HasOverrides && accessor.Overrides.Any(m => m.Resolve() == analyzedMethod)) { |
||||
yield return new AnalyzedEventTreeNode(ev); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static bool CanShow(EventDefinition ev) |
||||
{ |
||||
return ev.DeclaringType.IsInterface; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,101 @@
@@ -0,0 +1,101 @@
|
||||
// Copyright (c) 2011 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; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
using ICSharpCode.Decompiler.Ast; |
||||
using ICSharpCode.TreeView; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer |
||||
{ |
||||
internal sealed class AnalyzedInterfaceMethodImplementedByTreeNode : AnalyzerTreeNode |
||||
{ |
||||
private readonly MethodDefinition analyzedMethod; |
||||
private readonly ThreadingSupport threading; |
||||
|
||||
public AnalyzedInterfaceMethodImplementedByTreeNode(MethodDefinition analyzedMethod) |
||||
{ |
||||
if (analyzedMethod == null) |
||||
throw new ArgumentNullException("analyzedMethod"); |
||||
|
||||
this.analyzedMethod = analyzedMethod; |
||||
this.threading = new ThreadingSupport(); |
||||
this.LazyLoading = true; |
||||
} |
||||
|
||||
public override object Text |
||||
{ |
||||
get { return "Implemented By"; } |
||||
} |
||||
|
||||
public override object Icon |
||||
{ |
||||
get { return Images.Search; } |
||||
} |
||||
|
||||
protected override void LoadChildren() |
||||
{ |
||||
threading.LoadChildren(this, FetchChildren); |
||||
} |
||||
|
||||
protected override void OnCollapsing() |
||||
{ |
||||
if (threading.IsRunning) { |
||||
this.LazyLoading = true; |
||||
threading.Cancel(); |
||||
this.Children.Clear(); |
||||
} |
||||
} |
||||
|
||||
private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) |
||||
{ |
||||
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; |
||||
analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType); |
||||
return analyzer.PerformAnalysis(ct); |
||||
} |
||||
|
||||
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) |
||||
{ |
||||
if (!type.HasInterfaces) |
||||
yield break; |
||||
TypeReference implementedInterfaceRef = type.Interfaces.FirstOrDefault(i => i.Resolve() == analyzedMethod.DeclaringType); |
||||
if (implementedInterfaceRef == null) |
||||
yield break; |
||||
|
||||
foreach (MethodDefinition method in type.Methods.Where(m => m.Name == analyzedMethod.Name)) { |
||||
if (TypesHierarchyHelpers.MatchInterfaceMethod(method, analyzedMethod, implementedInterfaceRef)) |
||||
yield return new AnalyzedMethodTreeNode(method); |
||||
yield break; |
||||
} |
||||
|
||||
foreach (MethodDefinition method in type.Methods) { |
||||
if (method.HasOverrides && method.Overrides.Any(m => m.Resolve() == analyzedMethod)) { |
||||
yield return new AnalyzedMethodTreeNode(method); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static bool CanShow(MethodDefinition method) |
||||
{ |
||||
return method.DeclaringType.IsInterface; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,105 @@
@@ -0,0 +1,105 @@
|
||||
// Copyright (c) 2011 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; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
using ICSharpCode.Decompiler.Ast; |
||||
using ICSharpCode.TreeView; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer |
||||
{ |
||||
internal sealed class AnalyzedInterfacePropertyImplementedByTreeNode : AnalyzerTreeNode |
||||
{ |
||||
private readonly PropertyDefinition analyzedProperty; |
||||
private readonly MethodDefinition analyzedMethod; |
||||
private readonly ThreadingSupport threading; |
||||
|
||||
public AnalyzedInterfacePropertyImplementedByTreeNode(PropertyDefinition analyzedProperty) |
||||
{ |
||||
if (analyzedProperty == null) |
||||
throw new ArgumentNullException("analyzedProperty"); |
||||
|
||||
this.analyzedProperty = analyzedProperty; |
||||
this.analyzedMethod = this.analyzedProperty.GetMethod ?? this.analyzedProperty.SetMethod; |
||||
this.threading = new ThreadingSupport(); |
||||
this.LazyLoading = true; |
||||
} |
||||
|
||||
public override object Text |
||||
{ |
||||
get { return "Implemented By"; } |
||||
} |
||||
|
||||
public override object Icon |
||||
{ |
||||
get { return Images.Search; } |
||||
} |
||||
|
||||
protected override void LoadChildren() |
||||
{ |
||||
threading.LoadChildren(this, FetchChildren); |
||||
} |
||||
|
||||
protected override void OnCollapsing() |
||||
{ |
||||
if (threading.IsRunning) { |
||||
this.LazyLoading = true; |
||||
threading.Cancel(); |
||||
this.Children.Clear(); |
||||
} |
||||
} |
||||
|
||||
private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) |
||||
{ |
||||
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; |
||||
analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType); |
||||
return analyzer.PerformAnalysis(ct); |
||||
} |
||||
|
||||
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) |
||||
{ |
||||
if (!type.HasInterfaces) |
||||
yield break; |
||||
TypeReference implementedInterfaceRef = type.Interfaces.FirstOrDefault(i => i.Resolve() == analyzedMethod.DeclaringType); |
||||
if (implementedInterfaceRef == null) |
||||
yield break; |
||||
|
||||
foreach (PropertyDefinition property in type.Properties.Where(e => e.Name == analyzedProperty.Name)) { |
||||
MethodDefinition accessor = property.GetMethod ?? property.SetMethod; |
||||
if (TypesHierarchyHelpers.MatchInterfaceMethod(accessor, analyzedMethod, implementedInterfaceRef)) |
||||
yield return new AnalyzedPropertyTreeNode(property); |
||||
yield break; |
||||
} |
||||
|
||||
foreach (PropertyDefinition property in type.Properties.Where(e => e.Name.EndsWith(analyzedProperty.Name))) { |
||||
MethodDefinition accessor = property.GetMethod ?? property.SetMethod; |
||||
if (accessor.HasOverrides && accessor.Overrides.Any(m => m.Resolve() == analyzedMethod)) { |
||||
yield return new AnalyzedPropertyTreeNode(property); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static bool CanShow(PropertyDefinition property) |
||||
{ |
||||
return property.DeclaringType.IsInterface; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,184 @@
@@ -0,0 +1,184 @@
|
||||
// Copyright (c) 2011 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; |
||||
using System.Collections.Generic; |
||||
using System.Threading; |
||||
using ICSharpCode.TreeView; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer |
||||
{ |
||||
internal sealed class AnalyzedTypeExposedByTreeNode : AnalyzerTreeNode |
||||
{ |
||||
private readonly TypeDefinition analyzedType; |
||||
private readonly ThreadingSupport threading; |
||||
|
||||
public AnalyzedTypeExposedByTreeNode(TypeDefinition analyzedType) |
||||
{ |
||||
if (analyzedType == null) |
||||
throw new ArgumentNullException("analyzedType"); |
||||
|
||||
this.analyzedType = analyzedType; |
||||
this.threading = new ThreadingSupport(); |
||||
this.LazyLoading = true; |
||||
} |
||||
|
||||
public override object Text |
||||
{ |
||||
get { return "Exposed By"; } |
||||
} |
||||
|
||||
public override object Icon |
||||
{ |
||||
get { return Images.Search; } |
||||
} |
||||
|
||||
protected override void LoadChildren() |
||||
{ |
||||
threading.LoadChildren(this, FetchChildren); |
||||
} |
||||
|
||||
protected override void OnCollapsing() |
||||
{ |
||||
if (threading.IsRunning) { |
||||
this.LazyLoading = true; |
||||
threading.Cancel(); |
||||
this.Children.Clear(); |
||||
} |
||||
} |
||||
|
||||
private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) |
||||
{ |
||||
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; |
||||
|
||||
analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedType, FindReferencesInType); |
||||
return analyzer.PerformAnalysis(ct); |
||||
} |
||||
|
||||
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) |
||||
{ |
||||
if (analyzedType.IsEnum && type == analyzedType) |
||||
yield break; |
||||
|
||||
if (!this.Language.ShowMember(type)) |
||||
yield break; |
||||
|
||||
foreach (FieldDefinition field in type.Fields) { |
||||
if (TypeIsExposedBy(field)) |
||||
yield return new AnalyzedFieldTreeNode(field); |
||||
} |
||||
|
||||
foreach (PropertyDefinition property in type.Properties) { |
||||
if (TypeIsExposedBy(property)) |
||||
yield return new AnalyzedPropertyTreeNode(property); |
||||
} |
||||
|
||||
foreach (EventDefinition eventDef in type.Events) { |
||||
if (TypeIsExposedBy(eventDef)) |
||||
yield return new AnalyzedEventTreeNode(eventDef); |
||||
} |
||||
|
||||
foreach (MethodDefinition method in type.Methods) { |
||||
if (TypeIsExposedBy(method)) |
||||
yield return new AnalyzedMethodTreeNode(method); |
||||
} |
||||
} |
||||
|
||||
private bool TypeIsExposedBy(FieldDefinition field) |
||||
{ |
||||
if (field.IsPrivate) |
||||
return false; |
||||
|
||||
if (field.FieldType.Resolve() == analyzedType) |
||||
return true; |
||||
|
||||
return false; |
||||
} |
||||
|
||||
private bool TypeIsExposedBy(PropertyDefinition property) |
||||
{ |
||||
if (IsPrivate(property)) |
||||
return false; |
||||
|
||||
if (property.PropertyType.Resolve() == analyzedType) |
||||
return true; |
||||
|
||||
return false; |
||||
} |
||||
|
||||
private bool TypeIsExposedBy(EventDefinition eventDef) |
||||
{ |
||||
if (IsPrivate(eventDef)) |
||||
return false; |
||||
|
||||
if (eventDef.EventType.Resolve() == analyzedType) |
||||
return true; |
||||
|
||||
return false; |
||||
} |
||||
|
||||
private bool TypeIsExposedBy(MethodDefinition method) |
||||
{ |
||||
// if the method has overrides, it is probably an explicit interface member
|
||||
// and should be considered part of the public API even though it is marked private.
|
||||
if (method.IsPrivate) { |
||||
if (!method.HasOverrides) |
||||
return false; |
||||
else if (!method.Overrides[0].DeclaringType.Resolve().IsInterface) |
||||
return false; |
||||
} |
||||
|
||||
// exclude methods with 'semantics'. for example, property getters & setters.
|
||||
// HACK: this is a potentially fragile implementation, as the MethodSemantics may be extended to other uses at a later date.
|
||||
if (method.SemanticsAttributes != MethodSemanticsAttributes.None) |
||||
return false; |
||||
|
||||
if (method.ReturnType.Resolve() == analyzedType) |
||||
return true; |
||||
|
||||
if (method.HasParameters) { |
||||
foreach (var parameter in method.Parameters) { |
||||
if (parameter.ParameterType.Resolve() == analyzedType) |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
private static bool IsPrivate(PropertyDefinition property) |
||||
{ |
||||
bool isGetterPublic = (property.GetMethod != null && !property.GetMethod.IsPrivate); |
||||
bool isSetterPublic = (property.SetMethod != null && !property.SetMethod.IsPrivate); |
||||
return !(isGetterPublic || isSetterPublic); |
||||
} |
||||
|
||||
private static bool IsPrivate(EventDefinition eventDef) |
||||
{ |
||||
bool isAdderPublic = (eventDef.AddMethod != null && !eventDef.AddMethod.IsPrivate); |
||||
bool isRemoverPublic = (eventDef.RemoveMethod != null && !eventDef.RemoveMethod.IsPrivate); |
||||
return !(isAdderPublic || isRemoverPublic); |
||||
} |
||||
|
||||
public static bool CanShow(TypeDefinition type) |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
// Copyright (c) 2011 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; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
using ICSharpCode.TreeView; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer |
||||
{ |
||||
internal class AnalyzedTypeExtensionMethodsTreeNode : AnalyzerTreeNode |
||||
{ |
||||
private readonly TypeDefinition analyzedType; |
||||
private readonly ThreadingSupport threading; |
||||
|
||||
public AnalyzedTypeExtensionMethodsTreeNode(TypeDefinition analyzedType) |
||||
{ |
||||
if (analyzedType == null) |
||||
throw new ArgumentNullException("analyzedType"); |
||||
|
||||
this.analyzedType = analyzedType; |
||||
this.threading = new ThreadingSupport(); |
||||
this.LazyLoading = true; |
||||
} |
||||
|
||||
public override object Text |
||||
{ |
||||
get { return "Extension Methods"; } |
||||
} |
||||
|
||||
public override object Icon |
||||
{ |
||||
get { return Images.Search; } |
||||
} |
||||
|
||||
protected override void LoadChildren() |
||||
{ |
||||
threading.LoadChildren(this, FetchChildren); |
||||
} |
||||
|
||||
protected override void OnCollapsing() |
||||
{ |
||||
if (threading.IsRunning) { |
||||
this.LazyLoading = true; |
||||
threading.Cancel(); |
||||
this.Children.Clear(); |
||||
} |
||||
} |
||||
|
||||
private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) |
||||
{ |
||||
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; |
||||
|
||||
analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedType, FindReferencesInType); |
||||
return analyzer.PerformAnalysis(ct); |
||||
} |
||||
|
||||
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) |
||||
{ |
||||
foreach (MethodDefinition method in type.Methods) { |
||||
if (method.IsStatic && method.HasCustomAttributes) { |
||||
if (method.CustomAttributes.Any(ca => ca.AttributeType.FullName == "System.Runtime.CompilerServices.ExtensionAttribute")) { |
||||
if (method.HasParameters && method.Parameters[0].ParameterType.Resolve() == analyzedType) { |
||||
yield return new AnalyzedMethodTreeNode(method); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static bool CanShow(TypeDefinition type) |
||||
{ |
||||
return !(type.IsEnum); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,118 @@
@@ -0,0 +1,118 @@
|
||||
// Copyright (c) 2011 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; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
using ICSharpCode.Decompiler.Ast; |
||||
using ICSharpCode.TreeView; |
||||
using Mono.Cecil; |
||||
using Mono.Cecil.Cil; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer |
||||
{ |
||||
internal sealed class AnalyzedTypeInstantiationsTreeNode : AnalyzerTreeNode |
||||
{ |
||||
private readonly TypeDefinition analyzedType; |
||||
private readonly ThreadingSupport threading; |
||||
private readonly bool isSystemObject; |
||||
|
||||
public AnalyzedTypeInstantiationsTreeNode(TypeDefinition analyzedType) |
||||
{ |
||||
if (analyzedType == null) |
||||
throw new ArgumentNullException("analyzedType"); |
||||
|
||||
this.analyzedType = analyzedType; |
||||
this.threading = new ThreadingSupport(); |
||||
this.LazyLoading = true; |
||||
|
||||
this.isSystemObject = (analyzedType.FullName == "System.Object"); |
||||
} |
||||
|
||||
public override object Text |
||||
{ |
||||
get { return "Instantiated By"; } |
||||
} |
||||
|
||||
public override object Icon |
||||
{ |
||||
get { return Images.Search; } |
||||
} |
||||
|
||||
protected override void LoadChildren() |
||||
{ |
||||
threading.LoadChildren(this, FetchChildren); |
||||
} |
||||
|
||||
protected override void OnCollapsing() |
||||
{ |
||||
if (threading.IsRunning) { |
||||
this.LazyLoading = true; |
||||
threading.Cancel(); |
||||
this.Children.Clear(); |
||||
} |
||||
} |
||||
|
||||
private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) |
||||
{ |
||||
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; |
||||
|
||||
analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedType, FindReferencesInType); |
||||
return analyzer.PerformAnalysis(ct); |
||||
} |
||||
|
||||
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) |
||||
{ |
||||
foreach (MethodDefinition method in type.Methods) { |
||||
bool found = false; |
||||
if (!method.HasBody) |
||||
continue; |
||||
|
||||
// ignore chained constructors
|
||||
// (since object is the root of everything, we can short circuit the test in this case)
|
||||
if (method.Name == ".ctor" && |
||||
(isSystemObject || analyzedType == type || TypesHierarchyHelpers.IsBaseType(analyzedType, type, false))) |
||||
continue; |
||||
|
||||
foreach (Instruction instr in method.Body.Instructions) { |
||||
MethodReference mr = instr.Operand as MethodReference; |
||||
if (mr != null && mr.Name == ".ctor") { |
||||
if (Helpers.IsReferencedBy(analyzedType, mr.DeclaringType)) { |
||||
found = true; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
method.Body = null; |
||||
|
||||
if (found) |
||||
yield return new AnalyzedMethodTreeNode(method); |
||||
} |
||||
} |
||||
|
||||
public static bool CanShow(TypeDefinition type) |
||||
{ |
||||
if (type.IsClass && !type.IsEnum) { |
||||
return type.Methods.Where(m => m.Name == ".ctor").Any(m => !m.IsPrivate); |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
// Copyright (c) 2011 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; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer |
||||
{ |
||||
internal class AnalyzedTypeTreeNode : AnalyzerTreeNode, IMemberTreeNode |
||||
{ |
||||
private readonly TypeDefinition analyzedType; |
||||
|
||||
public AnalyzedTypeTreeNode(TypeDefinition analyzedType) |
||||
{ |
||||
if (analyzedType == null) |
||||
throw new ArgumentNullException("analyzedType"); |
||||
this.analyzedType = analyzedType; |
||||
this.LazyLoading = true; |
||||
} |
||||
|
||||
public override object Icon |
||||
{ |
||||
get { return TypeTreeNode.GetIcon(analyzedType); } |
||||
} |
||||
|
||||
public override object Text |
||||
{ |
||||
get |
||||
{ |
||||
return Language.TypeToString(analyzedType, true); |
||||
} |
||||
} |
||||
|
||||
public override void ActivateItem(System.Windows.RoutedEventArgs e) |
||||
{ |
||||
e.Handled = true; |
||||
MainWindow.Instance.JumpToReference(analyzedType); |
||||
} |
||||
|
||||
protected override void LoadChildren() |
||||
{ |
||||
if (AnalyzedTypeInstantiationsTreeNode.CanShow(analyzedType)) |
||||
this.Children.Add(new AnalyzedTypeInstantiationsTreeNode(analyzedType)); |
||||
|
||||
if (AnalyzedTypeExposedByTreeNode.CanShow(analyzedType)) |
||||
this.Children.Add(new AnalyzedTypeExposedByTreeNode(analyzedType)); |
||||
|
||||
if (AnalyzedTypeExtensionMethodsTreeNode.CanShow(analyzedType)) |
||||
this.Children.Add(new AnalyzedTypeExtensionMethodsTreeNode(analyzedType)); |
||||
} |
||||
|
||||
MemberReference IMemberTreeNode.Member |
||||
{ |
||||
get { return analyzedType; } |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue