Browse Source

Show derived types in tree view.

pull/10/head
Daniel Grunwald 15 years ago
parent
commit
34cca90a00
  1. 6
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 5
      ILSpy/ILSpy.csproj
  3. 4
      ILSpy/TreeNodes/AssemblyTreeNode.cs
  4. 10
      ILSpy/TreeNodes/BaseTypesTreeNode.cs
  5. 118
      ILSpy/TreeNodes/DerivedTypesTreeNode.cs
  6. 2
      ILSpy/TreeNodes/TypeTreeNode.cs

6
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -46,6 +46,8 @@ namespace Decompiler
// disable whitespace in front of parentheses: // disable whitespace in front of parentheses:
formattingPolicy.BeforeMethodCallParentheses = false; formattingPolicy.BeforeMethodCallParentheses = false;
formattingPolicy.BeforeMethodDeclarationParentheses = false; formattingPolicy.BeforeMethodDeclarationParentheses = false;
formattingPolicy.BeforeConstructorDeclarationParentheses = false;
formattingPolicy.BeforeDelegateDeclarationParentheses = false;
astCompileUnit.AcceptVisitor(new OutputVisitor(outputFormatter, formattingPolicy), null); astCompileUnit.AcceptVisitor(new OutputVisitor(outputFormatter, formattingPolicy), null);
} }
@ -429,6 +431,10 @@ namespace Decompiler
{ {
ConstructorDeclaration astMethod = new ConstructorDeclaration(); ConstructorDeclaration astMethod = new ConstructorDeclaration();
astMethod.Modifiers = ConvertModifiers(methodDef); astMethod.Modifiers = ConvertModifiers(methodDef);
if (methodDef.IsStatic) {
// don't show visibility for static ctors
astMethod.Modifiers &= ~Modifiers.VisibilityMask;
}
astMethod.Parameters = MakeParameters(methodDef.Parameters); astMethod.Parameters = MakeParameters(methodDef.Parameters);
astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef); astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef);
return astMethod; return astMethod;

5
ILSpy/ILSpy.csproj

@ -128,6 +128,7 @@
<Compile Include="TreeNodes\AssemblyReferenceTreeNode.cs" /> <Compile Include="TreeNodes\AssemblyReferenceTreeNode.cs" />
<Compile Include="TreeNodes\AssemblyTreeNode.cs" /> <Compile Include="TreeNodes\AssemblyTreeNode.cs" />
<Compile Include="TreeNodes\BaseTypesTreeNode.cs" /> <Compile Include="TreeNodes\BaseTypesTreeNode.cs" />
<Compile Include="TreeNodes\DerivedTypesTreeNode.cs" />
<Compile Include="TreeNodes\EventTreeNode.cs" /> <Compile Include="TreeNodes\EventTreeNode.cs" />
<Compile Include="TreeNodes\FieldTreeNode.cs" /> <Compile Include="TreeNodes\FieldTreeNode.cs" />
<Compile Include="TreeNodes\ILSpyTreeNode.cs" /> <Compile Include="TreeNodes\ILSpyTreeNode.cs" />
@ -208,6 +209,10 @@
<Project>{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}</Project> <Project>{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}</Project>
<Name>ICSharpCode.AvalonEdit</Name> <Name>ICSharpCode.AvalonEdit</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
<ProjectReference Include="..\SharpTreeView\ICSharpCode.TreeView.csproj"> <ProjectReference Include="..\SharpTreeView\ICSharpCode.TreeView.csproj">
<Project>{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}</Project> <Project>{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}</Project>
<Name>ICSharpCode.TreeView</Name> <Name>ICSharpCode.TreeView</Name>

4
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -65,6 +65,10 @@ namespace ICSharpCode.ILSpy.TreeNodes
get { return fileName; } get { return fileName; }
} }
public AssemblyList AssemblyList {
get { return assemblyList; }
}
public AssemblyDefinition AssemblyDefinition { public AssemblyDefinition AssemblyDefinition {
get { get {
try { try {

10
ILSpy/TreeNodes/BaseTypesTreeNode.cs

@ -119,13 +119,19 @@ namespace ICSharpCode.ILSpy.TreeNodes
if (def != null) if (def != null)
this.LazyLoading = true; // re-load children this.LazyLoading = true; // re-load children
} }
e.Handled = ActivateItem(this, def);
}
internal static bool ActivateItem(SharpTreeNode node, TypeDefinition def)
{
if (def != null) { if (def != null) {
var assemblyListNode = this.Ancestors().OfType<AssemblyListTreeNode>().FirstOrDefault(); var assemblyListNode = node.Ancestors().OfType<AssemblyListTreeNode>().FirstOrDefault();
if (assemblyListNode != null) { if (assemblyListNode != null) {
assemblyListNode.Select(assemblyListNode.AssemblyList.FindTypeNode(def)); assemblyListNode.Select(assemblyListNode.AssemblyList.FindTypeNode(def));
e.Handled = true; return true;
} }
} }
return false;
} }
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)

118
ILSpy/TreeNodes/DerivedTypesTreeNode.cs

@ -0,0 +1,118 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.ObjectModel;
using System.Linq;
using ICSharpCode.Decompiler;
using ICSharpCode.NRefactory.Utils;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes
{
/// <summary>
/// Lists the super types of a class.
/// </summary>
sealed class DerivedTypesTreeNode : ILSpyTreeNode<DerivedTypesEntryNode>
{
readonly AssemblyList list;
readonly TypeDefinition type;
public DerivedTypesTreeNode(AssemblyList list, TypeDefinition type)
{
this.list = list;
this.type = type;
this.LazyLoading = true;
}
public override object Text {
get { return "Derived Types"; }
}
public override object Icon {
get { return Images.SubTypes; }
}
protected override void LoadChildren()
{
AddDerivedTypes(this.Children, type, list);
}
internal static void AddDerivedTypes(ObservableCollection<DerivedTypesEntryNode> children, TypeDefinition type, AssemblyList list)
{
foreach (var asmNode in list.Assemblies) {
AssemblyDefinition asm = asmNode.AssemblyDefinition;
if (asm == null)
continue;
foreach (TypeDefinition td in TreeTraversal.PreOrder(asm.MainModule.Types, t => t.NestedTypes)) {
if (type.IsInterface && td.HasInterfaces) {
foreach (TypeReference typeRef in td.Interfaces) {
if (IsSameType(typeRef, type))
children.Add(new DerivedTypesEntryNode(td, list));
}
} else if (!type.IsInterface && IsSameType(td.BaseType, type)) {
children.Add(new DerivedTypesEntryNode(td, list));
}
}
}
}
static bool IsSameType(TypeReference typeRef, TypeDefinition type)
{
return typeRef.FullName == type.FullName;
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
EnsureLazyChildren();
foreach (var child in this.Children) {
child.Decompile(language, output, options);
}
}
}
class DerivedTypesEntryNode : ILSpyTreeNode<DerivedTypesEntryNode>
{
TypeDefinition def;
AssemblyList list;
public DerivedTypesEntryNode(TypeDefinition def, AssemblyList list)
{
this.def = def;
this.list = list;
this.LazyLoading = true;
}
public override bool ShowExpander {
get {
return !def.IsSealed && base.ShowExpander;
}
}
public override object Text {
get { return def.FullName; }
}
public override object Icon {
get {
return TypeTreeNode.GetIcon(def);
}
}
protected override void LoadChildren()
{
DerivedTypesTreeNode.AddDerivedTypes(this.Children, def, list);
}
public override void ActivateItem(System.Windows.RoutedEventArgs e)
{
e.Handled = BaseTypesEntryNode.ActivateItem(this, def);
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, language.TypeToString(def));
}
}
}

2
ILSpy/TreeNodes/TypeTreeNode.cs

@ -90,6 +90,8 @@ namespace ICSharpCode.ILSpy.TreeNodes
{ {
if (type.BaseType != null || type.HasInterfaces) if (type.BaseType != null || type.HasInterfaces)
this.Children.Add(new BaseTypesTreeNode(type)); this.Children.Add(new BaseTypesTreeNode(type));
if (!type.IsSealed)
this.Children.Add(new DerivedTypesTreeNode(parentAssemblyNode.AssemblyList, type));
foreach (TypeDefinition nestedType in type.NestedTypes) { foreach (TypeDefinition nestedType in type.NestedTypes) {
this.Children.Add(new TypeTreeNode(nestedType, parentAssemblyNode)); this.Children.Add(new TypeTreeNode(nestedType, parentAssemblyNode));
} }

Loading…
Cancel
Save