mirror of https://github.com/icsharpcode/ILSpy.git
48 changed files with 1938 additions and 397 deletions
@ -0,0 +1,88 @@
@@ -0,0 +1,88 @@
|
||||
// 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.Text; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
|
||||
using ICSharpCode.ILSpy.TreeNodes.Analyzer; |
||||
using ICSharpCode.TreeView; |
||||
|
||||
namespace ICSharpCode.ILSpy |
||||
{ |
||||
/// <summary>
|
||||
/// Analyzer tree view.
|
||||
/// </summary>
|
||||
public partial class AnalyzerTreeView : SharpTreeView, IPane |
||||
{ |
||||
static AnalyzerTreeView instance; |
||||
|
||||
public static AnalyzerTreeView Instance { |
||||
get { |
||||
if (instance == null) { |
||||
App.Current.VerifyAccess(); |
||||
instance = new AnalyzerTreeView(); |
||||
} |
||||
return instance; |
||||
} |
||||
} |
||||
|
||||
private AnalyzerTreeView() |
||||
{ |
||||
this.ShowRoot = false; |
||||
this.Root = new AnalyzerTreeNode { Language = MainWindow.Instance.CurrentLanguage }; |
||||
ContextMenuProvider.Add(this); |
||||
} |
||||
|
||||
public void Show() |
||||
{ |
||||
if (!IsVisible) |
||||
MainWindow.Instance.ShowInBottomPane("Analyzer", this); |
||||
} |
||||
|
||||
public void Show(AnalyzerTreeNode node) |
||||
{ |
||||
Show(); |
||||
|
||||
node.IsExpanded = true; |
||||
this.Root.Children.Add(node); |
||||
this.SelectedItem = node; |
||||
this.FocusNode(node); |
||||
} |
||||
|
||||
void IPane.Closed() |
||||
{ |
||||
this.Root.Children.Clear(); |
||||
} |
||||
} |
||||
|
||||
[ExportMainMenuCommand(Menu = "_View", Header = "_Analyzer", MenuCategory = "ShowPane", MenuOrder = 100)] |
||||
sealed class ShowAnalyzerCommand : SimpleCommand |
||||
{ |
||||
public override void Execute(object parameter) |
||||
{ |
||||
AnalyzerTreeView.Instance.Show(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,117 @@
@@ -0,0 +1,117 @@
|
||||
// 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.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Input; |
||||
using System.Windows.Markup; |
||||
using System.Windows.Media; |
||||
|
||||
namespace ICSharpCode.ILSpy.Controls |
||||
{ |
||||
class DockedPane : Control |
||||
{ |
||||
static DockedPane() |
||||
{ |
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(DockedPane), new FrameworkPropertyMetadata(typeof(DockedPane))); |
||||
} |
||||
|
||||
public static readonly DependencyProperty TitleProperty = |
||||
DependencyProperty.Register("Title", typeof(string), typeof(DockedPane)); |
||||
|
||||
public string Title { |
||||
get { return (string)GetValue(TitleProperty); } |
||||
set { SetValue(TitleProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty ContentProperty = |
||||
DependencyProperty.Register("Content", typeof(object), typeof(DockedPane)); |
||||
|
||||
public object Content { |
||||
get { return GetValue(ContentProperty); } |
||||
set { SetValue(ContentProperty, value); } |
||||
} |
||||
|
||||
public override void OnApplyTemplate() |
||||
{ |
||||
base.OnApplyTemplate(); |
||||
Button closeButton = (Button)this.Template.FindName("PART_Close", this); |
||||
if (closeButton != null) { |
||||
closeButton.Click += closeButton_Click; |
||||
} |
||||
} |
||||
|
||||
void closeButton_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
if (CloseButtonClicked != null) |
||||
CloseButtonClicked(this, e); |
||||
} |
||||
|
||||
public event EventHandler CloseButtonClicked; |
||||
|
||||
protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e) |
||||
{ |
||||
base.OnKeyDown(e); |
||||
if (e.Key == Key.F4 && e.KeyboardDevice.Modifiers == ModifierKeys.Control || e.Key == Key.Escape) { |
||||
if (CloseButtonClicked != null) |
||||
CloseButtonClicked(this, e); |
||||
e.Handled = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
[MarkupExtensionReturnType(typeof(Color))] |
||||
class ControlColor : MarkupExtension |
||||
{ |
||||
float val; |
||||
|
||||
/// <summary>
|
||||
/// Amount of highlight (0..1)
|
||||
/// </summary>
|
||||
public float Highlight { get; set; } |
||||
|
||||
/// <summary>
|
||||
/// val: Color value in the range 105..255.
|
||||
/// </summary>
|
||||
public ControlColor(float val) |
||||
{ |
||||
if (!(val >= 105 && val <= 255)) |
||||
throw new ArgumentOutOfRangeException("val"); |
||||
this.val = val; |
||||
} |
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider) |
||||
{ |
||||
if (val > 227) { |
||||
return Interpolate(227, SystemColors.ControlLightColor, 255, SystemColors.ControlLightLightColor); |
||||
} else if (val > 160) { |
||||
return Interpolate(160, SystemColors.ControlDarkColor, 227, SystemColors.ControlLightColor); |
||||
} else { |
||||
return Interpolate(105, SystemColors.ControlDarkDarkColor, 160, SystemColors.ControlDarkColor); |
||||
} |
||||
} |
||||
|
||||
Color Interpolate(float v1, Color c1, float v2, Color c2) |
||||
{ |
||||
float v = (val - v1) / (v2 - v1); |
||||
Color c = c1 * (1 - v) + c2 * v; |
||||
return c * (1 - Highlight) + SystemColors.HighlightColor * Highlight; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,288 @@
@@ -0,0 +1,288 @@
|
||||
// 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.Collections.ObjectModel; |
||||
using System.ComponentModel; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
using System.Windows.Threading; |
||||
using ICSharpCode.ILSpy.TreeNodes; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.ILSpy |
||||
{ |
||||
/// <summary>
|
||||
/// Notifies panes when they are closed.
|
||||
/// </summary>
|
||||
public interface IPane |
||||
{ |
||||
void Closed(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Search pane
|
||||
/// </summary>
|
||||
public partial class SearchPane : UserControl, IPane |
||||
{ |
||||
static SearchPane instance; |
||||
RunningSearch currentSearch; |
||||
|
||||
public static SearchPane Instance { |
||||
get { |
||||
if (instance == null) { |
||||
App.Current.VerifyAccess(); |
||||
instance = new SearchPane(); |
||||
} |
||||
return instance; |
||||
} |
||||
} |
||||
|
||||
private SearchPane() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
|
||||
public void Show() |
||||
{ |
||||
if (!IsVisible) |
||||
MainWindow.Instance.ShowInTopPane("Search", this); |
||||
Dispatcher.BeginInvoke( |
||||
DispatcherPriority.Background, |
||||
new Func<bool>(searchBox.Focus)); |
||||
} |
||||
|
||||
public static readonly DependencyProperty SearchTermProperty = |
||||
DependencyProperty.Register("SearchTerm", typeof(string), typeof(SearchPane), |
||||
new FrameworkPropertyMetadata(string.Empty, OnSearchTermChanged)); |
||||
|
||||
public string SearchTerm { |
||||
get { return (string)GetValue(SearchTermProperty); } |
||||
set { SetValue(SearchTermProperty, value); } |
||||
} |
||||
|
||||
static void OnSearchTermChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) |
||||
{ |
||||
((SearchPane)o).StartSearch((string)e.NewValue); |
||||
} |
||||
|
||||
void StartSearch(string searchTerm) |
||||
{ |
||||
if (currentSearch != null) { |
||||
currentSearch.Cancel(); |
||||
} |
||||
if (string.IsNullOrEmpty(searchTerm)) { |
||||
currentSearch = null; |
||||
listBox.ItemsSource = null; |
||||
} else { |
||||
MainWindow mainWindow = MainWindow.Instance; |
||||
currentSearch = new RunningSearch(mainWindow.CurrentAssemblyList.GetAssemblies(), searchTerm, mainWindow.CurrentLanguage); |
||||
listBox.ItemsSource = currentSearch.Results; |
||||
new Thread(currentSearch.Run).Start(); |
||||
} |
||||
} |
||||
|
||||
void IPane.Closed() |
||||
{ |
||||
this.SearchTerm = string.Empty; |
||||
} |
||||
|
||||
void ListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) |
||||
{ |
||||
JumpToSelectedItem(); |
||||
e.Handled = true; |
||||
} |
||||
|
||||
void ListBox_KeyDown(object sender, KeyEventArgs e) |
||||
{ |
||||
if (e.Key == Key.Space || e.Key == Key.Return) { |
||||
e.Handled = true; |
||||
JumpToSelectedItem(); |
||||
} |
||||
} |
||||
|
||||
void JumpToSelectedItem() |
||||
{ |
||||
SearchResult result = listBox.SelectedItem as SearchResult; |
||||
if (result != null) { |
||||
MainWindow.Instance.JumpToReference(result.Member); |
||||
} |
||||
} |
||||
} |
||||
|
||||
sealed class RunningSearch |
||||
{ |
||||
readonly Dispatcher dispatcher; |
||||
readonly CancellationTokenSource cts = new CancellationTokenSource(); |
||||
readonly LoadedAssembly[] assemblies; |
||||
readonly string searchTerm; |
||||
readonly Language language; |
||||
public readonly ObservableCollection<SearchResult> Results = new ObservableCollection<SearchResult>(); |
||||
int resultCount; |
||||
|
||||
public RunningSearch(LoadedAssembly[] assemblies, string searchTerm, Language language) |
||||
{ |
||||
this.dispatcher = Dispatcher.CurrentDispatcher; |
||||
this.assemblies = assemblies; |
||||
this.searchTerm = searchTerm; |
||||
this.language = language; |
||||
} |
||||
|
||||
public void Cancel() |
||||
{ |
||||
cts.Cancel(); |
||||
} |
||||
|
||||
public void Run() |
||||
{ |
||||
try { |
||||
foreach (var loadedAssembly in assemblies) { |
||||
AssemblyDefinition asm = loadedAssembly.AssemblyDefinition; |
||||
if (asm == null) |
||||
continue; |
||||
CancellationToken cancellationToken = cts.Token; |
||||
foreach (TypeDefinition type in asm.MainModule.Types) { |
||||
cancellationToken.ThrowIfCancellationRequested(); |
||||
PerformSearch(type); |
||||
} |
||||
} |
||||
} catch (OperationCanceledException) { |
||||
// ignore cancellation
|
||||
} |
||||
} |
||||
|
||||
void AddResult(SearchResult result) |
||||
{ |
||||
if (++resultCount == 1000) { |
||||
result = new SearchResult { Name = "Search aborted, more than 1000 results found." }; |
||||
cts.Cancel(); |
||||
} |
||||
dispatcher.BeginInvoke( |
||||
DispatcherPriority.Normal, |
||||
new Action(delegate { this.Results.Add(result); })); |
||||
cts.Token.ThrowIfCancellationRequested(); |
||||
} |
||||
|
||||
bool IsMatch(string text) |
||||
{ |
||||
if (text.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0) |
||||
return true; |
||||
else |
||||
return false; |
||||
} |
||||
|
||||
void PerformSearch(TypeDefinition type) |
||||
{ |
||||
if (IsMatch(type.Name)) { |
||||
AddResult(new SearchResult { |
||||
Member = type, |
||||
Image = TypeTreeNode.GetIcon(type), |
||||
Name = language.TypeToString(type, includeNamespace: false), |
||||
LocationImage = type.DeclaringType != null ? TypeTreeNode.GetIcon(type.DeclaringType) : Images.Namespace, |
||||
Location = type.DeclaringType != null ? language.TypeToString(type.DeclaringType, includeNamespace: true) : type.Namespace |
||||
}); |
||||
} |
||||
|
||||
foreach (TypeDefinition nestedType in type.NestedTypes) { |
||||
PerformSearch(nestedType); |
||||
} |
||||
|
||||
foreach (FieldDefinition field in type.Fields) { |
||||
if (IsMatch(field.Name)) { |
||||
AddResult(new SearchResult { |
||||
Member = field, |
||||
Image = FieldTreeNode.GetIcon(field), |
||||
Name = field.Name, |
||||
LocationImage = TypeTreeNode.GetIcon(type), |
||||
Location = language.TypeToString(type, includeNamespace: true) |
||||
}); |
||||
} |
||||
} |
||||
foreach (PropertyDefinition property in type.Properties) { |
||||
if (IsMatch(property.Name)) { |
||||
AddResult(new SearchResult { |
||||
Member = property, |
||||
Image = PropertyTreeNode.GetIcon(property), |
||||
Name = property.Name, |
||||
LocationImage = TypeTreeNode.GetIcon(type), |
||||
Location = language.TypeToString(type, includeNamespace: true) |
||||
}); |
||||
} |
||||
} |
||||
foreach (EventDefinition ev in type.Events) { |
||||
if (IsMatch(ev.Name)) { |
||||
AddResult(new SearchResult { |
||||
Member = ev, |
||||
Image = EventTreeNode.GetIcon(ev), |
||||
Name = ev.Name, |
||||
LocationImage = TypeTreeNode.GetIcon(type), |
||||
Location = language.TypeToString(type, includeNamespace: true) |
||||
}); |
||||
} |
||||
} |
||||
foreach (MethodDefinition method in type.Methods) { |
||||
if (IsMatch(method.Name)) { |
||||
AddResult(new SearchResult { |
||||
Member = method, |
||||
Image = MethodTreeNode.GetIcon(method), |
||||
Name = method.Name, |
||||
LocationImage = TypeTreeNode.GetIcon(type), |
||||
Location = language.TypeToString(type, includeNamespace: true) |
||||
}); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
class SearchResult : INotifyPropertyChanged |
||||
{ |
||||
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { |
||||
add { } |
||||
remove { } |
||||
} |
||||
|
||||
public MemberReference Member { get; set; } |
||||
|
||||
public string Location { get; set; } |
||||
public string Name { get; set; } |
||||
public ImageSource Image { get; set; } |
||||
public ImageSource LocationImage { get; set; } |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return Name; |
||||
} |
||||
} |
||||
|
||||
[ExportMainMenuCommand(Menu = "_View", Header = "_Search", MenuIcon="Images/Find.png", MenuCategory = "ShowPane", MenuOrder = 100)] |
||||
sealed class ShowSearchCommand : SimpleCommand |
||||
{ |
||||
public override void Execute(object parameter) |
||||
{ |
||||
SearchPane.Instance.Show(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
<UserControl x:Class="ICSharpCode.ILSpy.SearchPane" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls" |
||||
x:Name="self"> |
||||
<DockPanel> |
||||
<controls:SearchBox DockPanel.Dock="Top" WatermarkText="Search" WatermarkColor="Gray" ToolTip="Search" |
||||
Text="{Binding SearchTerm, ElementName=self}" x:Name="searchBox" /> |
||||
<ListBox Name="listBox" HorizontalContentAlignment="Stretch" SelectionMode="Single" MouseDoubleClick="ListBox_MouseDoubleClick" KeyDown="ListBox_KeyDown"> |
||||
<ListBox.ItemTemplate> |
||||
<DataTemplate> |
||||
<Grid> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition Width="20"/> |
||||
<ColumnDefinition Width="Auto"/> |
||||
<ColumnDefinition Width="*"/> |
||||
</Grid.ColumnDefinitions> |
||||
<Image Width="16" Height="16" Source="{Binding Image}" HorizontalAlignment="Left" /> |
||||
<TextBlock Text="{Binding Name}" Grid.Column="1" /> |
||||
<StackPanel Orientation="Horizontal" Grid.Column="2" HorizontalAlignment="Right"> |
||||
<Image Width="16" Height="16" Source="{Binding LocationImage}" Margin="4,0,4,0" /> |
||||
<TextBlock Text="{Binding Location}" TextTrimming="CharacterEllipsis" /> |
||||
</StackPanel> |
||||
</Grid> |
||||
</DataTemplate> |
||||
</ListBox.ItemTemplate> |
||||
</ListBox> |
||||
</DockPanel> |
||||
</UserControl> |
@ -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,107 @@
@@ -0,0 +1,107 @@
|
||||
// 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) |
||||
{ |
||||
if (!HasExtensionAttribute(type)) |
||||
yield break; |
||||
foreach (MethodDefinition method in type.Methods) { |
||||
if (method.IsStatic && HasExtensionAttribute(method)) { |
||||
if (method.HasParameters && method.Parameters[0].ParameterType.Resolve() == analyzedType) { |
||||
yield return new AnalyzedMethodTreeNode(method); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
bool HasExtensionAttribute(ICustomAttributeProvider p) |
||||
{ |
||||
if (p.HasCustomAttributes) { |
||||
foreach (CustomAttribute ca in p.CustomAttributes) { |
||||
TypeReference t = ca.AttributeType; |
||||
if (t.Name == "ExtensionAttribute" && t.Namespace == "System.Runtime.CompilerServices") |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
|
||||
public static bool CanShow(TypeDefinition type) |
||||
{ |
||||
// show on all types except static classes
|
||||
return !(type.IsAbstract && type.IsSealed); |
||||
} |
||||
} |
||||
} |
@ -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