mirror of https://github.com/icsharpcode/ILSpy.git
7 changed files with 314 additions and 6 deletions
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
using System; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer |
||||
{ |
||||
/// <summary>
|
||||
/// Description of AnalyzedEventAccessorsTreeNode.
|
||||
/// </summary>
|
||||
public class AnalyzedEventAccessorsTreeNode : AnalyzerTreeNode |
||||
{ |
||||
EventDefinition analyzedEvent; |
||||
|
||||
public AnalyzedEventAccessorsTreeNode(EventDefinition analyzedEvent) |
||||
{ |
||||
if (analyzedEvent == null) |
||||
throw new ArgumentNullException("analyzedEvent"); |
||||
this.analyzedEvent = analyzedEvent; |
||||
|
||||
if (analyzedEvent.AddMethod != null) |
||||
this.Children.Add(new AnalyzedEventAccessorTreeNode(analyzedEvent.AddMethod, "add")); |
||||
if (analyzedEvent.RemoveMethod != null) |
||||
this.Children.Add(new AnalyzedEventAccessorTreeNode(analyzedEvent.RemoveMethod, "remove")); |
||||
foreach (var accessor in analyzedEvent.OtherMethods) |
||||
this.Children.Add(new AnalyzedEventAccessorTreeNode(accessor, null)); |
||||
} |
||||
|
||||
public override object Icon |
||||
{ |
||||
get { return Images.Search; } |
||||
} |
||||
|
||||
public override object Text |
||||
{ |
||||
get { return "Accessors"; } |
||||
} |
||||
|
||||
public static bool CanShow(EventDefinition property) |
||||
{ |
||||
return !MainWindow.Instance.CurrentLanguage.ShowMember(property.AddMethod ?? property.RemoveMethod); |
||||
} |
||||
|
||||
class AnalyzedEventAccessorTreeNode : AnalyzedMethodTreeNode |
||||
{ |
||||
string name; |
||||
|
||||
public AnalyzedEventAccessorTreeNode(MethodDefinition analyzedMethod, string name) |
||||
: base(analyzedMethod) |
||||
{ |
||||
this.name = name; |
||||
} |
||||
|
||||
public override object Text |
||||
{ |
||||
get { return name ?? base.Text; } |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading; |
||||
using ICSharpCode.Decompiler.Ast; |
||||
using ICSharpCode.NRefactory.Utils; |
||||
using ICSharpCode.TreeView; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer |
||||
{ |
||||
class AnalyzedEventOverridesTreeNode : AnalyzerTreeNode |
||||
{ |
||||
readonly EventDefinition analyzedEvent; |
||||
readonly ThreadingSupport threading; |
||||
|
||||
public AnalyzedEventOverridesTreeNode(EventDefinition analyzedEvent) |
||||
{ |
||||
if (analyzedEvent == null) |
||||
throw new ArgumentNullException("analyzedEvent"); |
||||
|
||||
this.analyzedEvent = analyzedEvent; |
||||
this.threading = new ThreadingSupport(); |
||||
this.LazyLoading = true; |
||||
} |
||||
|
||||
public override object Text |
||||
{ |
||||
get { return "Overriden 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(); |
||||
} |
||||
} |
||||
|
||||
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) |
||||
{ |
||||
return FindReferences(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), ct); |
||||
} |
||||
|
||||
IEnumerable<SharpTreeNode> FindReferences(IEnumerable<LoadedAssembly> assemblies, CancellationToken ct) |
||||
{ |
||||
assemblies = assemblies.Where(asm => asm.AssemblyDefinition != null); |
||||
// use parallelism only on the assembly level (avoid locks within Cecil)
|
||||
return assemblies.AsParallel().WithCancellation(ct).SelectMany((LoadedAssembly asm) => FindReferences(asm, ct)); |
||||
} |
||||
|
||||
IEnumerable<SharpTreeNode> FindReferences(LoadedAssembly asm, CancellationToken ct) |
||||
{ |
||||
string asmName = asm.AssemblyDefinition.Name.Name; |
||||
string name = analyzedEvent.Name; |
||||
string declTypeName = analyzedEvent.DeclaringType.FullName; |
||||
foreach (TypeDefinition type in TreeTraversal.PreOrder(asm.AssemblyDefinition.MainModule.Types, t => t.NestedTypes)) { |
||||
ct.ThrowIfCancellationRequested(); |
||||
|
||||
if (!TypesHierarchyHelpers.IsBaseType(analyzedEvent.DeclaringType, type, resolveTypeArguments: false)) |
||||
continue; |
||||
|
||||
foreach (EventDefinition eventDef in type.Events) { |
||||
ct.ThrowIfCancellationRequested(); |
||||
|
||||
if (TypesHierarchyHelpers.IsBaseEvent(analyzedEvent, eventDef)) { |
||||
MethodDefinition anyAccessor = eventDef.AddMethod ?? eventDef.RemoveMethod; |
||||
bool hidesParent = !anyAccessor.IsVirtual ^ anyAccessor.IsNewSlot; |
||||
yield return new AnalyzedEventTreeNode(eventDef, hidesParent ? "(hides) " : ""); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static bool CanShowAnalyzer(EventDefinition property) |
||||
{ |
||||
var accessor = property.AddMethod ?? property.RemoveMethod; |
||||
return accessor.IsVirtual && !accessor.IsFinal && !accessor.DeclaringType.IsInterface; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,81 @@
@@ -0,0 +1,81 @@
|
||||
// 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; |
||||
using ICSharpCode.Decompiler; |
||||
|
||||
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer |
||||
{ |
||||
class AnalyzedEventTreeNode : AnalyzerTreeNode |
||||
{ |
||||
EventDefinition analyzedEvent; |
||||
string prefix; |
||||
|
||||
public AnalyzedEventTreeNode(EventDefinition analyzedEvent, string prefix = "") |
||||
{ |
||||
if (analyzedEvent == null) |
||||
throw new ArgumentNullException("analyzedMethod"); |
||||
this.analyzedEvent = analyzedEvent; |
||||
this.prefix = prefix; |
||||
this.LazyLoading = true; |
||||
} |
||||
|
||||
public override object Icon { |
||||
get { return EventTreeNode.GetIcon(analyzedEvent); } |
||||
} |
||||
|
||||
public override object Text { |
||||
get { |
||||
// TODO: This way of formatting is not suitable for events which explicitly implement interfaces.
|
||||
return prefix + Language.TypeToString(analyzedEvent.DeclaringType, true) + "." + EventTreeNode.GetText(analyzedEvent, Language); } |
||||
} |
||||
|
||||
public override void ActivateItem(System.Windows.RoutedEventArgs e) |
||||
{ |
||||
e.Handled = true; |
||||
MainWindow.Instance.JumpToReference(analyzedEvent); |
||||
} |
||||
|
||||
protected override void LoadChildren() |
||||
{ |
||||
if(AnalyzedEventAccessorsTreeNode.CanShow(analyzedEvent)) |
||||
this.Children.Add(new AnalyzedEventAccessorsTreeNode(analyzedEvent)); |
||||
if (AnalyzedEventOverridesTreeNode.CanShowAnalyzer(analyzedEvent)) |
||||
this.Children.Add(new AnalyzedEventOverridesTreeNode(analyzedEvent)); |
||||
} |
||||
|
||||
public static AnalyzerTreeNode TryCreateAnalyzer(MemberReference member) |
||||
{ |
||||
if (CanShow(member)) |
||||
return new AnalyzedEventTreeNode(member as EventDefinition); |
||||
else |
||||
return null; |
||||
} |
||||
|
||||
public static bool CanShow(MemberReference member) |
||||
{ |
||||
var property = member as EventDefinition; |
||||
if (property == null) |
||||
return false; |
||||
|
||||
return AnalyzedEventAccessorsTreeNode.CanShow(property) |
||||
|| AnalyzedEventOverridesTreeNode.CanShowAnalyzer(property); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue