diff options
author | Mike Krüger <mkrueger@novell.com> | 2011-06-17 12:44:39 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@novell.com> | 2011-06-17 17:04:22 +0400 |
commit | 019b96d27d5d80b9e498e51f8cfc70608c2f18a4 (patch) | |
tree | 63a68d0c4fff98f50b68ec29457e0094a28ca027 /main/src/addins/MonoDevelop.AssemblyBrowser | |
parent | 5dad48f1c001009e53bae6cab5733ef6a9c568c7 (diff) |
Did type system conversion (with ceil loader table).
Diffstat (limited to 'main/src/addins/MonoDevelop.AssemblyBrowser')
11 files changed, 183 insertions, 186 deletions
diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserTypeNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserTypeNodeBuilder.cs index 81aa94b8c4..288fc62f37 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserTypeNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserTypeNodeBuilder.cs @@ -44,12 +44,18 @@ namespace MonoDevelop.AssemblyBrowser } } + internal CecilLoader CecilLoader { + get { + return Widget.CecilLoader; + } + } + public AssemblyBrowserTypeNodeBuilder (AssemblyBrowserWidget assemblyBrowserWidget) { this.Widget = assemblyBrowserWidget; } - protected IProjectContent GetContent (ITreeBuilder treeBuilder) + protected IProjectContent GetContent (ITreeNavigator treeBuilder) { return ((Tuple<AssemblyDefinition, IProjectContent>)treeBuilder.GetParentDataItem (typeof(Tuple<AssemblyDefinition, IProjectContent>), true)).Item2; } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserWidget.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserWidget.cs index a8ee0a955c..43be2da815 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserWidget.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyBrowserWidget.cs @@ -489,37 +489,34 @@ namespace MonoDevelop.AssemblyBrowser { BackgroundWorker worker = sender as BackgroundWorker; try { - string pattern = e.Argument.ToString ().ToUpper (); int types = 0, curType = 0; foreach (var unit in this.definitions) { - foreach (var module in unit.Value.Modules) - types += module.Types.Count; + types += unit.Value.GetClasses ().Count (); } - var members = new List<IMemberDefinition> (); + var members = new List<IMember> (); switch (searchMode) { case SearchMode.Member: foreach (var unit in this.definitions) { - foreach (var module in unit.Value.Modules) - foreach (var type in module.Types) { + foreach (var type in unit.Value.GetClasses ()) { + if (worker.CancellationPending) + return; + curType++; + foreach (var member in type.GetMembers (unit.Value)) { if (worker.CancellationPending) return; - curType++; - foreach (var member in type.Methods.Cast<IMemberDefinition> ().Concat (type.Properties).Concat (type.Fields).Concat (type.Events)) { - if (worker.CancellationPending) - return; - if (member.Name.ToUpper ().Contains (pattern)) { - members.Add (member); - } + if (member.Name.ToUpper ().Contains (pattern)) { + members.Add (member); } } + } } Gtk.Application.Invoke (delegate { IdeApp.Workbench.StatusBar.SetProgressFraction ((double)curType / types); foreach (var member in members) { if (worker.CancellationPending) return; - memberListStore.AppendValues ("", //ImageService.GetPixbuf (member.StockIcon, Gtk.IconSize.Menu), + memberListStore.AppendValues (ImageService.GetPixbuf (member.GetStockIcon (), Gtk.IconSize.Menu), member.Name, member.DeclaringType.FullName, "", //((DomCecilCompilationUnit)member.DeclaringType.CompilationUnit).AssemblyDefinition.Name.FullName, @@ -532,20 +529,18 @@ namespace MonoDevelop.AssemblyBrowser IdeApp.Workbench.StatusBar.BeginProgress (GettextCatalog.GetString ("Searching string in disassembled code...")); }); foreach (var unit in this.definitions) { - foreach (var module in unit.Value.Modules) - foreach (var type in module.Types) { + foreach (var type in unit.Value.GetClasses ()) { + if (worker.CancellationPending) + return; + curType++; + foreach (var method in type.Methods) { if (worker.CancellationPending) return; - curType++; - foreach (var method in type.Methods) { - if (worker.CancellationPending) - return; // if (DomMethodNodeBuilder.Disassemble (rd => rd.DisassembleMethod (method)).ToUpper ().Contains (pattern)) { // members.Add (method); // } - } - } + } } Gtk.Application.Invoke (delegate { IdeApp.Workbench.StatusBar.SetProgressFraction ((double)curType / types); @@ -562,19 +557,17 @@ namespace MonoDevelop.AssemblyBrowser break; case SearchMode.Decompiler: foreach (var unit in this.definitions) { - foreach (var module in unit.Value.Modules) - foreach (var type in module.Types) { + foreach (var type in unit.Value.GetClasses ()) { + if (worker.CancellationPending) + return; + curType++; + foreach (var method in type.Methods) { if (worker.CancellationPending) return; - curType++; - foreach (var method in type.Methods) { - if (worker.CancellationPending) - return; /* if (DomMethodNodeBuilder.Decompile (domMethod, false).ToUpper ().Contains (pattern)) { - members.Add (method); - }*/ - } + members.Add (method);*/ } + } } Gtk.Application.Invoke (delegate { IdeApp.Workbench.StatusBar.SetProgressFraction ((double)curType / types); @@ -590,20 +583,20 @@ namespace MonoDevelop.AssemblyBrowser }); break; case SearchMode.Type: + var typeList = new List<IType> (); foreach (var unit in this.definitions) { - foreach (var module in unit.Value.Modules) - foreach (var type in module.Types) { + foreach (var type in unit.Value.GetClasses ()) { if (worker.CancellationPending) return; if (type.FullName.ToUpper ().IndexOf (pattern) >= 0) - members.Add (type); + typeList.Add (type); } } Gtk.Application.Invoke (delegate { - foreach (var type in members) { + foreach (var type in typeList) { if (worker.CancellationPending) return; - typeListStore.AppendValues ("", //ImageService.GetPixbuf (type.StockIcon, Gtk.IconSize.Menu), + typeListStore.AppendValues (ImageService.GetPixbuf (type.GetStockIcon (), Gtk.IconSize.Menu), type.Name, type.FullName.Substring (0, type.FullName.Length - type.Name.Length), "", // ((DomCecilCompilationUnit)type.CompilationUnit).AssemblyDefinition.Name.FullName, @@ -957,7 +950,7 @@ namespace MonoDevelop.AssemblyBrowser ITreeNavigator nav = SearchMember (url); if (nav == null) { foreach (var definition in definitions.ToArray ()) { - foreach (var assemblyNameReference in definition.Value.MainModule.AssemblyReferences) { + foreach (var assemblyNameReference in definition.Value.Annotation<AssemblyDefinition> ().MainModule.AssemblyReferences) { string assemblyFile = Runtime.SystemAssemblyService.DefaultAssemblyContext.GetAssemblyLocation (assemblyNameReference.FullName, null); if (assemblyFile != null && System.IO.File.Exists (assemblyFile)) AddReference (assemblyFile); @@ -978,7 +971,7 @@ namespace MonoDevelop.AssemblyBrowser AssemblyDefinition cu = null; foreach (var unit in definitions) { if (unit.Key == fileName) - cu = unit.Value; + cu = unit.Value.Annotation<AssemblyDefinition> (); } if (cu == null) return; @@ -1072,19 +1065,27 @@ namespace MonoDevelop.AssemblyBrowser } } - Dictionary<string, AssemblyDefinition> definitions = new Dictionary<string, AssemblyDefinition> (); - public AssemblyDefinition AddReference (string fileName) + CecilLoader loader = new CecilLoader (true); + internal CecilLoader CecilLoader { + get { + return loader; + } + } + + Dictionary<string, IProjectContent> definitions = new Dictionary<string, IProjectContent> (); + public IProjectContent AddReference (string fileName) { - AssemblyDefinition result; + IProjectContent result; if (definitions.TryGetValue (fileName, out result)) return result; - definitions [fileName] = result = ReadAssembly (fileName); - + var assembly = ReadAssembly (fileName); + definitions [fileName] = result = loader.LoadAssembly (assembly); + result.AddAnnotation (assembly); ITreeBuilder builder; if (definitions.Count == 1) { - builder = TreeView.LoadTree (Tuple.Create (result, new CecilLoader ().LoadAssembly (result))); + builder = TreeView.LoadTree (Tuple.Create (assembly, result)); } else { - builder = TreeView.AddChild (Tuple.Create (result, new CecilLoader ().LoadAssembly (result))); + builder = TreeView.AddChild (Tuple.Create (assembly, result)); } builder.MoveToFirstChild (); builder.Expanded = true; diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/BaseTypeFolder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/BaseTypeFolder.cs index c23983253b..e3b23ed97b 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/BaseTypeFolder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/BaseTypeFolder.cs @@ -34,12 +34,12 @@ namespace MonoDevelop.AssemblyBrowser { public class BaseTypeFolder : IDisposable { - public TypeDefinition Type { + public ITypeDefinition Type { get; private set; } - public BaseTypeFolder (TypeDefinition type) + public BaseTypeFolder (ITypeDefinition type) { this.Type = type; } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/BaseTypeFolderNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/BaseTypeFolderNodeBuilder.cs index eba8c76c74..d738b08413 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/BaseTypeFolderNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/BaseTypeFolderNodeBuilder.cs @@ -34,6 +34,7 @@ using Mono.Cecil; using MonoDevelop.Ide.Gui; using MonoDevelop.Ide.Gui.Pads; using MonoDevelop.Ide.Gui.Components; +using System.Linq; namespace MonoDevelop.AssemblyBrowser { @@ -59,15 +60,13 @@ namespace MonoDevelop.AssemblyBrowser closedIcon = Context.GetIcon (Stock.ClosedFolder); } - public override void BuildChildNodes (ITreeBuilder ctx, object dataObject) + public override void BuildChildNodes (ITreeBuilder builder, object dataObject) { var baseTypeFolder = (BaseTypeFolder)dataObject; - if (baseTypeFolder.Type != null && baseTypeFolder.Type.BaseType != null) - ctx.AddChild (baseTypeFolder.Type.BaseType); - // Todo: show implemented interfaces. - /*foreach (IReturnType type in baseTypeFolder.Type.ImplementedInterfaces) { - ctx.AddChild (type); - }*/ + var ctx = GetContent (builder); + foreach (var type in baseTypeFolder.Type.BaseTypes) { + builder.AddChild (type.Resolve (ctx)); + } } public override bool HasChildNodes (ITreeBuilder builder, object dataObject) { diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomEventNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomEventNodeBuilder.cs index fc0abf0bb8..a4c52dc762 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomEventNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomEventNodeBuilder.cs @@ -38,13 +38,14 @@ using Mono.TextEditor; using System.Collections.Generic; using Mono.Cecil; using MonoDevelop.TypeSystem; +using ICSharpCode.NRefactory.TypeSystem; namespace MonoDevelop.AssemblyBrowser { class DomEventNodeBuilder : AssemblyBrowserTypeNodeBuilder, IAssemblyBrowserNodeBuilder { public override Type NodeDataType { - get { return typeof(EventDefinition); } + get { return typeof(IEvent); } } public DomEventNodeBuilder (AssemblyBrowserWidget widget) : base (widget) @@ -53,36 +54,35 @@ namespace MonoDevelop.AssemblyBrowser public override string GetNodeName (ITreeNavigator thisNode, object dataObject) { - var evt = (EventDefinition)dataObject; + var evt = (IEvent)dataObject; return evt.FullName; } public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { - var evt = (EventDefinition)dataObject; -// label = Ambience.GetString (evt, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup); - label = evt.Name; -// if (evt.IsPrivate || evt.IsInternal) -// label = DomMethodNodeBuilder.FormatPrivate (label); + var evt = (IEvent)dataObject; + label = Ambience.GetString (evt, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.CompletionListFomat); + if (evt.IsPrivate || evt.IsInternal) + label = DomMethodNodeBuilder.FormatPrivate (label); icon = ImageService.GetPixbuf (evt.GetStockIcon (), Gtk.IconSize.Menu); } public override int CompareObjects (ITreeNavigator thisNode, ITreeNavigator otherNode) { - if (otherNode.DataItem is EventDefinition) - return ((EventDefinition)thisNode.DataItem).Name.CompareTo (((EventDefinition)otherNode.DataItem).Name); + if (otherNode.DataItem is IEvent) + return ((IEvent)thisNode.DataItem).Name.CompareTo (((IEvent)otherNode.DataItem).Name); return 1; } public override void BuildChildNodes (ITreeBuilder ctx, object dataObject) { - var evt = (EventDefinition)dataObject; - if (evt.AddMethod != null) - ctx.AddChild (evt.AddMethod); - if (evt.RemoveMethod != null) - ctx.AddChild (evt.RemoveMethod); - if (evt.InvokeMethod != null) - ctx.AddChild (evt.InvokeMethod); + var evt = (IEvent)dataObject; + if (evt.CanAdd) + ctx.AddChild (evt.AddAccessor); + if (evt.CanRemove) + ctx.AddChild (evt.RemoveAccessor); + if (evt.CanInvoke) + ctx.AddChild (evt.InvokeAccessor); } public override bool HasChildNodes (ITreeBuilder builder, object dataObject) @@ -113,8 +113,7 @@ namespace MonoDevelop.AssemblyBrowser List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile (TextEditorData data, ITreeNavigator navigator) { var evt = (EventDefinition)navigator.DataItem; - var parent = (TypeDefinition)navigator.GetParentDataItem (typeof(TypeDefinition), false); - return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), parent, b => b.AddEvent (evt)); + return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), evt.DeclaringType, b => b.AddEvent (evt)); } string IAssemblyBrowserNodeBuilder.GetDocumentationMarkup (ITreeNavigator navigator) diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomFieldNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomFieldNodeBuilder.cs index 9befb40bdc..ece6ac2b00 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomFieldNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomFieldNodeBuilder.cs @@ -38,13 +38,14 @@ using Mono.TextEditor; using System.Collections.Generic; using Mono.Cecil; using MonoDevelop.TypeSystem; +using ICSharpCode.NRefactory.TypeSystem; namespace MonoDevelop.AssemblyBrowser { class DomFieldNodeBuilder : AssemblyBrowserTypeNodeBuilder, IAssemblyBrowserNodeBuilder { public override Type NodeDataType { - get { return typeof(FieldDefinition); } + get { return typeof(IField); } } public DomFieldNodeBuilder (AssemblyBrowserWidget widget) : base (widget) @@ -54,40 +55,39 @@ namespace MonoDevelop.AssemblyBrowser public override string GetNodeName (ITreeNavigator thisNode, object dataObject) { - var field = (FieldDefinition)dataObject; + var field = (IField)dataObject; return field.FullName; } public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { - var field = (FieldDefinition)dataObject; - label = field.Name; -// label = Ambience.GetString (field, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup); -// if (field.IsPrivate || field.IsInternal) -// label = DomMethodNodeBuilder.FormatPrivate (label); -// icon = ImageService.GetPixbuf (field.StockIcon, Gtk.IconSize.Menu); + var field = (IField)dataObject; + label = Ambience.GetString (field, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.CompletionListFomat); + if (field.IsPrivate || field.IsInternal) + label = DomMethodNodeBuilder.FormatPrivate (label); + icon = ImageService.GetPixbuf (field.GetStockIcon (), Gtk.IconSize.Menu); } public override int CompareObjects (ITreeNavigator thisNode, ITreeNavigator otherNode) { - if (otherNode.DataItem is MethodDefinition) + if (otherNode.DataItem is IMethod) return 1; - if (otherNode.DataItem is PropertyDefinition) + if (otherNode.DataItem is IProperty) return 1; if (otherNode.DataItem is BaseTypeFolder) return 1; - if (otherNode.DataItem is FieldDefinition) - return ((FieldDefinition)thisNode.DataItem).Name.CompareTo (((FieldDefinition)otherNode.DataItem).Name); + if (otherNode.DataItem is IField) + return ((IField)thisNode.DataItem).Name.CompareTo (((IField)otherNode.DataItem).Name); return -1; } #region IAssemblyBrowserNodeBuilder string IAssemblyBrowserNodeBuilder.GetDescription (ITreeNavigator navigator) { - var field = (FieldDefinition)navigator.DataItem; + var field = (IField)navigator.DataItem; StringBuilder result = new StringBuilder (); result.Append ("<span font_family=\"monospace\">"); -// result.Append (Ambience.GetString (field, OutputFlags.AssemblyBrowserDescription)); + result.Append (Ambience.GetString (field, OutputFlags.AssemblyBrowserDescription)); result.Append ("</span>"); result.AppendLine (); DomMethodNodeBuilder.PrintDeclaringType (result, navigator); @@ -97,33 +97,32 @@ namespace MonoDevelop.AssemblyBrowser List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble (TextEditorData data, ITreeNavigator navigator) { - var field = (FieldDefinition)navigator.DataItem; + var field = CecilLoader.GetCecilObject ((IField)navigator.DataItem); return DomMethodNodeBuilder.Disassemble (data, rd => rd.DisassembleField (field)); } List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile (TextEditorData data, ITreeNavigator navigator) { - var field = (FieldDefinition)navigator.DataItem; - var parent = (TypeDefinition)navigator.GetParentDataItem (typeof(TypeDefinition), false); - return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), parent, b => b.AddField (field)); + var field = CecilLoader.GetCecilObject ((IField)navigator.DataItem); + return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), field.DeclaringType, b => b.AddField (field)); } string IAssemblyBrowserNodeBuilder.GetDocumentationMarkup (ITreeNavigator navigator) { - var field = (FieldDefinition)navigator.DataItem; + var field = (IField)navigator.DataItem; StringBuilder result = new StringBuilder (); result.Append ("<big>"); -// result.Append (Ambience.GetString (field, OutputFlags.AssemblyBrowserDescription)); + result.Append (Ambience.GetString (field, OutputFlags.AssemblyBrowserDescription)); result.Append ("</big>"); result.AppendLine (); -// var.DocumentationFormatOptions options = new AmbienceService.DocumentationFormatOptions (); -// options.MaxLineLength = -1; -// options.BigHeadings = true; -// options.Ambience = Ambience; -// result.AppendLine (); + var options = new AmbienceService.DocumentationFormatOptions (); + options.MaxLineLength = -1; + options.BigHeadings = true; + options.Ambience = Ambience; + result.AppendLine (); -// result.Append (AmbienceService.GetDocumentationMarkup (AmbienceService.GetDocumentation (field), options)); + result.Append (AmbienceService.GetDocumentationMarkup (AmbienceService.GetDocumentation (field), options)); return result.ToString (); } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomMethodNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomMethodNodeBuilder.cs index 8111fe7b7d..d997576223 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomMethodNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomMethodNodeBuilder.cs @@ -49,7 +49,7 @@ namespace MonoDevelop.AssemblyBrowser class DomMethodNodeBuilder : AssemblyBrowserTypeNodeBuilder, IAssemblyBrowserNodeBuilder { public override Type NodeDataType { - get { return typeof(MethodDefinition); } + get { return typeof(IMethod); } } public DomMethodNodeBuilder (AssemblyBrowserWidget widget) : base (widget) @@ -59,7 +59,7 @@ namespace MonoDevelop.AssemblyBrowser public override string GetNodeName (ITreeNavigator thisNode, object dataObject) { - var method = (MethodDefinition)dataObject; + var method = (IMethod)dataObject; return method.FullName; } @@ -69,22 +69,21 @@ namespace MonoDevelop.AssemblyBrowser } public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { - var method = (MethodDefinition)dataObject; + var method = (IMethod)dataObject; var ctx = GetContent (treeBuilder); - label = method.Name; -// label = Ambience.GetString (ctx, method, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup); -// if (method.IsPrivate || method.IsInternal) -// label = DomMethodNodeBuilder.FormatPrivate (label); + label = Ambience.GetString (ctx, method, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.CompletionListFomat); + if (method.IsPrivate || method.IsInternal) + label = DomMethodNodeBuilder.FormatPrivate (label); icon = ImageService.GetPixbuf (method.GetStockIcon (), Gtk.IconSize.Menu); } public override int CompareObjects (ITreeNavigator thisNode, ITreeNavigator otherNode) { - if (otherNode.DataItem is MethodDefinition) + if (!(otherNode.DataItem is IMethod)) return 1; if (otherNode.DataItem is IMethod) - return ((MethodDefinition)thisNode.DataItem).Name.CompareTo (((MethodDefinition)otherNode.DataItem).Name); + return ((IMethod)thisNode.DataItem).Name.CompareTo (((IMethod)otherNode.DataItem).Name); return -1; } @@ -92,7 +91,7 @@ namespace MonoDevelop.AssemblyBrowser #region IAssemblyBrowserNodeBuilder internal static void PrintDeclaringType (StringBuilder result, ITreeNavigator navigator) { - IType type = (IType)navigator.GetParentDataItem (typeof (IType), false); + var type = (IType)navigator.GetParentDataItem (typeof (IType), false); if (type == null) return; @@ -102,10 +101,10 @@ namespace MonoDevelop.AssemblyBrowser string IAssemblyBrowserNodeBuilder.GetDescription (ITreeNavigator navigator) { - var method = (MethodDefinition)navigator.DataItem; + var method = (IMethod)navigator.DataItem; StringBuilder result = new StringBuilder (); result.Append ("<span font_family=\"monospace\">"); -// result.Append (Ambience.GetString (method, OutputFlags.AssemblyBrowserDescription)); + result.Append (Ambience.GetString (method, OutputFlags.AssemblyBrowserDescription)); result.Append ("</span>"); result.AppendLine (); PrintDeclaringType (result, navigator); @@ -130,7 +129,7 @@ namespace MonoDevelop.AssemblyBrowser return (ModuleDefinition)nav.DataItem; } - + public static List<ReferenceSegment> Decompile (TextEditorData data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData) { try { @@ -166,7 +165,6 @@ namespace MonoDevelop.AssemblyBrowser return null; } - internal static string GetAttributes (Ambience ambience, IEnumerable<IAttribute> attributes) { StringBuilder result = new StringBuilder (); @@ -182,9 +180,8 @@ namespace MonoDevelop.AssemblyBrowser public List<ReferenceSegment> Decompile (TextEditorData data, ITreeNavigator navigator) { - var method = (MethodDefinition)navigator.DataItem; - var parent = (TypeDefinition)navigator.GetParentDataItem (typeof(TypeDefinition), false); - return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), parent, b => b.AddMethod (method)); + var method = CecilLoader.GetCecilObject ((IMethod)navigator.DataItem); + return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), method.DeclaringType, b => b.AddMethod (method)); } static void AppendLink (StringBuilder sb, string link, string text) @@ -208,7 +205,7 @@ namespace MonoDevelop.AssemblyBrowser List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble (TextEditorData data, ITreeNavigator navigator) { - var method = (MethodDefinition)navigator.DataItem; + var method = CecilLoader.GetCecilObject ((IMethod)navigator.DataItem); if (method == null) return null; return Disassemble (data, rd => rd.DisassembleMethod (method)); @@ -216,10 +213,10 @@ namespace MonoDevelop.AssemblyBrowser string IAssemblyBrowserNodeBuilder.GetDocumentationMarkup (ITreeNavigator navigator) { - var method = (MethodDefinition)navigator.DataItem; + var method = (IMethod)navigator.DataItem; StringBuilder result = new StringBuilder (); result.Append ("<big>"); -// result.Append (Ambience.GetString (method, OutputFlags.AssemblyBrowserDescription | OutputFlags.IncludeConstraints)); + result.Append (Ambience.GetString (method, OutputFlags.AssemblyBrowserDescription | OutputFlags.IncludeConstraints)); result.Append ("</big>"); result.AppendLine (); diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomPropertyNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomPropertyNodeBuilder.cs index d53cf4df73..bf1dab94bc 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomPropertyNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomPropertyNodeBuilder.cs @@ -38,13 +38,15 @@ using System.Threading; using Mono.TextEditor; using System.Collections.Generic; using Mono.Cecil; +using ICSharpCode.NRefactory.TypeSystem; +using MonoDevelop.TypeSystem; namespace MonoDevelop.AssemblyBrowser { class DomPropertyNodeBuilder : AssemblyBrowserTypeNodeBuilder, IAssemblyBrowserNodeBuilder { public override Type NodeDataType { - get { return typeof(PropertyDefinition); } + get { return typeof(IProperty); } } public DomPropertyNodeBuilder (AssemblyBrowserWidget widget) : base (widget) @@ -54,19 +56,19 @@ namespace MonoDevelop.AssemblyBrowser public override string GetNodeName (ITreeNavigator thisNode, object dataObject) { - var property = (PropertyDefinition)dataObject; + var property = (IProperty)dataObject; return property.Name; } public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { - var property = (PropertyDefinition)dataObject; - label = property.Name; -// label = Ambience.GetString (property, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup); -// if (property.IsPrivate || property.IsInternal) -// label = DomMethodNodeBuilder.FormatPrivate (label); -// icon = ImageService.GetPixbuf (property.StockIcon, Gtk.IconSize.Menu); + var property = (IProperty)dataObject; + label = Ambience.GetString (property, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.CompletionListFomat); + if (property.IsPrivate || property.IsInternal) + label = DomMethodNodeBuilder.FormatPrivate (label); + icon = ImageService.GetPixbuf (property.GetStockIcon (), Gtk.IconSize.Menu); } + public override int CompareObjects (ITreeNavigator thisNode, ITreeNavigator otherNode) { if (otherNode.DataItem is MethodDefinition) @@ -80,27 +82,27 @@ namespace MonoDevelop.AssemblyBrowser public override void BuildChildNodes (ITreeBuilder ctx, object dataObject) { - var property = (PropertyDefinition)dataObject; - if (property.GetMethod != null) - ctx.AddChild (property.GetMethod); - if (property.SetMethod != null) - ctx.AddChild (property.SetMethod); + var property = (IProperty)dataObject; + if (property.CanGet) + ctx.AddChild (property.Getter); + if (property.CanSet != null) + ctx.AddChild (property.Setter); } public override bool HasChildNodes (ITreeBuilder builder, object dataObject) { - var property = (PropertyDefinition)dataObject; - return property.GetMethod != null || property.SetMethod != null; + var property = (IProperty)dataObject; + return property.CanGet != null || property.CanSet != null; } #region IAssemblyBrowserNodeBuilder string IAssemblyBrowserNodeBuilder.GetDescription (ITreeNavigator navigator) { - var property = (PropertyDefinition)navigator.DataItem; + var property = (IProperty)navigator.DataItem; StringBuilder result = new StringBuilder (); result.Append ("<span font_family=\"monospace\">"); -// result.Append (Ambience.GetString (property, OutputFlags.AssemblyBrowserDescription)); + result.Append (Ambience.GetString (property, OutputFlags.AssemblyBrowserDescription)); result.Append ("</span>"); result.AppendLine (); DomMethodNodeBuilder.PrintDeclaringType (result, navigator); @@ -110,13 +112,12 @@ namespace MonoDevelop.AssemblyBrowser List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Disassemble (TextEditorData data, ITreeNavigator navigator) { - var property = (PropertyDefinition)navigator.DataItem; + var property = CecilLoader.GetCecilObject ((IProperty)navigator.DataItem); return DomMethodNodeBuilder.Disassemble (data, rd => rd.DisassembleProperty (property)); } static string GetBody (string text) { - int idx = text.IndexOf ('{') + 1; int idx2 = text.LastIndexOf ('}'); if (idx2 - idx <= 0) @@ -129,27 +130,26 @@ namespace MonoDevelop.AssemblyBrowser List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile (TextEditorData data, ITreeNavigator navigator) { - var property = (PropertyDefinition)navigator.DataItem; - var parent = (TypeDefinition)navigator.GetParentDataItem (typeof(TypeDefinition), false); - return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), parent, b => b.AddProperty (property)); + var property = CecilLoader.GetCecilObject ((IProperty)navigator.DataItem); + return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), property.DeclaringType, b => b.AddProperty (property)); } string IAssemblyBrowserNodeBuilder.GetDocumentationMarkup (ITreeNavigator navigator) { - var property = (PropertyDefinition)navigator.DataItem; + var property = (IProperty)navigator.DataItem; StringBuilder result = new StringBuilder (); result.Append ("<big>"); -// result.Append (Ambience.GetString (property, OutputFlags.AssemblyBrowserDescription)); + result.Append (Ambience.GetString (property, OutputFlags.AssemblyBrowserDescription)); result.Append ("</big>"); result.AppendLine (); -// AmbienceService.DocumentationFormatOptions options = new AmbienceService.DocumentationFormatOptions (); -// options.MaxLineLength = -1; -// options.BigHeadings = true; -// options.Ambience = Ambience; + AmbienceService.DocumentationFormatOptions options = new AmbienceService.DocumentationFormatOptions (); + options.MaxLineLength = -1; + options.BigHeadings = true; + options.Ambience = Ambience; result.AppendLine (); -// result.Append (AmbienceService.GetDocumentationMarkup (AmbienceService.GetDocumentation (property), options)); + result.Append (AmbienceService.GetDocumentationMarkup (AmbienceService.GetDocumentation (property), options)); return result.ToString (); } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomTypeNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomTypeNodeBuilder.cs index 04e4bbd68f..bf995fe484 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomTypeNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomTypeNodeBuilder.cs @@ -48,7 +48,7 @@ namespace MonoDevelop.AssemblyBrowser class DomTypeNodeBuilder : AssemblyBrowserTypeNodeBuilder, IAssemblyBrowserNodeBuilder { public override Type NodeDataType { - get { return typeof(TypeDefinition); } + get { return typeof(ITypeDefinition); } } public override string ContextMenuAddinPath { @@ -110,38 +110,31 @@ namespace MonoDevelop.AssemblyBrowser public override string GetNodeName (ITreeNavigator thisNode, object dataObject) { - var type = (TypeDefinition)dataObject; + var type = (ITypeDefinition)dataObject; return type.Name; } public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { - var type = (TypeDefinition)dataObject; -// label = Ambience.GetString (GetContent (treeBuilder), type, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup); - label = type.Name; -// if (type.IsPrivate || type.IsInternal) -// label = DomMethodNodeBuilder.FormatPrivate (label); + var type = (ITypeDefinition)dataObject; + label = Ambience.GetString (GetContent (treeBuilder), (IType)type, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup); + if (type.GetDefinition ().IsPrivate || type.GetDefinition ().IsPrivate) + label = DomMethodNodeBuilder.FormatPrivate (label); icon = ImageService.GetPixbuf (type.GetStockIcon (), Gtk.IconSize.Menu); } - public override void BuildChildNodes (ITreeBuilder ctx, object dataObject) + public override void BuildChildNodes (ITreeBuilder builder, object dataObject) { - var type = (TypeDefinition)dataObject; + var type = (ITypeDefinition)dataObject; var list = new System.Collections.ArrayList (); list.Add (new BaseTypeFolder (type)); - bool publicOnly = ctx.Options ["PublicApiOnly"]; - foreach (var t in type.NestedTypes.Where (m => !m.IsSpecialName && !(publicOnly && (m.IsPublic)))) + bool publicOnly = builder.Options ["PublicApiOnly"]; + foreach (var t in type.InnerClasses.Where (m => !m.GetDefinition ().IsSynthetic && !(publicOnly && m.GetDefinition ().IsPublic))) list.Add (t); - foreach (var m in type.Methods.Where (m => !m.IsSpecialName && !(publicOnly && !(m.IsPublic || m.IsFamily)))) + foreach (var m in type.Members.Where (m => !m.IsSynthetic && !(publicOnly && !(m.IsPublic || m.IsInternal)))) list.Add (m); - foreach (var p in type.Properties) - list.Add (p); - foreach (var f in type.Fields.Where (m => !m.IsSpecialName && !(publicOnly && !(m.IsPublic || m.IsFamily)))) - list.Add (f); - foreach (var e in type.Events) - list.Add (e); - ctx.AddChildren (list); + builder.AddChildren (list); } public override bool HasChildNodes (ITreeBuilder builder, object dataObject) @@ -164,7 +157,7 @@ namespace MonoDevelop.AssemblyBrowser public string GetDescription (ITreeNavigator navigator) { - var type = (TypeDefinition)navigator.DataItem; + var type = (IType)navigator.DataItem; StringBuilder result = new StringBuilder (); result.Append ("<span font_family=\"monospace\">"); // result.Append (Ambience.GetString (type, OutputFlags.AssemblyBrowserDescription)); @@ -178,22 +171,24 @@ namespace MonoDevelop.AssemblyBrowser public List<ReferenceSegment> Disassemble (TextEditorData data, ITreeNavigator navigator) { - var type = (TypeDefinition)navigator.DataItem; + var type = CecilLoader.GetCecilObject ((ITypeDefinition)navigator.DataItem); + Console.WriteLine ("disassembple:" + type); return DomMethodNodeBuilder.Disassemble (data, rd => rd.DisassembleType (type)); } public List<ReferenceSegment> Decompile (TextEditorData data, ITreeNavigator navigator) { - var type = (TypeDefinition)navigator.DataItem; + var type = CecilLoader.GetCecilObject ((ITypeDefinition)navigator.DataItem); + Console.WriteLine ("decompile:" + type +" --- :" + ((ITypeDefinition)navigator.DataItem).GetType ()); return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), type, b => b.AddType (type)); } string IAssemblyBrowserNodeBuilder.GetDocumentationMarkup (ITreeNavigator navigator) { - var type = (TypeDefinition)navigator.DataItem; - StringBuilder result = new StringBuilder (); + var type = (IType)navigator.DataItem; + var result = new StringBuilder (); result.Append ("<big>"); -// result.Append (Ambience.GetString (type, OutputFlags.AssemblyBrowserDescription)); + result.Append (Ambience.GetString (GetContent (navigator), type, OutputFlags.AssemblyBrowserDescription)); result.Append ("</big>"); result.AppendLine (); diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/ModuleDefinitionNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/ModuleDefinitionNodeBuilder.cs index 852338db4e..b88d16024a 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/ModuleDefinitionNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/ModuleDefinitionNodeBuilder.cs @@ -35,6 +35,7 @@ using MonoDevelop.Ide.Gui; using MonoDevelop.Ide.Gui.Components; using Mono.TextEditor; using Mono.Cecil; +using System.Linq; namespace MonoDevelop.AssemblyBrowser { @@ -62,23 +63,23 @@ namespace MonoDevelop.AssemblyBrowser closedIcon = Context.GetIcon (Stock.ClosedFolder); } - public override void BuildChildNodes (ITreeBuilder ctx, object dataObject) + public override void BuildChildNodes (ITreeBuilder builder, object dataObject) { var module = (ModuleDefinition)dataObject; Dictionary<string, Namespace> namespaces = new Dictionary<string, Namespace> (); - bool publicOnly = ctx.Options ["PublicApiOnly"]; - foreach (var type in module.Types) { - if (publicOnly && !type.IsPublic) - continue; - if (!namespaces.ContainsKey (type.Namespace)) - namespaces [type.Namespace] = new Namespace (type.Namespace); - namespaces [type.Namespace].Types.Add (type); + bool publicOnly = builder.Options ["PublicApiOnly"]; + var ctx = GetContent (builder); + foreach (var ns in ctx.GetNamespaces ()) { + var newSpace = new Namespace (ns); + newSpace.Types.AddRange (ctx.GetClasses (ns, StringComparer.Ordinal).Where (c => !publicOnly || c.IsPublic )); + if (newSpace.Types.Count > 0) + namespaces [ns] = newSpace; } - ctx.AddChild (new ReferenceFolder (module)); + builder.AddChild (new ReferenceFolder (module)); if (module.Resources.Count > 0) - ctx.AddChild (new ResourceFolder (module)); + builder.AddChild (new ResourceFolder (module)); foreach (Namespace ns in namespaces.Values) { - ctx.AddChild (ns); + builder.AddChild (ns); } } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/Namespace.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/Namespace.cs index 7402e22597..d51ea7d2ae 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/Namespace.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/Namespace.cs @@ -35,14 +35,14 @@ namespace MonoDevelop.AssemblyBrowser { public class Namespace : IDisposable { - List<TypeDefinition> types = new List<TypeDefinition> (); + List<ITypeDefinition> types = new List<ITypeDefinition> (); public string Name { get; private set; } - public List<TypeDefinition> Types { + public List<ITypeDefinition> Types { get { return types; } |