diff --git a/SharpDevelop.sln b/SharpDevelop.sln index a4a463f1de..5f16852dfa 100644 --- a/SharpDevelop.sln +++ b/SharpDevelop.sln @@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Build.Tasks", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TreeView", "src\Libraries\SharpTreeView\ICSharpCode.TreeView\ICSharpCode.TreeView.csproj", "{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Decompiler", "src\Libraries\ICSharpCode.Decompiler\ICSharpCode.Decompiler.csproj", "{984CC812-9470-4A13-AFF9-CC44068D666C}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AddIns", "AddIns", "{39327899-ED91-4F7F-988C-4FE4E17C014D}" ProjectSection(SolutionItems) = postProject EndProjectSection @@ -109,6 +111,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor", "src\AddIns\Dis EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IconEditor", "src\AddIns\DisplayBindings\IconEditor\IconEditor.csproj", "{DFB936AD-90EE-4B4F-941E-4F4A636F0D92}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpyAddIn", "src\AddIns\DisplayBindings\ILSpyAddIn\ILSpyAddIn.csproj", "{8AA421C8-D7AF-4957-9F43-5135328ACB24}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Analysis", "Analysis", "{7019F43E-DFD7-4D1C-8C96-E75D55646DE7}" ProjectSection(SolutionItems) = postProject EndProjectSection @@ -445,6 +449,22 @@ Global {DFB936AD-90EE-4B4F-941E-4F4A636F0D92}.Release|Any CPU.ActiveCfg = Release|Any CPU {DFB936AD-90EE-4B4F-941E-4F4A636F0D92}.Release|x86.Build.0 = Release|Any CPU {DFB936AD-90EE-4B4F-941E-4F4A636F0D92}.Release|x86.ActiveCfg = Release|Any CPU + {8AA421C8-D7AF-4957-9F43-5135328ACB24}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8AA421C8-D7AF-4957-9F43-5135328ACB24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8AA421C8-D7AF-4957-9F43-5135328ACB24}.Debug|x86.Build.0 = Debug|Any CPU + {8AA421C8-D7AF-4957-9F43-5135328ACB24}.Debug|x86.ActiveCfg = Debug|Any CPU + {8AA421C8-D7AF-4957-9F43-5135328ACB24}.Release|Any CPU.Build.0 = Release|Any CPU + {8AA421C8-D7AF-4957-9F43-5135328ACB24}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8AA421C8-D7AF-4957-9F43-5135328ACB24}.Release|x86.Build.0 = Release|Any CPU + {8AA421C8-D7AF-4957-9F43-5135328ACB24}.Release|x86.ActiveCfg = Release|Any CPU + {984CC812-9470-4A13-AFF9-CC44068D666C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {984CC812-9470-4A13-AFF9-CC44068D666C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {984CC812-9470-4A13-AFF9-CC44068D666C}.Debug|x86.Build.0 = Debug|Any CPU + {984CC812-9470-4A13-AFF9-CC44068D666C}.Debug|x86.ActiveCfg = Debug|Any CPU + {984CC812-9470-4A13-AFF9-CC44068D666C}.Release|Any CPU.Build.0 = Release|Any CPU + {984CC812-9470-4A13-AFF9-CC44068D666C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {984CC812-9470-4A13-AFF9-CC44068D666C}.Release|x86.Build.0 = Release|Any CPU + {984CC812-9470-4A13-AFF9-CC44068D666C}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -464,6 +484,7 @@ Global {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1} = {2A232EF1-EB95-41C6-B63A-C106E0C95D3C} {4139CCF6-FB49-4A9D-B2CF-331E9EA3198D} = {2A232EF1-EB95-41C6-B63A-C106E0C95D3C} {DDE2A481-8271-4EAC-A330-8FA6A38D13D1} = {2A232EF1-EB95-41C6-B63A-C106E0C95D3C} + {984CC812-9470-4A13-AFF9-CC44068D666C} = {2A232EF1-EB95-41C6-B63A-C106E0C95D3C} {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} = {E5A0F4D8-37FD-4A30-BEB0-4409DC4E0865} {53DCA265-3C3C-42F9-B647-F72BA678122B} = {E5A0F4D8-37FD-4A30-BEB0-4409DC4E0865} {DC393B66-92ED-4CAD-AB25-CFEF23F3D7C6} = {E5A0F4D8-37FD-4A30-BEB0-4409DC4E0865} @@ -493,6 +514,7 @@ Global {E618A9CD-A39F-4925-A538-E8A3FEF24E54} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F} {DCA2703D-250A-463E-A68A-07ED105AE6BD} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F} {DFB936AD-90EE-4B4F-941E-4F4A636F0D92} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F} + {8AA421C8-D7AF-4957-9F43-5135328ACB24} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F} {1F261725-6318-4434-A1B1-6C70CE4CD324} = {7019F43E-DFD7-4D1C-8C96-E75D55646DE7} {1D18D788-F7EE-4585-A23B-34DC8EC63CB8} = {49CE38B8-0460-46BF-9DFF-5B33A0F9EB5E} {EC06F96A-AEEC-49D6-B03D-AB87C6EB674C} = {49CE38B8-0460-46BF-9DFF-5B33A0F9EB5E} diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs index 0af90ee93b..a5b9a90a7f 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs @@ -12,6 +12,7 @@ namespace ICSharpCode.XamlBinding /// /// Description of XamlLanguageBinding. /// + [TextEditorService] public class XamlLanguageBinding : XmlEditor.XmlLanguageBinding { // XamlColorizer colorizer; diff --git a/src/AddIns/Debugger/Debugger.AddIn/Pads/BreakPointsPad.cs b/src/AddIns/Debugger/Debugger.AddIn/Pads/BreakPointsPad.cs index 97179860ed..5054e62061 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Pads/BreakPointsPad.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Pads/BreakPointsPad.cs @@ -37,11 +37,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads protected override void OnItemActivated(SDBookmark bookmark) { if (bookmark is DecompiledBreakpointBookmark) { - // get information from breakpoint and navigate to the decompiled type - string assemblyFile, typeName; - if (DecompiledBreakpointBookmark.GetAssemblyAndType(bookmark.FileName, out assemblyFile, out typeName)) { - NavigationService.NavigateTo(assemblyFile, typeName, string.Empty, bookmark.LineNumber, false); - } +// // get information from breakpoint and navigate to the decompiled type +// string assemblyFile, typeName; +// if (DecompiledBreakpointBookmark.GetAssemblyAndType(bookmark.FileName, out assemblyFile, out typeName)) { +// NavigationService.NavigateTo(assemblyFile, typeName, string.Empty, bookmark.LineNumber, false); +// } + throw new NotImplementedException(); } else { base.OnItemActivated(bookmark); } diff --git a/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs b/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs index 742d2cf239..0d32108139 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs @@ -358,9 +358,7 @@ namespace ICSharpCode.SharpDevelop.Services public void InitializeService() { // get decompiler service - var items = AddInTree.BuildItems("/SharpDevelop/Services/DebuggerDecompilerService", null, false); - if (items.Count > 0) - debuggerDecompilerService = items[0]; + debuggerDecompilerService = SD.GetService(); // init NDebugger CurrentDebugger = new NDebugger(); diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs index 09de907e73..a877686570 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs @@ -2,6 +2,7 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; +using System.ComponentModel.Design; using System.IO; using System.Linq; using System.Text; @@ -34,6 +35,11 @@ namespace ICSharpCode.AvalonEdit.AddIn public AvalonEditViewContent(OpenedFile file, Encoding fixedEncodingForLoading = null) { + // Use common service container for view content and primary text editor. + // This makes all text editor services available as view content services and vice versa. + // (with the exception of the interfaces implemented directly by this class, + // those are available as view-content services only) + this.Services = codeEditor.PrimaryTextEditor.GetRequiredService(); if (fixedEncodingForLoading != null) { codeEditor.UseFixedEncoding = true; codeEditor.PrimaryTextEditor.Encoding = fixedEncodingForLoading; diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs index 4da018d6bb..8ac2d6d96e 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs @@ -37,6 +37,7 @@ namespace ICSharpCode.AvalonEdit.AddIn /// Integrates AvalonEdit with SharpDevelop. /// Also provides support for Split-View (showing two AvalonEdit instances using the same TextDocument) /// + [TextEditorService] public class CodeEditor : Grid, IDisposable { const string contextMenuPath = "/SharpDevelop/ViewContent/AvalonEdit/ContextMenu"; diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/EnhancedScrollBar.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/EnhancedScrollBar.cs index b9faf7d5f2..061e50eaaa 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/EnhancedScrollBar.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/EnhancedScrollBar.cs @@ -21,6 +21,7 @@ namespace ICSharpCode.AvalonEdit.AddIn /// /// Scrollbar that shows markers. /// + [TextEditorService] public class EnhancedScrollBar : IDisposable { readonly TextEditor editor; diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs index d729b1a0e7..7eb287e234 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.Design; using System.Globalization; using System.IO; using System.Linq; @@ -43,7 +44,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options textMarkerService = new TextMarkerService(textEditor.Document); textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService); textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService); - textEditor.TextArea.TextView.Services.AddService(typeof(ITextMarkerService), textMarkerService); + textEditor.Document.GetRequiredService().AddService(typeof(ITextMarkerService), textMarkerService); } BracketHighlightRenderer bracketHighlighter; diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ParserFoldingStrategy.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ParserFoldingStrategy.cs index e9a0a85466..010b515d4f 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ParserFoldingStrategy.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ParserFoldingStrategy.cs @@ -8,6 +8,7 @@ using System.Linq; using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Folding; using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Parser; namespace ICSharpCode.AvalonEdit.AddIn @@ -15,6 +16,7 @@ namespace ICSharpCode.AvalonEdit.AddIn /// /// Uses the NRefactory type system to create parsing information. /// + [TextEditorService] public class ParserFoldingStrategy : IDisposable { readonly FoldingManager foldingManager; diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/DebuggerDecompilerService.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/DebuggerDecompilerService.cs index a499d0b4fe..5b5666df7e 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/DebuggerDecompilerService.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/DebuggerDecompilerService.cs @@ -15,6 +15,7 @@ using Mono.Cecil; namespace ICSharpCode.ILSpyAddIn { + /* // Dummy class to avoid the build errors after updating the ICSharpCode.Decompiler version. // TODO: get rid of this & fix debugging decompiled files public class DecompileInformation { @@ -83,15 +84,15 @@ namespace ICSharpCode.ILSpyAddIn DebuggerTextOutput output = new DebuggerTextOutput(new PlainTextOutput()); astBuilder.GenerateCode(output); - /*int token = type.MetadataToken.ToInt32(); - var info = new DecompileInformation { - CodeMappings = astBuilder.CodeMappings, - LocalVariables = astBuilder.LocalVariables, - DecompiledMemberReferences = astBuilder.DecompiledMemberReferences - }; - - // save the data - DebugInformation.AddOrUpdate(token, info, (k, v) => info);*/ +// int token = type.MetadataToken.ToInt32(); +// var info = new DecompileInformation { +// CodeMappings = astBuilder.CodeMappings, +// LocalVariables = astBuilder.LocalVariables, +// DecompiledMemberReferences = astBuilder.DecompiledMemberReferences +// }; +// +// // save the data +// DebugInformation.AddOrUpdate(token, info, (k, v) => info); } catch { return; } @@ -199,4 +200,5 @@ namespace ICSharpCode.ILSpyAddIn return resolver; } } + */ } diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.addin b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.addin index 7b4da78f64..2577b4636b 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.addin +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.addin @@ -16,12 +16,8 @@ - - - - - + diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj index b0ced697c2..a6a2d2bc71 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj @@ -7,7 +7,7 @@ Library ICSharpCode.ILSpyAddIn ILSpyAddIn - v4.0 + v4.5 Properties ..\..\..\..\AddIns\DisplayBindings\Decompiler\ False @@ -74,7 +74,7 @@ SetILSpyPathDialog.cs - + @@ -99,17 +99,14 @@ Mono.Cecil False - + {53DCA265-3C3C-42F9-B647-F72BA678122B} ICSharpCode.NRefactory.CSharp + False - + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} ICSharpCode.NRefactory - - - {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195} - NRefactory False @@ -122,11 +119,6 @@ ICSharpCode.Core False - - {924EE450-603D-49C1-A8E5-4AFAA31CE6F3} - ICSharpCode.SharpDevelop.Dom - False - {0162E499-42D0-409B-AA25-EED21F75336B} AvalonEdit.AddIn diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/ILSpyAssemblyResolver.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/ILSpyAssemblyResolver.cs index da290dadc9..61b61d69a7 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/ILSpyAssemblyResolver.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/ILSpyAssemblyResolver.cs @@ -6,9 +6,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; - using ICSharpCode.Core; -using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Parser; using Mono.Cecil; namespace ICSharpCode.ILSpyAddIn.LaunchILSpy @@ -61,7 +61,7 @@ namespace ICSharpCode.ILSpyAddIn.LaunchILSpy if (assembly == null) { // search using ILSpy's GacInterop.FindAssemblyInNetGac() - string fileInGac = FindAssemblyInNetGac(name); + string fileInGac = SD.GlobalAssemblyCache.FindAssemblyInNetGac(new DomAssemblyName(name.FullName)); if (!string.IsNullOrEmpty(fileInGac)) { assembly = AssemblyDefinition.ReadAssembly(fileInGac, parameters); } @@ -103,75 +103,5 @@ namespace ICSharpCode.ILSpyAddIn.LaunchILSpy } } } - - #region FindAssemblyInGac - // This region is based on code from Mono.Cecil: - - // Author: - // Jb Evain (jbevain@gmail.com) - // - // Copyright (c) 2008 - 2010 Jb Evain - // - // 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. - // - - static readonly string[] gac_paths = { GacInterop.GacRootPathV2, GacInterop.GacRootPathV4 }; - static readonly string[] gacs = { "GAC_MSIL", "GAC_32", "GAC" }; - static readonly string[] prefixes = { string.Empty, "v4.0_" }; - - /// - /// Gets the file name for an assembly stored in the GAC. - /// - public static string FindAssemblyInNetGac (AssemblyNameReference reference) - { - // without public key, it can't be in the GAC - if (reference.PublicKeyToken == null) - return null; - - for (int i = 0; i < 2; i++) { - for (int j = 0; j < gacs.Length; j++) { - var gac = Path.Combine (gac_paths [i], gacs [j]); - var file = GetAssemblyFile (reference, prefixes [i], gac); - if (File.Exists (file)) - return file; - } - } - - return null; - } - - static string GetAssemblyFile (AssemblyNameReference reference, string prefix, string gac) - { - var gac_folder = new StringBuilder () - .Append (prefix) - .Append (reference.Version) - .Append ("__"); - - for (int i = 0; i < reference.PublicKeyToken.Length; i++) - gac_folder.Append (reference.PublicKeyToken [i].ToString ("x2")); - - return Path.Combine ( - Path.Combine ( - Path.Combine (gac, reference.Name), gac_folder.ToString ()), - reference.Name + ".dll"); - } - #endregion } } diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/ILSpyController.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/ILSpyController.cs index 28c1d2c78b..ae02b7baf3 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/ILSpyController.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/ILSpyController.cs @@ -8,7 +8,9 @@ using System.IO; using System.Text; using System.Windows.Forms; using ICSharpCode.Core; -using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.NRefactory.Documentation; +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Project; @@ -19,29 +21,20 @@ namespace ICSharpCode.ILSpyAddIn /// public static class ILSpyController { - public static void TryGoTo(AbstractEntity entity) + public static void OpenInILSpy(IEntity entity) { if (entity == null) throw new ArgumentNullException("entity"); - while ((entity is IMember) && ((IMember)entity).GenericMember is AbstractEntity) - entity = (AbstractEntity)((IMember)entity).GenericMember; + // Get the underlying entity for generic instance members + if (entity is IMember) + entity = ((IMember)entity).MemberDefinition; // Try to find the assembly which contains the resolved type - IProjectContent pc = entity.ProjectContent; - ReflectionProjectContent rpc = pc as ReflectionProjectContent; - string assemblyLocation = null; - if (rpc != null) { - assemblyLocation = GetAssemblyLocation(rpc); - } else { - IProject project = pc.Project as IProject; - if (project != null) { - assemblyLocation = project.OutputAssemblyFullPath; - } - } + var assemblyLocation = entity.ParentAssembly.GetRuntimeAssemblyLocation(); if (string.IsNullOrEmpty(assemblyLocation)) { - MessageService.ShowWarning("ILSpy AddIn: Could not determine the assembly location for " + entity.FullyQualifiedName + "."); + MessageService.ShowWarning("ILSpy AddIn: Could not determine the assembly location for " + entity.ParentAssembly.AssemblyName + "."); return; } @@ -49,19 +42,11 @@ namespace ICSharpCode.ILSpyAddIn if (string.IsNullOrEmpty(ilspyPath)) return; - string commandLine = "/singleInstance \"" + assemblyLocation + "\" \"/navigateTo:" + entity.DocumentationTag + "\""; + string commandLine = "/singleInstance \"" + assemblyLocation + "\" \"/navigateTo:" + IdStringProvider.GetIdString(entity) + "\""; LoggingService.Debug(ilspyPath + " " + commandLine); Process.Start(ilspyPath, commandLine); } - public static string GetAssemblyLocation(ReflectionProjectContent rpc) - { - if (rpc == null) - throw new ArgumentNullException("rpc"); - // prefer GAC assemblies over reference assemblies: - return rpc.RealAssemblyLocation; - } - #region Find ILSpy internal const string ILSpyExePathPropertyName = "ILSpyAddIn.ILSpyExePath"; @@ -73,7 +58,7 @@ namespace ICSharpCode.ILSpyAddIn /// The full path of ILSpy.exe, or null if the path was unknown and the user cancelled the path selection dialog. internal static string GetILSpyExeFullPathInteractive() { - string path = PropertyService.Get(ILSpyExePathPropertyName); + string path = PropertyService.Get(ILSpyExePathPropertyName, ""); string askReason = null; if (String.IsNullOrEmpty(path)) { diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/TextEditorContextMenuCommand.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/OpenInILSpyCommand.cs similarity index 88% rename from src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/TextEditorContextMenuCommand.cs rename to src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/OpenInILSpyCommand.cs index 803c432b00..4650759f90 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/TextEditorContextMenuCommand.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/OpenInILSpyCommand.cs @@ -4,8 +4,6 @@ using System; using ICSharpCode.Core; using ICSharpCode.SharpDevelop.Bookmarks; -using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.SharpDevelop.Gui.ClassBrowser; namespace ICSharpCode.ILSpyAddIn { @@ -13,11 +11,13 @@ namespace ICSharpCode.ILSpyAddIn /// Implements a menu command to position .NET ILSpy on a class /// or class member. /// - public sealed class TextEditorContextMenuCommand : AbstractMenuCommand + public sealed class OpenInILSpyCommand : AbstractMenuCommand { public override void Run() { - IClass c; + throw new NotImplementedException(); + #warning implement OpenInILSpyCommand + /*IClass c; IMember m; MemberNode mn = this.Owner as MemberNode; @@ -56,8 +56,8 @@ namespace ICSharpCode.ILSpyAddIn if (entity == null) entity = c as AbstractEntity; if (entity != null) { - ILSpyController.TryGoTo(entity); - } + ILSpyController.OpenInILSpy(entity); + }*/ } } } diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/SetILSpyPathDialog.resx b/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/SetILSpyPathDialog.resx index 4bd20a8b5b..8762ad0018 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/SetILSpyPathDialog.resx +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/SetILSpyPathDialog.resx @@ -117,19 +117,20 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + False - - + + False - - + + False - - + + False - - + + False - + \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/NavigateToDecompiledEntityService.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/NavigateToDecompiledEntityService.cs index f9d16ed562..ed1f2d6300 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/NavigateToDecompiledEntityService.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/NavigateToDecompiledEntityService.cs @@ -4,14 +4,15 @@ using System; using System.IO; using System.Linq; - +using ICSharpCode.Core; +using ICSharpCode.NRefactory.Documentation; +using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.ILSpyAddIn { - public class NavigateToDecompiledEntityService : INavigateToEntityService, INavigateToMemberService + public class NavigateToDecompiledEntityService : INavigateToEntityService { public bool NavigateToEntity(IEntity entity) { @@ -19,46 +20,43 @@ namespace ICSharpCode.ILSpyAddIn throw new ArgumentNullException("entity"); // Get the underlying entity for generic instance members - while ((entity is IMember) && ((IMember)entity).GenericMember != null) - entity = ((IMember)entity).GenericMember; + if (entity is IMember) + entity = ((IMember)entity).MemberDefinition; - IClass declaringType = (entity as IClass) ?? entity.DeclaringType; + ITypeDefinition declaringType = (entity as ITypeDefinition) ?? entity.DeclaringTypeDefinition; if (declaringType == null) return false; // get the top-level type - while (declaringType.DeclaringType != null) - declaringType = declaringType.DeclaringType; + while (declaringType.DeclaringTypeDefinition != null) + declaringType = declaringType.DeclaringTypeDefinition; - ReflectionProjectContent rpc = entity.ProjectContent as ReflectionProjectContent; - if (rpc != null) { - string assemblyLocation = ILSpyController.GetAssemblyLocation(rpc); - if (!string.IsNullOrEmpty(assemblyLocation) && File.Exists(assemblyLocation)) { - NavigateTo(assemblyLocation, declaringType.DotNetName, ((AbstractEntity)entity).DocumentationTag); - return true; - } + FileName assemblyLocation = declaringType.ParentAssembly.GetRuntimeAssemblyLocation(); + if (assemblyLocation != null && File.Exists(assemblyLocation)) { + NavigateTo(assemblyLocation, declaringType.ReflectionName, IdStringProvider.GetIdString(entity)); + return true; } return false; } - public static void NavigateTo(string assemblyFile, string typeName, string entityTag) + public static void NavigateTo(FileName assemblyFile, string typeName, string entityIdString) { - if (string.IsNullOrEmpty(assemblyFile)) - throw new ArgumentException("assemblyFile is null or empty"); - + if (assemblyFile == null) + throw new ArgumentNullException("assemblyFile"); if (string.IsNullOrEmpty(typeName)) throw new ArgumentException("typeName is null or empty"); foreach (var viewContent in WorkbenchSingleton.Workbench.ViewContentCollection.OfType()) { - if (string.Equals(viewContent.AssemblyFile, assemblyFile, StringComparison.OrdinalIgnoreCase) && typeName == viewContent.FullTypeName) { + if (viewContent.AssemblyFile == assemblyFile && typeName == viewContent.FullTypeName) { viewContent.WorkbenchWindow.SelectWindow(); - viewContent.JumpToEntity(entityTag); + viewContent.JumpToEntity(entityIdString); return; } } - WorkbenchSingleton.Workbench.ShowView(new DecompiledViewContent(assemblyFile, typeName, entityTag)); + WorkbenchSingleton.Workbench.ShowView(new DecompiledViewContent(assemblyFile, typeName, entityIdString)); } - public bool NavigateToMember(string assemblyFile, string typeName, string entityTag, int lineNumber, bool updateMarker) + /* + public bool NavigateToMember(FileName assemblyFile, string typeName, string entityTag, int lineNumber, bool updateMarker) { if (string.IsNullOrEmpty(assemblyFile)) throw new ArgumentException("assemblyFile is null or empty"); @@ -95,5 +93,6 @@ namespace ICSharpCode.ILSpyAddIn WorkbenchSingleton.Workbench.ShowView(decompiledView); return true; } + */ } } diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/CodeView.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/CodeView.cs index e5c89b553b..b7dc62cefe 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/CodeView.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/CodeView.cs @@ -2,6 +2,7 @@ // This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; +using System.ComponentModel.Design; using System.Diagnostics; using System.Windows; using System.Windows.Controls; @@ -13,6 +14,8 @@ using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Rendering; using ICSharpCode.AvalonEdit.Search; +using ICSharpCode.Core; +using ICSharpCode.NRefactory.Editor; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Bookmarks; using ICSharpCode.SharpDevelop.Editor; @@ -21,180 +24,44 @@ using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.ILSpyAddIn.ViewContent { - class DecompiledTextEditorAdapter : AvalonEditTextEditorAdapter - { - public DecompiledTextEditorAdapter(TextEditor textEditor) : base(textEditor) - {} - - public string DecompiledFileName { get; set; } - - public override ICSharpCode.Core.FileName FileName { - get { return ICSharpCode.Core.FileName.Create(DecompiledFileName); } - } - } - /// /// Equivalent to AE.AddIn CodeEditor, but without editing capabilities. /// class CodeView : Grid, IDisposable, IPositionable { - public event EventHandler DocumentChanged; - - readonly DecompiledTextEditorAdapter adapter; + readonly SharpDevelopTextEditor textEditor; readonly IconBarManager iconBarManager; readonly IconBarMargin iconMargin; readonly TextMarkerService textMarkerService; + readonly AvalonEditTextEditorAdapter adapter; - public CodeView(string decompiledFileName) + public CodeView() { - this.adapter = new DecompiledTextEditorAdapter(new SharpDevelopTextEditor { IsReadOnly = true }) { - DecompiledFileName = decompiledFileName - }; - this.Children.Add(adapter.TextEditor); - adapter.TextEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#"); + textEditor = new SharpDevelopTextEditor(); + textEditor.IsReadOnly = true; + this.Children.Add(textEditor); + adapter = new AvalonEditTextEditorAdapter(textEditor); + + textEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#"); // add margin this.iconMargin = new IconBarMargin(iconBarManager = new IconBarManager()); - this.adapter.TextEditor.TextArea.LeftMargins.Insert(0, iconMargin); - this.adapter.TextEditor.TextArea.TextView.VisualLinesChanged += delegate { iconMargin.InvalidateVisual(); }; + textEditor.TextArea.LeftMargins.Insert(0, iconMargin); + textEditor.TextArea.TextView.VisualLinesChanged += delegate { iconMargin.InvalidateVisual(); }; // add marker service - this.textMarkerService = new TextMarkerService(adapter.TextEditor.Document); - this.adapter.TextEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService); - this.adapter.TextEditor.TextArea.TextView.LineTransformers.Add(textMarkerService); - this.adapter.TextEditor.TextArea.TextView.Services.AddService(typeof(ITextMarkerService), textMarkerService); - this.adapter.TextEditor.TextArea.TextView.Services.AddService(typeof(IBookmarkMargin), iconBarManager); - // DON'T add the editor in textview ervices - will mess the setting of breakpoints + this.textMarkerService = new TextMarkerService(textEditor.Document); + textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService); + textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService); + var documentServiceContainer = textEditor.Document.GetRequiredService(); + documentServiceContainer.AddService(typeof(ITextMarkerService), textMarkerService); + documentServiceContainer.AddService(typeof(IBookmarkMargin), iconBarManager); - // add events - this.adapter.TextEditor.MouseHover += TextEditorMouseHover; - this.adapter.TextEditor.MouseHoverStopped += TextEditorMouseHoverStopped; - this.adapter.TextEditor.MouseLeave += TextEditorMouseLeave; - - this.adapter.TextEditor.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(this.adapter.TextEditor.TextArea)); + textEditor.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(textEditor.TextArea)); } - #region Popup - ToolTip toolTip; - Popup popupToolTip; - - void TextEditorMouseHover(object sender, MouseEventArgs e) - { - ToolTipRequestEventArgs args = new ToolTipRequestEventArgs(this.adapter); - var pos = adapter.TextEditor.GetPositionFromPoint(e.GetPosition(this)); - args.InDocument = pos.HasValue; - if (pos.HasValue) { - args.LogicalPosition = AvalonEditDocumentAdapter.ToLocation(pos.Value.Location); - } - - if (!args.Handled) { - // if request wasn't handled by a marker, pass it to the ToolTipRequestService - ToolTipRequestService.RequestToolTip(args); - } - - if (!TryCloseExistingPopup(false)) { - return; - } - - if (args.ContentToShow != null) { - popupToolTip = args.ContentToShow as Popup; - - if (popupToolTip != null) { - var popupPosition = GetPopupPosition(e); - popupToolTip.HorizontalOffset = popupPosition.X; - popupToolTip.VerticalOffset = popupPosition.Y; - popupToolTip.IsOpen = true; - popupToolTip.StaysOpen = true; // We will close it ourselves - e.Handled = true; - } else { - if (toolTip == null) { - toolTip = new ToolTip(); - toolTip.Closed += delegate { toolTip = null; }; - } - toolTip.PlacementTarget = this.adapter.TextEditor; // required for property inheritance - - if(args.ContentToShow is string) { - toolTip.Content = new TextBlock - { - Text = args.ContentToShow as string, - TextWrapping = TextWrapping.Wrap - }; - } - else - toolTip.Content = args.ContentToShow; - - toolTip.IsOpen = true; - e.Handled = true; - } - } - } - - bool TryCloseExistingPopup(bool mouseClick) - { - if (popupToolTip != null) { - if (popupToolTip.IsOpen && !mouseClick && popupToolTip is ITooltip && !((ITooltip)popupToolTip).CloseOnHoverEnd) { - return false; // Popup does not want to be closed yet - } - popupToolTip.IsOpen = false; - popupToolTip = null; - } - return true; - } - - /// Returns Popup position based on mouse position, in device independent units - Point GetPopupPosition(MouseEventArgs mouseArgs) - { - Point mousePos = mouseArgs.GetPosition(this); - Point positionInPixels; - // align Popup with line bottom - TextViewPosition? logicalPos = adapter.TextEditor.GetPositionFromPoint(mousePos); - if (logicalPos.HasValue) { - var textView = adapter.TextEditor.TextArea.TextView; - positionInPixels = - textView.PointToScreen( - textView.GetVisualPosition(logicalPos.Value, VisualYPosition.LineBottom) - textView.ScrollOffset); - positionInPixels.X -= 4; - } else { - positionInPixels = PointToScreen(mousePos + new Vector(-4, 6)); - } - // use device independent units, because Popup Left/Top are in independent units - return positionInPixels.TransformFromDevice(this); - } - - void TextEditorMouseHoverStopped(object sender, MouseEventArgs e) - { - if (toolTip != null) { - toolTip.IsOpen = false; - e.Handled = true; - } - - TextEditorMouseLeave(sender, e); - } - - void TextEditorMouseLeave(object sender, MouseEventArgs e) - { - if (popupToolTip != null && !popupToolTip.IsMouseOver) { - // do not close popup if mouse moved from editor to popup - TryCloseExistingPopup(false); - } - } - - #endregion - public TextDocument Document { - get { return adapter.TextEditor.Document; } - set { - adapter.TextEditor.Document = value; - if (DocumentChanged != null) { - DocumentChanged(value, EventArgs.Empty); - } - } - } - - public ITextEditor TextEditor { - get { - return adapter; - } + get { return textEditor.Document; } } public IconBarManager IconBarManager { @@ -205,47 +72,21 @@ namespace ICSharpCode.ILSpyAddIn.ViewContent { } - public void UnfoldAndScroll(int lineNumber) - { - if (lineNumber <= 0 || lineNumber > adapter.Document.TotalNumberOfLines) - return; - -// var line = adapter.TextEditor.Document.GetLineByNumber(lineNumber); - -// // unfold -// var foldings = foldingManager.GetFoldingsContaining(line.Offset); -// if (foldings != null) { -// foreach (var folding in foldings) { -// if (folding.IsFolded) { -// folding.IsFolded = false; -// } -// } -// } - - // scroll to - adapter.TextEditor.ScrollTo(lineNumber, 0); - } - - public void Redraw(ISegment segment, System.Windows.Threading.DispatcherPriority priority) - { - this.adapter.TextEditor.TextArea.TextView.Redraw(segment, priority); - } - public int Line { get { - return this.adapter.Caret.Line; + return textEditor.TextArea.Caret.Line; } } public int Column { get { - return this.adapter.Caret.Column; + return textEditor.TextArea.Caret.Column; } } public void JumpTo(int line, int column) { - this.adapter.JumpTo(line, column); + adapter.JumpTo(line, column); } } } diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/DecompiledViewContent.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/DecompiledViewContent.cs index 3aedad43d2..f0c587b605 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/DecompiledViewContent.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/DecompiledViewContent.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.Design; using System.IO; using System.Linq; using System.Threading; @@ -27,56 +28,52 @@ namespace ICSharpCode.ILSpyAddIn /// class DecompiledViewContent : AbstractViewContentWithoutFile { - readonly string assemblyFile; + readonly FileName assemblyFile; readonly string fullTypeName; - readonly string tempFileName; + readonly string uri; /// /// Entity to jump to once decompilation has finished. /// - string jumpToEntityTagWhenDecompilationFinished; + string jumpToEntityIdStringWhenDecompilationFinished; bool decompilationFinished; readonly CodeView codeView; readonly CancellationTokenSource cancellation = new CancellationTokenSource(); - MemberReference decompiledType; Dictionary memberLocations; #region Constructor - public DecompiledViewContent(string assemblyFile, string fullTypeName, string entityTag) + public DecompiledViewContent(FileName assemblyFile, string fullTypeName, string entityTag) { - // TODO: create options for decompiling in a specific language - this.tempFileName = string.Format("{0}{1}{2}.cs", assemblyFile, DecompiledBreakpointBookmark.SEPARATOR, fullTypeName); - this.codeView = new CodeView(tempFileName); + this.uri = string.Format("ilspy://{0}|{1}", assemblyFile, fullTypeName); + this.codeView = new CodeView(); this.assemblyFile = assemblyFile; this.fullTypeName = fullTypeName; - this.jumpToEntityTagWhenDecompilationFinished = entityTag; + this.jumpToEntityIdStringWhenDecompilationFinished = entityTag; string shortTypeName = fullTypeName.Substring(fullTypeName.LastIndexOf('.') + 1); this.TitleName = "[" + shortTypeName + "]"; - this.InfoTip = tempFileName; - Thread thread = new Thread(DecompilationThread); thread.Name = "Decompiler (" + shortTypeName + ")"; thread.Start(); BookmarkManager.Removed += BookmarkManager_Removed; BookmarkManager.Added += BookmarkManager_Added; - - // add services - this.Services.AddService(typeof(ITextEditor), this.codeView.TextEditor); } #endregion #region Properties - public string AssemblyFile { + public FileName AssemblyFile { get { return assemblyFile; } } + /// + /// The reflection name of the top-level type displayed in this view content. + /// public string FullTypeName { get { return fullTypeName; } } @@ -98,11 +95,8 @@ namespace ICSharpCode.ILSpyAddIn codeView.Dispose(); BookmarkManager.Added -= BookmarkManager_Added; BookmarkManager.Removed -= BookmarkManager_Removed; - if (decompiledType != null) { - DecompileInformation data; - DebuggerDecompilerService.DebugInformation.TryRemove(decompiledType.MetadataToken.ToInt32(), out data); - data = null; - } +// DecompileInformation data; +// DebuggerDecompilerService.DebugInformation.TryRemove(decompiledType.MetadataToken.ToInt32(), out data); base.Dispose(); } #endregion @@ -122,14 +116,14 @@ namespace ICSharpCode.ILSpyAddIn #endregion #region JumpToEntity - public void JumpToEntity(string entityTag) + public void JumpToEntity(string entityIdString) { if (!decompilationFinished) { - this.jumpToEntityTagWhenDecompilationFinished = entityTag; + this.jumpToEntityIdStringWhenDecompilationFinished = entityIdString; return; } TextLocation location; - if (memberLocations != null && memberLocations.TryGetValue(entityTag, out location)) + if (memberLocations != null && memberLocations.TryGetValue(entityIdString, out location)) codeView.JumpTo(location.Line, location.Column); } #endregion @@ -150,7 +144,7 @@ namespace ICSharpCode.ILSpyAddIn MessageService.ShowException(ex); return; } - AnalyticsMonitorService.TrackException(ex); + SD.AnalyticsMonitor.TrackException(ex); StringWriter writer = new StringWriter(); writer.WriteLine(string.Format("Exception while decompiling {0} ({1})", fullTypeName, assemblyFile)); @@ -178,7 +172,6 @@ namespace ICSharpCode.ILSpyAddIn astBuilder.GenerateCode(textOutput); // save decompilation data - decompiledType = typeDefinition; memberLocations = textOutput.MemberLocations; } @@ -190,10 +183,10 @@ namespace ICSharpCode.ILSpyAddIn codeView.Document.UndoStack.ClearAll(); this.decompilationFinished = true; - JumpToEntity(this.jumpToEntityTagWhenDecompilationFinished); + JumpToEntity(this.jumpToEntityIdStringWhenDecompilationFinished); // update UI - UpdateIconMargin(); + //UpdateIconMargin(); // fire events OnDecompilationFinished(EventArgs.Empty); @@ -201,6 +194,7 @@ namespace ICSharpCode.ILSpyAddIn #endregion #region Update UI + /* void UpdateIconMargin() { codeView.IconBarManager.UpdateClassMemberBookmarks( @@ -250,30 +244,19 @@ namespace ICSharpCode.ILSpyAddIn this.JumpToLineNumber(line); } - public void JumpToLineNumber(int lineNumber) - { - if (codeView == null || codeView.Document == null) - return; - - if (lineNumber <= 0 || lineNumber > codeView.Document.LineCount) - return; - - codeView.UnfoldAndScroll(lineNumber); - } - void UpdateCurrentLineBookmark(int lineNumber) { if (lineNumber <= 0) return; - CurrentLineBookmark.SetPosition(codeView.TextEditor.FileName, codeView.TextEditor.Document, lineNumber, 0, lineNumber, 0); + CurrentLineBookmark.SetPosition(uri, codeView.Document, lineNumber, 0, lineNumber, 0); var currentLineBookmark = BookmarkManager.Bookmarks.OfType().FirstOrDefault(); if (currentLineBookmark != null) { // update bookmark & marker codeView.IconBarManager.Bookmarks.Add(currentLineBookmark); currentLineBookmark.Document = this.codeView.TextEditor.Document; } - } + }*/ #endregion @@ -290,9 +273,9 @@ namespace ICSharpCode.ILSpyAddIn void BookmarkManager_Added(object sender, BookmarkEventArgs e) { var mark = e.Bookmark; - if (mark != null && mark is BreakpointBookmark && mark.FileName == this.codeView.TextEditor.FileName) { + if (mark != null && mark is BreakpointBookmark && mark.FileName == uri) { codeView.IconBarManager.Bookmarks.Add(mark); - mark.Document = this.codeView.TextEditor.Document; + mark.Document = this.codeView.Document; } } #endregion diff --git a/src/Libraries/ICSharpCode.Decompiler/Ast/AstBuilder.cs b/src/Libraries/ICSharpCode.Decompiler/Ast/AstBuilder.cs index a95ddbaf2d..b915fc5040 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Ast/AstBuilder.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Ast/AstBuilder.cs @@ -52,7 +52,7 @@ namespace ICSharpCode.Decompiler.Ast public class AstBuilder { DecompilerContext context; - CompilationUnit astCompileUnit = new CompilationUnit(); + SyntaxTree syntaxTree = new SyntaxTree(); Dictionary astNamespaces = new Dictionary(); bool transformationsHaveRun; @@ -139,15 +139,15 @@ namespace ICSharpCode.Decompiler.Ast public void RunTransformations(Predicate transformAbortCondition) { - TransformationPipeline.RunTransformationsUntil(astCompileUnit, transformAbortCondition, context); + TransformationPipeline.RunTransformationsUntil(syntaxTree, transformAbortCondition, context); transformationsHaveRun = true; } /// /// Gets the abstract source tree. /// - public CompilationUnit CompilationUnit { - get { return astCompileUnit; } + public SyntaxTree SyntaxTree { + get { return syntaxTree; } } /// @@ -159,16 +159,16 @@ namespace ICSharpCode.Decompiler.Ast if (!transformationsHaveRun) RunTransformations(); - astCompileUnit.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); - var outputFormatter = new TextOutputFormatter(output); + syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); + var outputFormatter = new TextOutputFormatter(output) { FoldBraces = context.Settings.FoldBraces }; var formattingPolicy = context.Settings.CSharpFormattingOptions; - astCompileUnit.AcceptVisitor(new CSharpOutputVisitor(outputFormatter, formattingPolicy)); + syntaxTree.AcceptVisitor(new CSharpOutputVisitor(outputFormatter, formattingPolicy)); } public void AddAssembly(AssemblyDefinition assemblyDefinition, bool onlyAssemblyLevel = false) { if (assemblyDefinition.Name.Version != null) { - astCompileUnit.AddChild( + syntaxTree.AddChild( new AttributeSection { AttributeTarget = "assembly", Attributes = { @@ -185,10 +185,10 @@ namespace ICSharpCode.Decompiler.Ast }, EntityDeclaration.AttributeRole); } - ConvertCustomAttributes(astCompileUnit, assemblyDefinition, "assembly"); - ConvertSecurityAttributes(astCompileUnit, assemblyDefinition, "assembly"); - ConvertCustomAttributes(astCompileUnit, assemblyDefinition.MainModule, "module"); - AddTypeForwarderAttributes(astCompileUnit, assemblyDefinition.MainModule, "assembly"); + ConvertCustomAttributes(syntaxTree, assemblyDefinition, "assembly"); + ConvertSecurityAttributes(syntaxTree, assemblyDefinition, "assembly"); + ConvertCustomAttributes(syntaxTree, assemblyDefinition.MainModule, "module"); + AddTypeForwarderAttributes(syntaxTree, assemblyDefinition.MainModule, "assembly"); if (!onlyAssemblyLevel) { foreach (TypeDefinition typeDef in assemblyDefinition.MainModule.Types) { @@ -203,7 +203,7 @@ namespace ICSharpCode.Decompiler.Ast } } - void AddTypeForwarderAttributes(CompilationUnit astCompileUnit, ModuleDefinition module, string target) + void AddTypeForwarderAttributes(SyntaxTree astCompileUnit, ModuleDefinition module, string target) { if (!module.HasExportedTypes) return; @@ -237,7 +237,7 @@ namespace ICSharpCode.Decompiler.Ast } else { // Create the namespace NamespaceDeclaration astNamespace = new NamespaceDeclaration { Name = name }; - astCompileUnit.AddChild(astNamespace, CompilationUnit.MemberRole); + syntaxTree.Members.Add(astNamespace); astNamespaces[name] = astNamespace; return astNamespace; } @@ -248,31 +248,31 @@ namespace ICSharpCode.Decompiler.Ast var astType = CreateType(typeDef); NamespaceDeclaration astNS = GetCodeNamespace(typeDef.Namespace); if (astNS != null) { - astNS.AddChild(astType, NamespaceDeclaration.MemberRole); + astNS.Members.Add(astType); } else { - astCompileUnit.AddChild(astType, CompilationUnit.MemberRole); + syntaxTree.Members.Add(astType); } } public void AddMethod(MethodDefinition method) { AstNode node = method.IsConstructor ? (AstNode)CreateConstructor(method) : CreateMethod(method); - astCompileUnit.AddChild(node, CompilationUnit.MemberRole); + syntaxTree.Members.Add(node); } public void AddProperty(PropertyDefinition property) { - astCompileUnit.AddChild(CreateProperty(property), CompilationUnit.MemberRole); + syntaxTree.Members.Add(CreateProperty(property)); } public void AddField(FieldDefinition field) { - astCompileUnit.AddChild(CreateField(field), CompilationUnit.MemberRole); + syntaxTree.Members.Add(CreateField(field)); } public void AddEvent(EventDefinition ev) { - astCompileUnit.AddChild(CreateEvent(ev), CompilationUnit.MemberRole); + syntaxTree.Members.Add(CreateEvent(ev)); } /// diff --git a/src/Libraries/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs b/src/Libraries/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs index 8ad9047c1c..3437af546b 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs @@ -755,7 +755,7 @@ namespace ICSharpCode.Decompiler.Ast for (int i = 0; i < args.Count; i++) { atce.Initializers.Add( new NamedExpression { - Identifier = ctor.Parameters[i].Name, + Name = ctor.Parameters[i].Name, Expression = args[i] }); } @@ -805,7 +805,7 @@ namespace ICSharpCode.Decompiler.Ast MemberReferenceExpression mre = m.Get("left").Single(); initializer.Elements.Add( new NamedExpression { - Identifier = mre.MemberName, + Name = mre.MemberName, Expression = m.Get("right").Single().Detach() }.CopyAnnotationsFrom(mre)); } else { diff --git a/src/Libraries/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs b/src/Libraries/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs index b17e24656f..5e3cef9947 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs @@ -36,6 +36,8 @@ namespace ICSharpCode.Decompiler.Ast bool firstUsingDeclaration; bool lastUsingDeclaration; + public bool FoldBraces = false; + public TextOutputFormatter(ITextOutput output) { if (output == null) @@ -183,7 +185,7 @@ namespace ICSharpCode.Decompiler.Ast { if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration) braceLevelWithinType++; - if (nodeStack.OfType().Count() <= 1) { + if (nodeStack.OfType().Count() <= 1 || FoldBraces) { output.MarkFoldStart(defaultCollapsed: braceLevelWithinType == 1); } output.WriteLine(); @@ -195,7 +197,7 @@ namespace ICSharpCode.Decompiler.Ast { output.Unindent(); output.Write('}'); - if (nodeStack.OfType().Count() <= 1) + if (nodeStack.OfType().Count() <= 1 || FoldBraces) output.MarkFoldEnd(); if (braceLevelWithinType >= 0) braceLevelWithinType--; diff --git a/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/CombineQueryExpressions.cs b/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/CombineQueryExpressions.cs index be6182b981..a0d1ca8c1e 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/CombineQueryExpressions.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/CombineQueryExpressions.cs @@ -82,11 +82,11 @@ namespace ICSharpCode.Decompiler.Ast.Transforms new AnonymousTypeCreateExpression { Initializers = { new NamedExpression { - Identifier = Pattern.AnyString, + Name = Pattern.AnyString, Expression = new IdentifierExpression(Pattern.AnyString) }.WithName("nae1"), new NamedExpression { - Identifier = Pattern.AnyString, + Name = Pattern.AnyString, Expression = new AnyNode("nae2Expr") }.WithName("nae2") } @@ -114,11 +114,11 @@ namespace ICSharpCode.Decompiler.Ast.Transforms QuerySelectClause selectClause = (QuerySelectClause)innerQuery.Clauses.Last(); NamedExpression nae1 = match.Get("nae1").SingleOrDefault(); NamedExpression nae2 = match.Get("nae2").SingleOrDefault(); - if (nae1 != null && nae1.Identifier != ((IdentifierExpression)nae1.Expression).Identifier) + if (nae1 != null && nae1.Name != ((IdentifierExpression)nae1.Expression).Identifier) return false; Expression nae2Expr = match.Get("nae2Expr").Single(); IdentifierExpression nae2IdentExpr = nae2Expr as IdentifierExpression; - if (nae2IdentExpr != null && (nae2 == null || nae2.Identifier == nae2IdentExpr.Identifier)) { + if (nae2IdentExpr != null && (nae2 == null || nae2.Name == nae2IdentExpr.Identifier)) { // from * in (from x in ... select new { x = x, y = y }) ... // => // from x in ... ... @@ -142,7 +142,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms } string ident; if (nae2 != null) - ident = nae2.Identifier; + ident = nae2.Name; else if (nae2Expr is IdentifierExpression) ident = ((IdentifierExpression)nae2Expr).Identifier; else if (nae2Expr is MemberReferenceExpression) diff --git a/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/ExpressionTreeConverter.cs b/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/ExpressionTreeConverter.cs index 3bc0596377..32f7cb0dbe 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/ExpressionTreeConverter.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/ExpressionTreeConverter.cs @@ -567,7 +567,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms for (int i = 0; i < resolvedCtor.Parameters.Count; i++) { atce.Initializers.Add( new NamedExpression { - Identifier = resolvedCtor.Parameters[i].Name, + Name = resolvedCtor.Parameters[i].Name, Expression = arguments[i].Detach() }); } diff --git a/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/IntroduceUsingDeclarations.cs b/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/IntroduceUsingDeclarations.cs index 55d49b977d..3d4a8e7c19 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/IntroduceUsingDeclarations.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/IntroduceUsingDeclarations.cs @@ -55,7 +55,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms for (int i = 1; i < parts.Length; i++) { nsType = new MemberType { Target = nsType, MemberName = parts[i] }; } - compilationUnit.InsertChildAfter(null, new UsingDeclaration { Import = nsType }, CompilationUnit.MemberRole); + compilationUnit.InsertChildAfter(null, new UsingDeclaration { Import = nsType }, SyntaxTree.MemberRole); } if (!context.Settings.FullyQualifyAmbiguousTypeNames) diff --git a/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs b/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs index fc02a15d72..22d1afe627 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs @@ -897,6 +897,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms #region Automatic Events static readonly Accessor automaticEventPatternV4 = new Accessor { + Attributes = { new Repeat(new AnyNode()) }, Body = new BlockStatement { new VariableDeclarationStatement { Type = new AnyNode("type"), Variables = { new AnyNode() } }, new VariableDeclarationStatement { Type = new Backreference("type"), Variables = { new AnyNode() } }, @@ -965,6 +966,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms return null; EventDeclaration ed = new EventDeclaration(); ev.Attributes.MoveTo(ed.Attributes); + foreach (var attr in ev.AddAccessor.Attributes) { + attr.AttributeTarget = "method"; + ed.Attributes.Add(attr.Detach()); + } ed.ReturnType = ev.ReturnType.Detach(); ed.Modifiers = ev.Modifiers; ed.Variables.Add(new VariableInitializer(ev.Name)); diff --git a/src/Libraries/ICSharpCode.Decompiler/DecompilerSettings.cs b/src/Libraries/ICSharpCode.Decompiler/DecompilerSettings.cs index f78194a6f9..36c91745ca 100644 --- a/src/Libraries/ICSharpCode.Decompiler/DecompilerSettings.cs +++ b/src/Libraries/ICSharpCode.Decompiler/DecompilerSettings.cs @@ -254,6 +254,18 @@ namespace ICSharpCode.Decompiler } } } + + bool foldBraces = false; + + public bool FoldBraces { + get { return foldBraces; } + set { + if (foldBraces != value) { + foldBraces = value; + OnPropertyChanged("FoldBraces"); + } + } + } #region Options to aid VB decompilation bool introduceIncrementAndDecrement = true; diff --git a/src/Libraries/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs b/src/Libraries/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs index 675d9e28a0..ed246a092a 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs @@ -674,6 +674,9 @@ namespace ICSharpCode.Decompiler.Disassembler public void DisassembleField(FieldDefinition field) { output.WriteDefinition(".field ", field); + if (field.HasLayoutInfo) { + output.Write("[" + field.Offset + "] "); + } WriteEnum(field.Attributes & FieldAttributes.FieldAccessMask, fieldVisibility); const FieldAttributes hasXAttributes = FieldAttributes.HasDefault | FieldAttributes.HasFieldMarshal | FieldAttributes.HasFieldRVA; WriteFlags(field.Attributes & ~(FieldAttributes.FieldAccessMask | hasXAttributes), fieldAttributes); diff --git a/src/Libraries/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/src/Libraries/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 60bead91a6..8ec5004283 100644 --- a/src/Libraries/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/src/Libraries/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -7,15 +7,16 @@ Library ICSharpCode.Decompiler ICSharpCode.Decompiler - v4.0 - Client + v4.5 + + Properties False False 4 false True - ..\NewNRefactory\ICSharpCode.NRefactory.snk + ..\NRefactory\ICSharpCode.NRefactory.snk False File @@ -131,14 +132,17 @@ {D68133BD-1E63-496E-9EDE-4FBDBF77B486} Mono.Cecil + False - + {53DCA265-3C3C-42F9-B647-F72BA678122B} ICSharpCode.NRefactory.CSharp + False - + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} ICSharpCode.NRefactory + False diff --git a/src/Libraries/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs b/src/Libraries/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs index 2e46e285bf..b050353ab4 100644 --- a/src/Libraries/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs +++ b/src/Libraries/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs @@ -303,7 +303,13 @@ namespace ICSharpCode.Decompiler.ILAst return v.Type; } case ILCode.Ldloca: - return new ByReferenceType(((ILVariable)expr.Operand).Type); + { + ILVariable v = (ILVariable)expr.Operand; + if (v.Type != null) + return new ByReferenceType(v.Type); + else + return null; + } #endregion #region Call / NewObj case ILCode.Call: @@ -385,23 +391,29 @@ namespace ICSharpCode.Decompiler.ILAst case ILCode.Ldobj: { TypeReference type = (TypeReference)expr.Operand; - if (expectedType != null) { - int infoAmount = GetInformationAmount(expectedType); + var argType = InferTypeForExpression(expr.Arguments[0], null); + if (argType is PointerType || argType is ByReferenceType) { + var elementType = ((TypeSpecification)argType).ElementType; + int infoAmount = GetInformationAmount(elementType); if (infoAmount == 1 && GetInformationAmount(type) == 8) { // A bool can be loaded from both bytes and sbytes. - type = expectedType; + type = elementType; } if (infoAmount >= 8 && infoAmount <= 64 && infoAmount == GetInformationAmount(type)) { // An integer can be loaded as another integer of the same size. // For integers smaller than 32 bit, the signs must match (as loading performs sign extension) - if (infoAmount >= 32 || IsSigned(expectedType) == IsSigned(type)) - type = expectedType; + bool? elementTypeIsSigned = IsSigned(elementType); + bool? typeIsSigned = IsSigned(type); + if (elementTypeIsSigned != null && typeIsSigned != null) { + if (infoAmount >= 32 || elementTypeIsSigned == typeIsSigned) + type = elementType; + } } } - if (forceInferChildren) { - if (InferTypeForExpression(expr.Arguments[0], new ByReferenceType(type)) is PointerType) - InferTypeForExpression(expr.Arguments[0], new PointerType(type)); - } + if (argType is PointerType) + InferTypeForExpression(expr.Arguments[0], new PointerType(type)); + else + InferTypeForExpression(expr.Arguments[0], new ByReferenceType(type)); return type; } case ILCode.Stobj: diff --git a/src/Libraries/ICSharpCode.Decompiler/Properties/AssemblyInfo.cs b/src/Libraries/ICSharpCode.Decompiler/Properties/AssemblyInfo.cs index 818b72b10b..96d8d145f0 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Properties/AssemblyInfo.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Properties/AssemblyInfo.cs @@ -19,8 +19,8 @@ using System.Runtime.InteropServices; // If you need to expose a type to COM, use [ComVisible(true)] on that type. [assembly: ComVisible(false)] -[assembly: AssemblyVersion("2.1.0.1603")] -[assembly: AssemblyInformationalVersion("2.1.0.1603-1170e2f8")] +[assembly: AssemblyVersion("2.1.0.1619")] +[assembly: AssemblyInformationalVersion("2.1.0.1619-214c1f73")] [assembly: NeutralResourcesLanguage("en-US")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2243:AttributeStringLiteralsShouldParseCorrectly", diff --git a/src/Libraries/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs b/src/Libraries/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs index df395b446f..3af31e282c 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs @@ -69,6 +69,19 @@ namespace AppliedToEvent public event EventHandler MyEvent; } } +//$$ AppliedToEventMethods +namespace AppliedToEventMethods +{ + [AttributeUsage(AttributeTargets.Method)] + public class MyAttributeAttribute : Attribute + { + } + public class TestClass + { + [method: MyAttribute] + public event EventHandler MyEvent; + } +} //$$ AppliedToField namespace AppliedToField { diff --git a/src/Libraries/ICSharpCode.Decompiler/Tests/DecompilerTestBase.cs b/src/Libraries/ICSharpCode.Decompiler/Tests/DecompilerTestBase.cs index 5eb7012284..8205042a97 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Tests/DecompilerTestBase.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Tests/DecompilerTestBase.cs @@ -58,7 +58,7 @@ namespace ICSharpCode.Decompiler.Tests AssemblyDefinition assembly = Compile(code); AstBuilder decompiler = new AstBuilder(new DecompilerContext(assembly.MainModule) { Settings = settings }); decompiler.AddAssembly(assembly); - new Helpers.RemoveCompilerAttribute().Run(decompiler.CompilationUnit); + new Helpers.RemoveCompilerAttribute().Run(decompiler.SyntaxTree); StringWriter output = new StringWriter(); decompiler.GenerateCode(new PlainTextOutput(output)); return output.ToString(); diff --git a/src/Libraries/ICSharpCode.Decompiler/Tests/IL/ILTests.cs b/src/Libraries/ICSharpCode.Decompiler/Tests/IL/ILTests.cs index 3cfed30f22..f06f3108c5 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Tests/IL/ILTests.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Tests/IL/ILTests.cs @@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.Tests var assembly = AssemblyDefinition.ReadAssembly(Path.Combine(path, compiledFile)); AstBuilder decompiler = new AstBuilder(new DecompilerContext(assembly.MainModule)); decompiler.AddAssembly(assembly); - new Helpers.RemoveCompilerAttribute().Run(decompiler.CompilationUnit); + new Helpers.RemoveCompilerAttribute().Run(decompiler.SyntaxTree); StringWriter output = new StringWriter(); decompiler.GenerateCode(new PlainTextOutput(output)); CodeAssert.AreEqual(expectedOutput, output.ToString()); diff --git a/src/Libraries/ICSharpCode.Decompiler/Tests/TestRunner.cs b/src/Libraries/ICSharpCode.Decompiler/Tests/TestRunner.cs index 52a03a4623..009a3c6c17 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Tests/TestRunner.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Tests/TestRunner.cs @@ -184,7 +184,7 @@ namespace ICSharpCode.Decompiler.Tests AssemblyDefinition assembly = Compile(code, optimize, useDebug); AstBuilder decompiler = new AstBuilder(new DecompilerContext(assembly.MainModule)); decompiler.AddAssembly(assembly); - new Helpers.RemoveCompilerAttribute().Run(decompiler.CompilationUnit); + new Helpers.RemoveCompilerAttribute().Run(decompiler.SyntaxTree); StringWriter output = new StringWriter(); decompiler.GenerateCode(new PlainTextOutput(output)); CodeAssert.AreEqual(code, output.ToString()); diff --git a/src/Libraries/ICSharpCode.Decompiler/Tests/UnsafeCode.cs b/src/Libraries/ICSharpCode.Decompiler/Tests/UnsafeCode.cs index 198f0fc978..66fb29529b 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Tests/UnsafeCode.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Tests/UnsafeCode.cs @@ -33,6 +33,21 @@ public class UnsafeCode return *(long*)(&d); } + public unsafe double ConvertLongToDouble(long d) + { + return *(double*)(&d); + } + + public unsafe int ConvertFloatToInt(float d) + { + return *(int*)(&d); + } + + public unsafe float ConvertIntToFloat(int d) + { + return *(float*)(&d); + } + public unsafe void PassRefParameterAsPointer(ref int p) { fixed (int* ptr = &p) @@ -48,7 +63,8 @@ public class UnsafeCode public unsafe void AddressInMultiDimensionalArray(double[,] matrix) { - fixed (double* ptr = &matrix[1, 2]) { + fixed (double* ptr = &matrix[1, 2]) + { this.PointerReferenceExpression(ptr); } } @@ -58,7 +74,7 @@ public class UnsafeCode fixed (char* ptr = text) { char* ptr2 = ptr; - while (*ptr2 != 0) + while (*ptr2 != '\0') { *ptr2 = 'A'; ptr2++; @@ -68,7 +84,7 @@ public class UnsafeCode public unsafe void PutDoubleIntoLongArray1(long[] array, int index, double val) { - fixed (long* ptr = array) + fixed (long* ptr = array) { ((double*)ptr)[index] = val; } @@ -76,7 +92,7 @@ public class UnsafeCode public unsafe void PutDoubleIntoLongArray2(long[] array, int index, double val) { - fixed (long* ptr = &array[index]) + fixed (long* ptr = &array[index]) { *(double*)ptr = val; } @@ -89,7 +105,7 @@ public class UnsafeCode public unsafe void FixMultipleStrings(string text) { - fixed (char* ptr = text, userName = Environment.UserName, ptr2 = text) + fixed (char* ptr = text, userName = Environment.UserName, ptr2 = text) { *ptr = 'c'; *userName = 'd'; @@ -100,7 +116,7 @@ public class UnsafeCode public unsafe string StackAlloc(int count) { char* ptr = stackalloc char[count]; - for (int i = 0; i < count; i++) + for (int i = 0; i < count; i++) { ptr[i] = (char)i; } diff --git a/src/Libraries/ICSharpCode.Decompiler/Tests/ValueTypes.cs b/src/Libraries/ICSharpCode.Decompiler/Tests/ValueTypes.cs index 84997e5a22..b3aa644786 100644 --- a/src/Libraries/ICSharpCode.Decompiler/Tests/ValueTypes.cs +++ b/src/Libraries/ICSharpCode.Decompiler/Tests/ValueTypes.cs @@ -160,4 +160,12 @@ public static class ValueTypes s.SetField(); return p; } + + public static void UseRefBoolInCondition(ref bool x) + { + if (x) + { + Console.WriteLine("true"); + } + } } diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index 4c03beed26..6f67944f06 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -112,6 +112,7 @@ + @@ -740,6 +741,7 @@ + diff --git a/src/Main/Base/Project/Src/Bookmarks/IBookmarkMargin.cs b/src/Main/Base/Project/Src/Bookmarks/IBookmarkMargin.cs index 4d0ead5521..3ced002f5a 100644 --- a/src/Main/Base/Project/Src/Bookmarks/IBookmarkMargin.cs +++ b/src/Main/Base/Project/Src/Bookmarks/IBookmarkMargin.cs @@ -5,11 +5,14 @@ using System; using System.Collections.Generic; using System.Windows.Input; +using ICSharpCode.SharpDevelop.Editor; + namespace ICSharpCode.SharpDevelop.Bookmarks { /// /// The bookmark margin. /// + [DocumentService] public interface IBookmarkMargin { /// diff --git a/src/Main/Base/Project/Src/Editor/DocumentServiceAttribute.cs b/src/Main/Base/Project/Src/Editor/DocumentServiceAttribute.cs new file mode 100644 index 0000000000..e7d0e3e5ba --- /dev/null +++ b/src/Main/Base/Project/Src/Editor/DocumentServiceAttribute.cs @@ -0,0 +1,30 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.SharpDevelop.Editor +{ + /// + /// Specifies that the given interface is a service that can be retrieved using an or + /// an as service provider. + /// + /// + /// This attribute is intended to be used as documentation, it does not have any effect at runtime. + /// + [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class)] + public class DocumentServiceAttribute : Attribute + { + } + + /// + /// Specifies that the given interface is a service that can be retrieved using an as service provider. + /// + /// + /// This attribute is intended to be used as documentation, it does not have any effect at runtime. + /// + [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class)] + public class TextEditorServiceAttribute : Attribute + { + } +} diff --git a/src/Main/Base/Project/Src/Editor/IEditorUIService.cs b/src/Main/Base/Project/Src/Editor/IEditorUIService.cs index 4c801e970a..4bc521dd35 100644 --- a/src/Main/Base/Project/Src/Editor/IEditorUIService.cs +++ b/src/Main/Base/Project/Src/Editor/IEditorUIService.cs @@ -8,6 +8,7 @@ using ICSharpCode.NRefactory.Editor; namespace ICSharpCode.SharpDevelop.Editor { + [TextEditorService] public interface IEditorUIService { IInlineUIElement CreateInlineUIElement(ITextAnchor position, UIElement element); diff --git a/src/Main/Base/Project/Src/Editor/ISyntaxHighlighter.cs b/src/Main/Base/Project/Src/Editor/ISyntaxHighlighter.cs index b64c0f77b7..5db5eb5d6a 100644 --- a/src/Main/Base/Project/Src/Editor/ISyntaxHighlighter.cs +++ b/src/Main/Base/Project/Src/Editor/ISyntaxHighlighter.cs @@ -12,6 +12,7 @@ namespace ICSharpCode.SharpDevelop.Editor /// /// Represents the syntax highlighter inside the text editor. /// + [TextEditorService] public interface ISyntaxHighlighter { /// diff --git a/src/Main/Base/Project/Src/Editor/ITextMarker.cs b/src/Main/Base/Project/Src/Editor/ITextMarker.cs index 5f308934b6..84211a76d6 100644 --- a/src/Main/Base/Project/Src/Editor/ITextMarker.cs +++ b/src/Main/Base/Project/Src/Editor/ITextMarker.cs @@ -107,6 +107,7 @@ namespace ICSharpCode.SharpDevelop.Editor CircleInScrollBar = 0x1000 } + [DocumentService] public interface ITextMarkerService { /// diff --git a/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs b/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs index 121abe3c91..fca78b0f74 100644 --- a/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs +++ b/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs @@ -577,20 +577,25 @@ namespace ICSharpCode.SharpDevelop.Gui #endregion #region IServiceProvider - ServiceContainer services = new ServiceContainer(); + IServiceContainer services = new ServiceContainer(); public object GetService(Type serviceType) { object obj = services.GetService(serviceType); - if (obj == null) { - if (serviceType.IsInstanceOfType(this)) - return this; - } - return obj; + if (obj != null) + return obj; + if (serviceType.IsInstanceOfType(this)) + return this; + return null; } - public ServiceContainer Services { + public IServiceContainer Services { get { return services; } + protected set { + if (value == null) + throw new ArgumentNullException(); + services = value; + } } #endregion diff --git a/src/Main/Base/Project/Src/Gui/Pads/OutlinePad.cs b/src/Main/Base/Project/Src/Gui/Pads/OutlinePad.cs index 7d0fa08191..89db816fda 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/OutlinePad.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/OutlinePad.cs @@ -11,6 +11,7 @@ namespace ICSharpCode.SharpDevelop.Gui /// /// Implement this interface to make a view content display tools in the outline pad. /// + [ViewContentService] public interface IOutlineContentHost { /// @@ -41,17 +42,8 @@ namespace ICSharpCode.SharpDevelop.Gui void WorkbenchActiveContentChanged(object sender, EventArgs e) { IViewContent view = WorkbenchSingleton.Workbench.ActiveViewContent; - if(view!=null){ + if (view!=null) { IOutlineContentHost content = view.GetService(typeof(IOutlineContentHost)) as IOutlineContentHost; - if(content!=null){ - contentControl.SetContent(content.OutlineContent, content); - return ; - } - } - - ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider; - if (provider != null) { - IOutlineContentHost content = provider.TextEditor.GetService(typeof(IOutlineContentHost)) as IOutlineContentHost; if (content != null) { contentControl.SetContent(content.OutlineContent, content); return; diff --git a/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs b/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs index 2d3d3f15a8..c257069339 100644 --- a/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs +++ b/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs @@ -313,6 +313,7 @@ namespace ICSharpCode.SharpDevelop.Debugging /// /// Interface for common debugger-decompiler mapping operations. /// + [SDService] public interface IDebuggerDecompilerService { /// diff --git a/src/Main/Base/Project/Src/Services/NavigationService/NavigationService.cs b/src/Main/Base/Project/Src/Services/NavigationService/NavigationService.cs index ee6ffe6688..548b1daff1 100644 --- a/src/Main/Base/Project/Src/Services/NavigationService/NavigationService.cs +++ b/src/Main/Base/Project/Src/Services/NavigationService/NavigationService.cs @@ -468,7 +468,7 @@ namespace ICSharpCode.SharpDevelop #endregion #region Navigate to Member - + /* Part of Eusebiu's debugger/decompiler implementation public static bool NavigateTo(string assemblyFile, string typeName, string entityTag, int lineNumber = 0, bool updateMarker = true) { if (string.IsNullOrEmpty(assemblyFile)) @@ -483,7 +483,7 @@ namespace ICSharpCode.SharpDevelop } return false; } - + */ #endregion } @@ -497,7 +497,7 @@ namespace ICSharpCode.SharpDevelop { bool NavigateToEntity(IEntity entity); } - + /* Part of Eusebiu's debugger/decompiler implementation /// /// Called by when the member reference is not defined in source code. /// @@ -508,4 +508,5 @@ namespace ICSharpCode.SharpDevelop { bool NavigateToMember(string assemblyFile, string typeName, string entityTag, int lineNumber, bool updateMarker); } + */ } diff --git a/src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs b/src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs index a339537725..65d77630c7 100644 --- a/src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs +++ b/src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs @@ -154,7 +154,7 @@ namespace ICSharpCode.SharpDevelop.Parser try { using (FileStream fs = new FileStream(cacheFileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete, 4096, FileOptions.SequentialScan)) { using (BinaryReader reader = new BinaryReaderWith7BitEncodedInts(fs)) { - if (reader.ReadByte() != cacheMagicNumber) { + if (reader.ReadInt32() != cacheMagicNumber) { LoggingService.Warn("Incorrect magic number"); return null; } diff --git a/src/Main/Base/Project/Src/Services/ViewContentServiceAttribute.cs b/src/Main/Base/Project/Src/Services/ViewContentServiceAttribute.cs new file mode 100644 index 0000000000..d7e6d6f7c4 --- /dev/null +++ b/src/Main/Base/Project/Src/Services/ViewContentServiceAttribute.cs @@ -0,0 +1,18 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.SharpDevelop +{ + /// + /// Specifies that the given interface is a service that can be retrieved using an as service provider. + /// + /// + /// This attribute is intended to be used as documentation, it does not have any effect at runtime. + /// + [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class)] + public class ViewContentServiceAttribute : Attribute + { + } +} diff --git a/src/Main/Base/Project/Src/Util/ExtensionMethods.cs b/src/Main/Base/Project/Src/Util/ExtensionMethods.cs index 0df56d8452..432a2d3a8b 100644 --- a/src/Main/Base/Project/Src/Util/ExtensionMethods.cs +++ b/src/Main/Base/Project/Src/Util/ExtensionMethods.cs @@ -15,6 +15,7 @@ using System.Windows.Forms; using System.Windows.Media; using System.Xml; using System.Xml.Linq; +using ICSharpCode.Core; using ICSharpCode.Core.Presentation; using ICSharpCode.NRefactory; using ICSharpCode.NRefactory.Editor; @@ -182,6 +183,27 @@ namespace ICSharpCode.SharpDevelop return snapshot.GetProject(assembly.UnresolvedAssembly as IProjectContent); } + /// + /// Gets the location of the assembly on disk. + /// + public static FileName GetReferenceAssemblyLocation(this IAssembly assembly) + { + return FileName.Create(assembly.UnresolvedAssembly.Location); + } + + /// + /// Gets the location of the assembly on disk. + /// If the specified assembly is a reference assembly, this method the location of the actual runtime assembly instead. + /// + /// + /// May return null if the assembly has no location. + /// + public static FileName GetRuntimeAssemblyLocation(this IAssembly assembly) + { + #warning Find and use GAC assembly if possible + return FileName.Create(assembly.UnresolvedAssembly.Location); + } + /// /// Creates an array containing a part of the array (similar to string.Substring). ///