From 82190a1d2a0c05b26414ca63eec044728be521eb Mon Sep 17 00:00:00 2001 From: Matthias Koch Date: Fri, 7 Apr 2017 08:41:59 +0200 Subject: [PATCH 1/3] TBR: Add ObservableObject as base class. --- .../CodeCleanup/StyleCopDescriptor.cs | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs b/src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs index ecf4909..c45db2b 100644 --- a/src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs +++ b/src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs @@ -15,6 +15,7 @@ namespace StyleCop.ReSharper.CodeCleanup using System.Text; using System.Xml; + using JetBrains.ReSharper.Daemon.CSharp.CodeCleanup; using JetBrains.ReSharper.Feature.Services.CodeCleanup; using JetBrains.Util; @@ -89,19 +90,42 @@ public override StyleCopCodeCleanupOptions Load(XmlElement element) /// /// Options for code cleanup /// - public class StyleCopCodeCleanupOptions + public class StyleCopCodeCleanupOptions : ObservableObject { + private bool fixViolations; + private bool createXmlDocStubs; + /// /// Option to fix StyleCop violations /// [DisplayName("Fix StyleCop violations")] - public bool FixViolations { get; set; } + public bool FixViolations + { + get + { + return this.fixViolations; + } + set + { + this.SetField(ref this.fixViolations, value); + } + } /// /// Options to generate XML doc stubs /// [DisplayName("Create XML doc stubs")] - public bool CreateXmlDocStubs { get; set; } + public bool CreateXmlDocStubs + { + get + { + return this.createXmlDocStubs; + } + set + { + this.SetField(ref this.createXmlDocStubs, value); + } + } /// /// Initializes a new instance of the class. From 6c64c5e94f8fcaa0b8d4a5c1628f73115429c57a Mon Sep 17 00:00:00 2001 From: Matthias Koch Date: Fri, 7 Apr 2017 09:11:58 +0200 Subject: [PATCH 2/3] Fix code cleanup options. (flattened) --- .../CodeCleanup/StyleCopCodeCleanupModule.cs | 13 +- .../CodeCleanup/StyleCopDescriptor.cs | 252 ++++++++++-------- .../Options/CodeStyleOptions.cs | 8 +- 3 files changed, 149 insertions(+), 124 deletions(-) diff --git a/src/StyleCop.ReSharper/CodeCleanup/StyleCopCodeCleanupModule.cs b/src/StyleCop.ReSharper/CodeCleanup/StyleCopCodeCleanupModule.cs index b391dc2..14299a5 100644 --- a/src/StyleCop.ReSharper/CodeCleanup/StyleCopCodeCleanupModule.cs +++ b/src/StyleCop.ReSharper/CodeCleanup/StyleCopCodeCleanupModule.cs @@ -47,7 +47,8 @@ public class StyleCopCodeCleanupModule : ICodeCleanupModule /// /// StyleCop descriptor. /// - public static readonly StyleCopDescriptor Descriptor = new StyleCopDescriptor(); + public static readonly FixViolationsDescriptor FIX_VIOLATIONS = new FixViolationsDescriptor(); + public static readonly CreateXmlDocStubsDescriptor CREATE_XML_DOC_STUB = new CreateXmlDocStubsDescriptor (); /// /// Gets the collection of option descriptors. @@ -59,7 +60,7 @@ public ICollection Descriptors { get { - return new CodeCleanupOptionDescriptor[] { Descriptor }; + return new CodeCleanupOptionDescriptor[] { FIX_VIOLATIONS, CREATE_XML_DOC_STUB }; } } @@ -138,15 +139,14 @@ public void Process( return; } - StyleCopCodeCleanupOptions options = profile.GetSetting(Descriptor); - if (!options.FixViolations) + if (!profile.GetSetting (FIX_VIOLATIONS)) { return; } var services = solution.GetPsiServices(); - services.Transactions.Execute("Code cleanup", () => this.InternalProcess(projectFile.ToProjectFile(), file, options.CreateXmlDocStubs)); + services.Transactions.Execute("Code cleanup", () => this.InternalProcess(projectFile.ToProjectFile(), file, profile.GetSetting(CREATE_XML_DOC_STUB))); StyleCopTrace.Out(); } @@ -162,7 +162,8 @@ public void Process( /// public void SetDefaultSetting(CodeCleanupProfile profile, CodeCleanup.DefaultProfileType profileType) { - profile.SetSetting(Descriptor, new StyleCopCodeCleanupOptions()); + profile.SetSetting(FIX_VIOLATIONS, value: true); + profile.SetSetting(CREATE_XML_DOC_STUB, value: false); } /// diff --git a/src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs b/src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs index c45db2b..cfe7548 100644 --- a/src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs +++ b/src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs @@ -19,133 +19,155 @@ namespace StyleCop.ReSharper.CodeCleanup using JetBrains.ReSharper.Feature.Services.CodeCleanup; using JetBrains.Util; - /// - /// The style cop descriptor. - /// - [DisplayName("Fix StyleCop violations")] - [Category(CSharpCategory)] - [TypeConverter(typeof(ExpandableObjectConverter))] - public class StyleCopDescriptor : CodeCleanupOptionDescriptor + [Category (CSharpCategory)] + [DisplayName ("Fix StyleCop violations")] + [DefaultValue (true)] + public class FixViolationsDescriptor : CodeCleanupBoolOptionDescriptor { - /// - /// Initializes a new instance of the class. - /// - public StyleCopDescriptor() - : base("StyleCop") + public FixViolationsDescriptor () + : base ("FixViolations") { } + } - /// - /// Summarize the options for the Code Cleanup dialog - /// - /// - /// The selected profile - /// - /// - /// A string that summarizes the options - /// - public override string Present(CodeCleanupProfile profile) + [Category (CSharpCategory)] + [DisplayName ("Create XML doc stubs")] + [DefaultValue (false)] + public class CreateXmlDocStubsDescriptor : CodeCleanupBoolOptionDescriptor + { + public CreateXmlDocStubsDescriptor () + : base ("CreateXmlDocStubs") { - return profile.GetSetting(this).ToString(); } + } - /// - /// Save the options - /// - /// - /// The parent XML element to add the options to - /// - /// - /// The options to save - /// - public override void Save(XmlElement element, StyleCopCodeCleanupOptions value) - { - element.CreateLeafElementWithValue( - "FixViolations", - value.FixViolations.ToString(CultureInfo.InvariantCulture)); - element.CreateLeafElementWithValue( - "CreateXmlDocStubs", - value.CreateXmlDocStubs.ToString(CultureInfo.InvariantCulture)); - } + ///// + ///// The style cop descriptor. + ///// + //[DisplayName("Fix StyleCop violations")] + //[Category(CSharpCategory)] + //[TypeConverter(typeof(ExpandableObjectConverter))] + //public class StyleCopDescriptor : CodeCleanupOptionDescriptor + //{ + // /// + // /// Initializes a new instance of the class. + // /// + // public StyleCopDescriptor() + // : base("StyleCop") + // { + // } - /// - /// Load the options - /// - /// - /// The parent XML element - /// - /// - /// A loaded instance of the options - /// - public override StyleCopCodeCleanupOptions Load(XmlElement element) - { - return new StyleCopCodeCleanupOptions - { - FixViolations = bool.Parse(XmlUtil.ReadLeafElementValue(element, "FixViolations")), - CreateXmlDocStubs = bool.Parse(XmlUtil.ReadLeafElementValue(element, "CreateXmlDocStubs")) - }; - } - } + // /// + // /// Summarize the options for the Code Cleanup dialog + // /// + // /// + // /// The selected profile + // /// + // /// + // /// A string that summarizes the options + // /// + // public override string Present(CodeCleanupProfile profile) + // { + // return profile.GetSetting(this).ToString(); + // } - /// - /// Options for code cleanup - /// - public class StyleCopCodeCleanupOptions : ObservableObject - { - private bool fixViolations; - private bool createXmlDocStubs; + // /// + // /// Save the options + // /// + // /// + // /// The parent XML element to add the options to + // /// + // /// + // /// The options to save + // /// + // public override void Save(XmlElement element, StyleCopCodeCleanupOptions value) + // { + // element.CreateLeafElementWithValue( + // "FixViolations", + // value.FixViolations.ToString(CultureInfo.InvariantCulture)); + // element.CreateLeafElementWithValue( + // "CreateXmlDocStubs", + // value.CreateXmlDocStubs.ToString(CultureInfo.InvariantCulture)); + // } - /// - /// Option to fix StyleCop violations - /// - [DisplayName("Fix StyleCop violations")] - public bool FixViolations - { - get - { - return this.fixViolations; - } - set - { - this.SetField(ref this.fixViolations, value); - } - } + // /// + // /// Load the options + // /// + // /// + // /// The parent XML element + // /// + // /// + // /// A loaded instance of the options + // /// + // public override StyleCopCodeCleanupOptions Load(XmlElement element) + // { + // return new StyleCopCodeCleanupOptions + // { + // FixViolations = bool.Parse(XmlUtil.ReadLeafElementValue(element, "FixViolations")), + // CreateXmlDocStubs = bool.Parse(XmlUtil.ReadLeafElementValue(element, "CreateXmlDocStubs")) + // }; + // } + //} - /// - /// Options to generate XML doc stubs - /// - [DisplayName("Create XML doc stubs")] - public bool CreateXmlDocStubs - { - get - { - return this.createXmlDocStubs; - } - set - { - this.SetField(ref this.createXmlDocStubs, value); - } - } + ///// + ///// Options for code cleanup + ///// + //public class StyleCopCodeCleanupOptions : ObservableObject + //{ + // private bool fixViolations; + // private bool createXmlDocStubs; - /// - /// Initializes a new instance of the class. - /// - public StyleCopCodeCleanupOptions() - { - this.FixViolations = true; + // /// + // /// Option to fix StyleCop violations + // /// + // [DisplayName("Fix StyleCop violations")] + // public bool FixViolations + // { + // get + // { + // return this.fixViolations; + // } + // set + // { + // this.SetField(ref this.fixViolations, value); + // } + // } - // TODO: What's the best default? - // I like the argument that we shouldn't blindly create XML docs, but set - // them properly, but it's nice to be able to fix up everything we can... - this.CreateXmlDocStubs = false; - } + // /// + // /// Options to generate XML doc stubs + // /// + // [DisplayName("Create XML doc stubs")] + // public bool CreateXmlDocStubs + // { + // get + // { + // return this.createXmlDocStubs; + // } + // set + // { + // this.SetField(ref this.createXmlDocStubs, value); + // } + // } - public override string ToString() - { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.Append(this.FixViolations ? "Yes" : "No"); - stringBuilder.Append(this.CreateXmlDocStubs ? " (create XML doc stubs)" : " (do not create XML doc stubs)"); - return stringBuilder.ToString(); - } - } + // /// + // /// Initializes a new instance of the class. + // /// + // public StyleCopCodeCleanupOptions() + // { + // this.FixViolations = true; + + // // TODO: What's the best default? + // // I like the argument that we shouldn't blindly create XML docs, but set + // // them properly, but it's nice to be able to fix up everything we can... + // this.CreateXmlDocStubs = false; + // } + + // public override string ToString() + // { + // StringBuilder stringBuilder = new StringBuilder(); + // stringBuilder.Append(this.FixViolations ? "Yes" : "No"); + // stringBuilder.Append(this.CreateXmlDocStubs ? " (create XML doc stubs)" : " (do not create XML doc stubs)"); + // return stringBuilder.ToString(); + // } + //} } \ No newline at end of file diff --git a/src/StyleCop.ReSharper/Options/CodeStyleOptions.cs b/src/StyleCop.ReSharper/Options/CodeStyleOptions.cs index ee8e59a..4baf79d 100644 --- a/src/StyleCop.ReSharper/Options/CodeStyleOptions.cs +++ b/src/StyleCop.ReSharper/Options/CodeStyleOptions.cs @@ -341,7 +341,8 @@ public static void CodeStyleOptionsReset(IContextBoundSettingsStore settingsStor SetCodeCleanupProfileSetting(styleCopProfile, "CSReorderTypeMembers", null, true); - styleCopProfile.SetSetting(StyleCopCodeCleanupModule.Descriptor, new StyleCopCodeCleanupOptions()); + styleCopProfile.SetSetting(StyleCopCodeCleanupModule.FIX_VIOLATIONS, value: true); + styleCopProfile.SetSetting(StyleCopCodeCleanupModule.CREATE_XML_DOC_STUB, value: false); codeCleanupSettings.SetProfiles(profiles, settingsStore); codeCleanupSettings.SetSilentCleanupProfileName(settingsStore, styleCopProfile.Name); @@ -1406,8 +1407,9 @@ public static bool CodeStyleOptionsValid(IContextBoundSettingsStore settingsStor return false; } - StyleCopCodeCleanupOptions options = styleCopProfile.GetSetting(StyleCopCodeCleanupModule.Descriptor); - if (!options.FixViolations || options.CreateXmlDocStubs) + var fixViolations = styleCopProfile.GetSetting(StyleCopCodeCleanupModule.FIX_VIOLATIONS); + var createXmlDocStubs = styleCopProfile.GetSetting (StyleCopCodeCleanupModule.CREATE_XML_DOC_STUB); + if (!fixViolations || createXmlDocStubs) { return false; } From 9487c3947797d2afb14ad4a7bd92051706c1a9e2 Mon Sep 17 00:00:00 2001 From: Matthias Koch Date: Fri, 7 Apr 2017 09:23:27 +0200 Subject: [PATCH 3/3] Remove commented code / old descriptor. --- .../CodeCleanup/StyleCopDescriptor.cs | 135 ------------------ 1 file changed, 135 deletions(-) diff --git a/src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs b/src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs index cfe7548..b81c9ef 100644 --- a/src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs +++ b/src/StyleCop.ReSharper/CodeCleanup/StyleCopDescriptor.cs @@ -11,13 +11,8 @@ namespace StyleCop.ReSharper.CodeCleanup { using System; using System.ComponentModel; - using System.Globalization; - using System.Text; - using System.Xml; - using JetBrains.ReSharper.Daemon.CSharp.CodeCleanup; using JetBrains.ReSharper.Feature.Services.CodeCleanup; - using JetBrains.Util; [Category (CSharpCategory)] [DisplayName ("Fix StyleCop violations")] @@ -40,134 +35,4 @@ public CreateXmlDocStubsDescriptor () { } } - - ///// - ///// The style cop descriptor. - ///// - //[DisplayName("Fix StyleCop violations")] - //[Category(CSharpCategory)] - //[TypeConverter(typeof(ExpandableObjectConverter))] - //public class StyleCopDescriptor : CodeCleanupOptionDescriptor - //{ - // /// - // /// Initializes a new instance of the class. - // /// - // public StyleCopDescriptor() - // : base("StyleCop") - // { - // } - - // /// - // /// Summarize the options for the Code Cleanup dialog - // /// - // /// - // /// The selected profile - // /// - // /// - // /// A string that summarizes the options - // /// - // public override string Present(CodeCleanupProfile profile) - // { - // return profile.GetSetting(this).ToString(); - // } - - // /// - // /// Save the options - // /// - // /// - // /// The parent XML element to add the options to - // /// - // /// - // /// The options to save - // /// - // public override void Save(XmlElement element, StyleCopCodeCleanupOptions value) - // { - // element.CreateLeafElementWithValue( - // "FixViolations", - // value.FixViolations.ToString(CultureInfo.InvariantCulture)); - // element.CreateLeafElementWithValue( - // "CreateXmlDocStubs", - // value.CreateXmlDocStubs.ToString(CultureInfo.InvariantCulture)); - // } - - // /// - // /// Load the options - // /// - // /// - // /// The parent XML element - // /// - // /// - // /// A loaded instance of the options - // /// - // public override StyleCopCodeCleanupOptions Load(XmlElement element) - // { - // return new StyleCopCodeCleanupOptions - // { - // FixViolations = bool.Parse(XmlUtil.ReadLeafElementValue(element, "FixViolations")), - // CreateXmlDocStubs = bool.Parse(XmlUtil.ReadLeafElementValue(element, "CreateXmlDocStubs")) - // }; - // } - //} - - ///// - ///// Options for code cleanup - ///// - //public class StyleCopCodeCleanupOptions : ObservableObject - //{ - // private bool fixViolations; - // private bool createXmlDocStubs; - - // /// - // /// Option to fix StyleCop violations - // /// - // [DisplayName("Fix StyleCop violations")] - // public bool FixViolations - // { - // get - // { - // return this.fixViolations; - // } - // set - // { - // this.SetField(ref this.fixViolations, value); - // } - // } - - // /// - // /// Options to generate XML doc stubs - // /// - // [DisplayName("Create XML doc stubs")] - // public bool CreateXmlDocStubs - // { - // get - // { - // return this.createXmlDocStubs; - // } - // set - // { - // this.SetField(ref this.createXmlDocStubs, value); - // } - // } - - // /// - // /// Initializes a new instance of the class. - // /// - // public StyleCopCodeCleanupOptions() - // { - // this.FixViolations = true; - - // // TODO: What's the best default? - // // I like the argument that we shouldn't blindly create XML docs, but set - // // them properly, but it's nice to be able to fix up everything we can... - // this.CreateXmlDocStubs = false; - // } - - // public override string ToString() - // { - // StringBuilder stringBuilder = new StringBuilder(); - // stringBuilder.Append(this.FixViolations ? "Yes" : "No"); - // stringBuilder.Append(this.CreateXmlDocStubs ? " (create XML doc stubs)" : " (do not create XML doc stubs)"); - // return stringBuilder.ToString(); - // } - //} } \ No newline at end of file