Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming')
-rw-r--r--main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/MonoNameConventionPolicy.xml179
-rw-r--r--main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionEditRuleDialog.cs211
-rw-r--r--main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionPanel.cs73
-rw-r--r--main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionPanelWidget.cs154
-rw-r--r--main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionPolicy.cs96
-rw-r--r--main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionRule.cs132
6 files changed, 845 insertions, 0 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/MonoNameConventionPolicy.xml b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/MonoNameConventionPolicy.xml
new file mode 100644
index 0000000000..4643473284
--- /dev/null
+++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/MonoNameConventionPolicy.xml
@@ -0,0 +1,179 @@
+<NameConventionPolicy>
+ <Rules>
+ <NamingRule>
+ <Name>Namespaces</Name>
+ <AffectedEntity>Namespace</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Types</Name>
+ <AffectedEntity>Class, Struct, Enum, Delegate</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Interfaces</Name>
+ <RequiredPrefixes>
+ <String>I</String>
+ </RequiredPrefixes>
+ <AffectedEntity>Interface</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Attributes</Name>
+ <RequiredSuffixes>
+ <String>Attribute</String>
+ </RequiredSuffixes>
+ <AffectedEntity>CustomAttributes</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Event Arguments</Name>
+ <RequiredSuffixes>
+ <String>EventArgs</String>
+ </RequiredSuffixes>
+ <AffectedEntity>CustomEventArgs</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Exceptions</Name>
+ <RequiredSuffixes>
+ <String>Exception</String>
+ </RequiredSuffixes>
+ <AffectedEntity>CustomExceptions</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Methods</Name>
+ <AffectedEntity>Methods</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Static Readonly Fields</Name>
+ <AffectedEntity>ReadonlyField</AffectedEntity>
+ <VisibilityMask>Internal, Protected, Public</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>False</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Fields (Non Private)</Name>
+ <AffectedEntity>Field</AffectedEntity>
+ <VisibilityMask>Internal, Protected, Public</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>ReadOnly Fields (Non Private)</Name>
+ <AffectedEntity>ReadonlyField</AffectedEntity>
+ <VisibilityMask>Internal, Protected, Public</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>False</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Fields (Private)</Name>
+ <AllowedPrefixes>
+ <String>_</String>
+ <String>m_</String>
+ </AllowedPrefixes>
+ <AffectedEntity>Field, ReadonlyField</AffectedEntity>
+ <VisibilityMask>Private</VisibilityMask>
+ <NamingStyle>CamelCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>False</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Static Fields (Private)</Name>
+ <AffectedEntity>Field</AffectedEntity>
+ <VisibilityMask>Private</VisibilityMask>
+ <NamingStyle>CamelCase</NamingStyle>
+ <IncludeInstanceMembers>False</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>ReadOnly Fields (Private)</Name>
+ <AllowedPrefixes>
+ <String>_</String>
+ <String>m_</String>
+ </AllowedPrefixes>
+ <AffectedEntity>ReadonlyField</AffectedEntity>
+ <VisibilityMask>Private</VisibilityMask>
+ <NamingStyle>CamelCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>False</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Constant Fields</Name>
+ <AffectedEntity>ConstantField</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Properties</Name>
+ <AffectedEntity>Property</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Events</Name>
+ <AffectedEntity>Event</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Enum Members</Name>
+ <AffectedEntity>EnumMember</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Parameters</Name>
+ <AffectedEntity>Parameter</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>CamelCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ <NamingRule>
+ <Name>Type Parameters</Name>
+ <RequiredPrefixes>
+ <String>T</String>
+ </RequiredPrefixes>
+ <AffectedEntity>TypeParameter</AffectedEntity>
+ <VisibilityMask>VisibilityMask</VisibilityMask>
+ <NamingStyle>PascalCase</NamingStyle>
+ <IncludeInstanceMembers>True</IncludeInstanceMembers>
+ <IncludeStaticEntities>True</IncludeStaticEntities>
+ </NamingRule>
+ </Rules>
+</NameConventionPolicy> \ No newline at end of file
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionEditRuleDialog.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionEditRuleDialog.cs
new file mode 100644
index 0000000000..3c64d104fa
--- /dev/null
+++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionEditRuleDialog.cs
@@ -0,0 +1,211 @@
+//
+// NamingConventionEditRuleDialog.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2012 Xamarin Inc. (http://xamarin.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.Linq;
+using Gtk;
+using System.Collections.Generic;
+using MonoDevelop.Core;
+using ICSharpCode.NRefactory6.CSharp.Diagnostics;
+
+namespace MonoDevelop.CSharp.Diagnostics.InconsistentNaming
+{
+ partial class NameConventionEditRuleDialog : Gtk.Dialog
+ {
+ static readonly Dictionary<AffectedEntity, string> EntityName = new Dictionary<AffectedEntity, string> ();
+ static readonly Dictionary<Modifiers, string> AccessibilityName = new Dictionary<Modifiers, string> ();
+
+ static NameConventionEditRuleDialog ()
+ {
+ EntityName [AffectedEntity.Namespace] = GettextCatalog.GetString ("Namespaces");
+
+ EntityName [AffectedEntity.Class] = GettextCatalog.GetString ("Classes");
+ EntityName [AffectedEntity.Struct] = GettextCatalog.GetString ("Structs");
+ EntityName [AffectedEntity.Enum] = GettextCatalog.GetString ("Enums");
+ EntityName [AffectedEntity.Interface] = GettextCatalog.GetString ("Interfaces");
+ EntityName [AffectedEntity.Delegate] = GettextCatalog.GetString ("Delegates");
+
+ EntityName [AffectedEntity.CustomAttributes] = GettextCatalog.GetString ("Attributes");
+ EntityName [AffectedEntity.CustomEventArgs] = GettextCatalog.GetString ("Event Arguments");
+ EntityName [AffectedEntity.CustomExceptions] = GettextCatalog.GetString ("Exceptions");
+
+ EntityName [AffectedEntity.Property] = GettextCatalog.GetString ("Properties");
+ EntityName [AffectedEntity.AsyncMethod] = GettextCatalog.GetString ("Async methods");
+ EntityName [AffectedEntity.Method] = GettextCatalog.GetString ("Methods");
+ EntityName [AffectedEntity.Field] = GettextCatalog.GetString ("Fields");
+ EntityName [AffectedEntity.ConstantField] = GettextCatalog.GetString ("Constant fields");
+ EntityName [AffectedEntity.ReadonlyField] = GettextCatalog.GetString ("Readonly fields");
+ EntityName [AffectedEntity.Event] = GettextCatalog.GetString ("Events");
+ EntityName [AffectedEntity.EnumMember] = GettextCatalog.GetString ("Enum Members");
+
+ EntityName [AffectedEntity.Parameter] = GettextCatalog.GetString ("Parameters");
+ EntityName [AffectedEntity.TypeParameter] = GettextCatalog.GetString ("Type Parameters");
+
+ // Unit test special case
+ EntityName [AffectedEntity.TestType] = GettextCatalog.GetString ("Test Types");
+ EntityName [AffectedEntity.TestMethod] = GettextCatalog.GetString ("Test Methods");
+
+ // private entities
+ EntityName [AffectedEntity.LambdaParameter] = GettextCatalog.GetString ("Lambda Parameters");
+ EntityName [AffectedEntity.LocalVariable] = GettextCatalog.GetString ("Local Variables");
+ EntityName [AffectedEntity.LocalConstant] = GettextCatalog.GetString ("Local Constants");
+ EntityName [AffectedEntity.Label] = GettextCatalog.GetString ("Labels");
+
+ AccessibilityName [Modifiers.Public] = GettextCatalog.GetString ("Public");
+ AccessibilityName [Modifiers.Private] = GettextCatalog.GetString ("Private");
+ AccessibilityName [Modifiers.Internal] = GettextCatalog.GetString ("Internal");
+ AccessibilityName [Modifiers.Protected] = GettextCatalog.GetString ("Protected");
+ }
+
+ NameConventionRule rule;
+
+ ListStore entityStore = new ListStore (typeof(string), typeof(AffectedEntity), typeof(bool));
+ ListStore accessibiltyStore = new ListStore (typeof(string), typeof(Modifiers), typeof(bool));
+
+ public NameConventionEditRuleDialog (NameConventionRule rule)
+ {
+ if (rule == null)
+ throw new System.ArgumentNullException ("rule");
+ this.rule = rule;
+ this.Build ();
+
+ var ct1 = new CellRendererToggle ();
+ ct1.Toggled += delegate(object o, Gtk.ToggledArgs args) {
+ TreeIter iter;
+ if (!entityStore.GetIterFromString (out iter, args.Path))
+ return;
+ entityStore.SetValue (iter, 2, !(bool)entityStore.GetValue (iter, 2));
+ };
+ treeviewEntities.AppendColumn ("IsChecked", ct1, "active", 2);
+ treeviewEntities.AppendColumn ("Entity", new CellRendererText (), "text", 0);
+ treeviewEntities.Model = entityStore;
+
+ var ct2 = new CellRendererToggle ();
+ ct2.Toggled += delegate(object o, Gtk.ToggledArgs args) {
+ TreeIter iter;
+ if (!accessibiltyStore.GetIterFromString (out iter, args.Path))
+ return;
+ accessibiltyStore.SetValue (iter, 2, !(bool)accessibiltyStore.GetValue (iter, 2));
+ };
+ treeviewAccessibility.AppendColumn ("IsChecked", ct2, "active", 2);
+ treeviewAccessibility.AppendColumn ("Entity", new CellRendererText (), "text", 0);
+ treeviewAccessibility.Model = accessibiltyStore;
+ buttonOk.Clicked += (sender, e) => Apply ();
+
+ FillDialog ();
+ }
+
+ public void FillDialog ()
+ {
+ entryRuleName.Text = rule.Name ?? "";
+ if (rule.RequiredPrefixes != null)
+ entryPrefix.Text = rule.RequiredPrefixes.FirstOrDefault ();
+ if (rule.AllowedPrefixes != null)
+ entryPrefixAllowed.Text = string.Join (", ", rule.AllowedPrefixes);
+ if (rule.RequiredSuffixes != null)
+ entrySuffix.Text = rule.RequiredSuffixes.FirstOrDefault ();
+ styleComboBox.AppendText ("PascalCase");
+ styleComboBox.AppendText ("CamelCase");
+ styleComboBox.AppendText ("ALLUPPER");
+ styleComboBox.AppendText ("alllower");
+ styleComboBox.AppendText ("Firstupper");
+ styleComboBox.AppendText ("PascalCase_underscoreTolerant");
+ styleComboBox.AppendText ("PascalCase_UnderscoreTolerant");
+ styleComboBox.AppendText ("CamelCase_underscoreTolerant");
+ styleComboBox.AppendText ("CamelCase_UnderscoreTolerant");
+
+ styleComboBox.Active = (int)rule.NamingStyle - 1;
+
+ foreach (AffectedEntity ae in Enum.GetValues (typeof (AffectedEntity))) {
+ if (!EntityName.ContainsKey (ae))
+ continue;
+ entityStore.AppendValues (EntityName [ae], ae, rule.AffectedEntity.HasFlag (ae));
+ }
+
+ foreach (Modifiers mod in Enum.GetValues (typeof (Modifiers))) {
+ if (!AccessibilityName.ContainsKey (mod))
+ continue;
+ accessibiltyStore.AppendValues (AccessibilityName [mod], mod, rule.VisibilityMask.HasFlag (mod));
+ }
+
+ checkbuttonStatic.Active = rule.IncludeStaticEntities;
+ checkbuttonInstanceMembers.Active = rule.IncludeInstanceMembers;
+
+ }
+
+ public void Apply ()
+ {
+ rule.Name = entryRuleName.Text;
+ rule.NamingStyle = (NamingStyle)(1 + styleComboBox.Active);
+
+ var prefix = entryPrefix.Text.Trim ();
+ if (string.IsNullOrEmpty (prefix)) {
+ rule.RequiredPrefixes = null;
+ } else {
+ rule.RequiredPrefixes = new [] { prefix };
+ }
+
+ var allowedPrefix = entryPrefixAllowed.Text.Trim ();
+ if (string.IsNullOrEmpty (allowedPrefix)) {
+ rule.AllowedPrefixes = null;
+ } else {
+ rule.AllowedPrefixes = allowedPrefix.Split (',', ';').Select (s => s.Trim ()).ToArray ();
+ }
+
+ var suffix = entrySuffix.Text.Trim ();
+ if (string.IsNullOrEmpty (suffix)) {
+ rule.RequiredSuffixes = null;
+ } else {
+ rule.RequiredSuffixes = new [] { suffix };
+ }
+
+ var ae = AffectedEntity.None;
+ TreeIter iter;
+ if (entityStore.GetIterFirst (out iter)) {
+ do {
+ var entity = (AffectedEntity)entityStore.GetValue (iter, 1);
+ var include = (bool)entityStore.GetValue (iter, 2);
+ if (include)
+ ae |= entity;
+ } while (entityStore.IterNext (ref iter));
+ }
+ rule.AffectedEntity = ae;
+
+ var mod = Modifiers.None;
+ if (accessibiltyStore.GetIterFirst (out iter)) {
+ do {
+ var entity = (Modifiers)accessibiltyStore.GetValue (iter, 1);
+ var include = (bool)accessibiltyStore.GetValue (iter, 2);
+ if (include)
+ mod |= entity;
+ } while (accessibiltyStore.IterNext (ref iter));
+ }
+ rule.VisibilityMask = mod;
+ rule.IncludeStaticEntities = checkbuttonStatic.Active;
+ rule.IncludeInstanceMembers = checkbuttonInstanceMembers.Active;
+ }
+ }
+}
+
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionPanel.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionPanel.cs
new file mode 100644
index 0000000000..e91a6242ba
--- /dev/null
+++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionPanel.cs
@@ -0,0 +1,73 @@
+//
+// NamingConventionPanel.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2012 Xamarin <http://xamarin.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 MonoDevelop.Ide.Gui.Dialogs;
+using Gtk;
+using MonoDevelop.Core;
+using MonoDevelop.Ide.Editor;
+
+namespace MonoDevelop.CSharp.Diagnostics.InconsistentNaming
+{
+ class NameConventionPanel : PolicyOptionsPanel<NameConventionPolicy>
+ {
+ NameConventionPanelWidget panel;
+
+ static NameConventionPanel ()
+ {
+ // ensure that custom text editor shemes are loaded.
+ TextEditorDisplayBinding.InitSourceEditor ();
+ }
+
+ protected override string PolicyTitleWithMnemonic {
+ get {
+ return GettextCatalog.GetString ("_Naming Style");
+ }
+ }
+
+ public override Widget CreatePanelWidget ()
+ {
+ panel = new NameConventionPanelWidget ();
+ panel.PolicyChanged += delegate {
+ UpdateSelectedNamedPolicy ();
+ };
+ return panel;
+ }
+
+ protected override void LoadFrom (NameConventionPolicy policy)
+ {
+ panel.Policy = policy.Clone ();
+ }
+
+ protected override NameConventionPolicy GetPolicy ()
+ {
+ // return cloned policy
+ panel.ApplyChanges ();
+ return panel.Policy;
+ }
+ }
+
+}
+
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionPanelWidget.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionPanelWidget.cs
new file mode 100644
index 0000000000..f4da2ff9ba
--- /dev/null
+++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionPanelWidget.cs
@@ -0,0 +1,154 @@
+//
+// NamingConventionPanelWidget.cs
+//
+// Author:
+// Mike Krüger <mkrueger@novell.com>
+//
+// 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 Gtk;
+using MonoDevelop.Core;
+using MonoDevelop.Ide;
+using System.Collections.Generic;
+
+namespace MonoDevelop.CSharp.Diagnostics.InconsistentNaming
+{
+ [System.ComponentModel.ToolboxItem(true)]
+ partial class NameConventionPanelWidget : Gtk.Bin
+ {
+ TreeStore treeStore = new TreeStore (typeof(NameConventionRule));
+ NameConventionPolicy policy;
+
+ internal NameConventionPolicy Policy {
+ get {
+ return policy;
+ }
+ set {
+ policy = value;
+ FillRules (policy.Rules);
+ }
+ }
+
+ public NameConventionPanelWidget ()
+ {
+ Build ();
+ Show ();
+
+ var ct1 = new CellRendererText ();
+ var col1 = treeviewConventions.AppendColumn (GettextCatalog.GetString ("Rule"), ct1);
+ col1.Expand = true;
+ col1.SetCellDataFunc (ct1, delegate (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) {
+ var rule = (NameConventionRule)model.GetValue (iter, 0);
+ ct1.Text = rule.Name;
+ });
+
+
+ var ct2 = new CellRendererText ();
+ var col2 = treeviewConventions.AppendColumn (GettextCatalog.GetString ("Example"), ct2);
+ col2.Expand = true;
+ col2.SetCellDataFunc (ct2, delegate (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) {
+ var rule = (NameConventionRule)model.GetValue (iter, 0);
+ ct2.Text = rule.GetPreview ();
+ });
+
+ treeviewConventions.Model = treeStore;
+ treeviewConventions.Selection.Changed += HandleSelectionChanged;
+ treeviewConventions.RowActivated += (o, args) => EditSelectedEntry ();
+ buttonEdit.Clicked += (o, s) => EditSelectedEntry ();
+ buttonRemove.Clicked += (o, s) => RemoveSelectedEntry ();
+ buttonAdd.Clicked += (o, s) => AddEntry ();
+
+ HandleSelectionChanged (null, null);
+ }
+
+ void HandleSelectionChanged (object sender, EventArgs e)
+ {
+ TreeIter iter;
+ buttonEdit.Sensitive = treeviewConventions.Selection.GetSelected (out iter);
+ }
+
+ public void ApplyChanges ()
+ {
+ var rules = new List<NameConventionRule> ();
+ TreeIter iter;
+ if (treeStore.GetIterFirst (out iter)) {
+ do {
+ var rule = (NameConventionRule)treeStore.GetValue (iter, 0);
+ rules.Add (rule);
+ } while (treeStore.IterNext (ref iter));
+ }
+ policy.Rules = rules.ToArray ();
+ if (IdeApp.Workbench.ActiveDocument != null)
+ IdeApp.Workbench.ActiveDocument.UpdateParseDocument ();
+ }
+
+ void AddEntry ()
+ {
+ var newRule = new NameConventionRule ();
+ newRule.Name = "New Rule";
+ var diag = new NameConventionEditRuleDialog (newRule);
+ var result = MessageService.ShowCustomDialog (diag);
+ if (result == (int)ResponseType.Ok)
+ treeStore.AppendValues (newRule);
+ OnPolicyChanged (EventArgs.Empty);
+ }
+
+ void EditSelectedEntry ()
+ {
+ TreeIter iter;
+ if (!treeviewConventions.Selection.GetSelected (out iter))
+ return;
+ var rule = treeStore.GetValue (iter, 0) as NameConventionRule;
+ var diag = new NameConventionEditRuleDialog (rule);
+ int result = MessageService.ShowCustomDialog (diag);
+ treeviewConventions.QueueResize ();
+ if (result == (int)Gtk.ResponseType.Ok)
+ OnPolicyChanged (EventArgs.Empty);
+ }
+
+ void RemoveSelectedEntry ()
+ {
+ TreeIter iter;
+ if (!treeviewConventions.Selection.GetSelected (out iter))
+ return;
+ treeStore.Remove (ref iter);
+ OnPolicyChanged (EventArgs.Empty);
+ }
+
+ void FillRules (IEnumerable<NameConventionRule> rules)
+ {
+ treeStore.Clear ();
+ foreach (var rule in rules) {
+ treeStore.AppendValues (rule);
+ }
+ }
+
+ protected virtual void OnPolicyChanged (EventArgs e)
+ {
+ var handler = PolicyChanged;
+ if (handler != null)
+ handler (this, e);
+ }
+
+ public event EventHandler PolicyChanged;
+ }
+}
+
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionPolicy.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionPolicy.cs
new file mode 100644
index 0000000000..c2b8500bd3
--- /dev/null
+++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionPolicy.cs
@@ -0,0 +1,96 @@
+//
+// NamingConventions.cs
+//
+// Author:
+// Mike Krüger <mkrueger@novell.com>
+//
+// 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.Linq;
+using System.Collections.Generic;
+using MonoDevelop.Projects.Policies;
+using MonoDevelop.Core.Serialization;
+using ICSharpCode.NRefactory6.CSharp.Diagnostics;
+
+namespace MonoDevelop.CSharp.Diagnostics.InconsistentNaming
+{
+ [PolicyType ("Naming Conventions Policy")]
+ class NameConventionPolicy : IEquatable<NameConventionPolicy>
+ {
+ NameConventionRule[] rules = new NameConventionRule[0];
+
+ [ItemProperty]
+ public NameConventionRule[] Rules {
+ get { return rules; }
+ set { rules = value; }
+ }
+
+ public NameConventionPolicy Clone ()
+ {
+ var result = new NameConventionPolicy ();
+ result.rules = new List<NameConventionRule> (rules.Select (r => r.Clone ())).ToArray ();
+ return result;
+ }
+
+ public NameConventionPolicy ()
+ {
+ rules = new List<NameConventionRule> (DefaultRules.GetFdgRules ().Select (r => new NameConventionRule (r))).ToArray ();
+ }
+
+ class NamingConventionService : ICSharpCode.NRefactory6.CSharp.Diagnostics.NamingConventionService
+ {
+ NameConventionPolicy policy;
+ NamingRule[] rules = null;
+ public override IEnumerable<ICSharpCode.NRefactory6.CSharp.Diagnostics.NamingRule> Rules {
+ get {
+ if (rules == null) {
+ this.rules = policy.Rules.Select (r => r.GetNRefactoryRule ()).ToArray ();
+ }
+ return rules;
+ }
+ }
+
+ public NamingConventionService (NameConventionPolicy policy)
+ {
+ this.policy = policy;
+ }
+
+ }
+
+ public ICSharpCode.NRefactory6.CSharp.Diagnostics.NamingConventionService CreateNRefactoryService ()
+ {
+ return new NamingConventionService (this);
+ }
+
+ #region IEquatable implementation
+ public bool Equals (NameConventionPolicy other)
+ {
+ if (Rules.Length != other.Rules.Length)
+ return false;
+ for (int i = 0; i < rules.Length; i++) {
+ if (!rules [i].Equals (other.Rules[i]))
+ return false;
+ }
+ return true;
+ }
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionRule.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionRule.cs
new file mode 100644
index 0000000000..2453efff88
--- /dev/null
+++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Diagnostics/InconsistentNaming/NameConventionRule.cs
@@ -0,0 +1,132 @@
+//
+// NamingRule.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2012 Xamarin Inc. (http://xamarin.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.Text;
+using MonoDevelop.Projects.Policies;
+using MonoDevelop.Core.Serialization;
+using ICSharpCode.NRefactory6.CSharp.Refactoring;
+
+namespace MonoDevelop.CSharp.Diagnostics.InconsistentNaming
+{
+ [DataItem ("NamingRule")]
+ sealed class NameConventionRule
+ {
+ ICSharpCode.NRefactory6.CSharp.Diagnostics.NamingRule wrappedRule = new ICSharpCode.NRefactory6.CSharp.Diagnostics.NamingRule (ICSharpCode.NRefactory6.CSharp.Diagnostics.AffectedEntity.None);
+
+ [ItemProperty]
+ public string Name {
+ get { return wrappedRule.Name; }
+ set { wrappedRule.Name = value;}
+ }
+
+ [ItemProperty]
+ public string[] RequiredPrefixes {
+ get { return wrappedRule.RequiredPrefixes; }
+ set { wrappedRule.RequiredPrefixes = value;}
+ }
+
+ [ItemProperty]
+ public string[] AllowedPrefixes {
+ get { return wrappedRule.AllowedPrefixes; }
+ set { wrappedRule.AllowedPrefixes = value;}
+ }
+
+ [ItemProperty]
+ public string[] RequiredSuffixes {
+ get { return wrappedRule.RequiredSuffixes; }
+ set { wrappedRule.RequiredSuffixes = value;}
+ }
+
+ [ItemProperty]
+ public string[] ForbiddenPrefixes {
+ get { return wrappedRule.ForbiddenPrefixes; }
+ set { wrappedRule.ForbiddenPrefixes = value;}
+ }
+
+ [ItemProperty]
+ public string[] ForbiddenSuffixes {
+ get { return wrappedRule.ForbiddenSuffixes; }
+ set { wrappedRule.ForbiddenSuffixes = value;}
+ }
+
+ [ItemProperty]
+ public ICSharpCode.NRefactory6.CSharp.Diagnostics.AffectedEntity AffectedEntity {
+ get { return wrappedRule.AffectedEntity; }
+ set { wrappedRule.AffectedEntity = value;}
+ }
+
+ [ItemProperty]
+ public ICSharpCode.NRefactory6.CSharp.Diagnostics.Modifiers VisibilityMask {
+ get { return wrappedRule.VisibilityMask; }
+ set { wrappedRule.VisibilityMask = value;}
+ }
+
+ [ItemProperty]
+ public ICSharpCode.NRefactory6.CSharp.Diagnostics.NamingStyle NamingStyle {
+ get { return wrappedRule.NamingStyle; }
+ set { wrappedRule.NamingStyle = value;}
+ }
+
+ [ItemProperty]
+ public bool IncludeInstanceMembers {
+ get { return wrappedRule.IncludeInstanceMembers; }
+ set { wrappedRule.IncludeInstanceMembers = value;}
+ }
+
+ [ItemProperty]
+ public bool IncludeStaticEntities {
+ get { return wrappedRule.IncludeStaticEntities; }
+ set { wrappedRule.IncludeStaticEntities = value;}
+ }
+
+ internal NameConventionRule (ICSharpCode.NRefactory6.CSharp.Diagnostics.NamingRule wrappedRule)
+ {
+ this.wrappedRule = wrappedRule;
+ }
+
+ public NameConventionRule ()
+ {
+ }
+
+ public NameConventionRule Clone ()
+ {
+ return new NameConventionRule () {
+ wrappedRule = this.wrappedRule.Clone ()
+ };
+ }
+
+ public string GetPreview ()
+ {
+ return wrappedRule.GetPreview ();
+ }
+
+ internal ICSharpCode.NRefactory6.CSharp.Diagnostics.NamingRule GetNRefactoryRule ()
+ {
+ return wrappedRule;
+ }
+ }
+}
+