// // GenericFix.cs // // Author: // Mike Krüger // // Copyright (c) 2011 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; using System.Collections.Generic; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.CSharp; using MonoDevelop.CodeIssues; using MonoDevelop.Ide; using Mono.TextEditor; using ICSharpCode.NRefactory.Refactoring; namespace MonoDevelop.AnalysisCore.Fixes { public class InspectorResults : GenericResults { public BaseCodeIssueProvider Inspector { get; private set; } public InspectorResults (BaseCodeIssueProvider inspector, DomRegion region, string message, Severity level, IssueMarker mark, params GenericFix[] fixes) : base (region, message, level, mark, fixes) { this.Inspector = inspector; } public override bool HasOptionsDialog { get { return true; } } public override string OptionsTitle { get { return GetTitle (Inspector); } } public override void ShowResultOptionsDialog () { IdeApp.Workbench.ShowGlobalPreferencesDialog (null, "C#", dialog => { var panel = dialog.GetPanel ("C#"); if (panel == null) return; panel.Widget.SelectCodeIssue (Inspector.IdString); }); } public static string GetTitle (BaseCodeIssueProvider inspector) { if (inspector.Parent == null) return inspector.Title; return inspector.Parent.Title + " -> " + inspector.Title; } } public class GenericResults : FixableResult { public GenericResults (DomRegion region, string message, Severity level, IssueMarker mark, params GenericFix[] fixes) : base (region, message, level, mark) { this.Fixes = fixes; } } public class GenericFix : IAnalysisFix, IAnalysisFixAction { Action fix; Action batchFix; string label; public DocumentRegion DocumentRegion { get; set; } public string IdString { get; set; } public GenericFix (string label, Action fix, Action batchFix = null) { this.batchFix = batchFix; this.fix = fix; this.label = label; } #region IAnalysisFix implementation public string FixType { get { return "Generic"; } } #endregion #region IAnalysisFixAction implementation public void Fix () { fix (); } public bool SupportsBatchFix { get { return batchFix != null; } } public void BatchFix () { if (!SupportsBatchFix) { throw new InvalidOperationException ("Batch fixing is not supported."); } batchFix (); } public string Label { get { return label; } } #endregion } public class GenericFixHandler : IFixHandler { #region IFixHandler implementation public IEnumerable GetFixes (MonoDevelop.Ide.Gui.Document doc, object fix) { yield return (GenericFix)fix; } #endregion } }