Author: spouliot
Date: 2008-02-07 22:44:51 -0500 (Thu, 07 Feb 2008)
New Revision: 95220
Added:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/EnumsShouldUseInt32Rule.cs
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/ChangeLog
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.mdp
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.xml.in
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Makefile.am
Log:
2008-02-07 Sebastien Pouliot <[EMAIL PROTECTED]>
* EnumsShouldUseInt32Rule.cs: New. Rule to warn about enumations that
are not based on Int32.
* Gendarme.Rules.Design.mdp: Update project file.
* Gendarme.Rules.Design.xml.in: Add new rule description.
* Makefile.am: Add new rule/test to the build.
Modified: trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/ChangeLog
===================================================================
--- trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/ChangeLog
2008-02-08 03:44:10 UTC (rev 95219)
+++ trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/ChangeLog
2008-02-08 03:44:51 UTC (rev 95220)
@@ -1,3 +1,11 @@
+2008-02-07 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * EnumsShouldUseInt32Rule.cs: New. Rule to warn about enumations that
+ are not based on Int32.
+ * Gendarme.Rules.Design.mdp: Update project file.
+ * Gendarme.Rules.Design.xml.in: Add new rule description.
+ * Makefile.am: Add new rule/test to the build.
+
2008-02-07 Nestor Salceda <[EMAIL PROTECTED]>
* DisposableTypesShouldHaveFinalizerRule.cs,
Added:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/EnumsShouldUseInt32Rule.cs
===================================================================
---
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/EnumsShouldUseInt32Rule.cs
2008-02-08 03:44:10 UTC (rev 95219)
+++
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/EnumsShouldUseInt32Rule.cs
2008-02-08 03:44:51 UTC (rev 95220)
@@ -0,0 +1,83 @@
+//
+// Gendarme.Rules.Design.EnumsShouldUseInt32Rule
+//
+// Authors:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2008 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 Mono.Cecil;
+
+using Gendarme.Framework;
+using Gendarme.Framework.Rocks;
+
+namespace Gendarme.Rules.Design {
+
+ public class EnumsShouldUseInt32Rule : ITypeRule {
+
+ public MessageCollection CheckType (TypeDefinition type, Runner
runner)
+ {
+ // rule apply only on enums
+ if (!type.IsEnum)
+ return runner.RuleSuccess;
+
+ // rule applies!
+
+ string value_type = null;
+
+ foreach (FieldDefinition field in type.Fields) {
+ // we looking for the special value__
+ if (field.IsStatic)
+ continue;
+
+ value_type = field.FieldType.FullName;
+ break;
+ }
+
+ MessageType criticality = MessageType.Error;
+ switch (value_type) {
+ case "System.Int32":
+ return runner.RuleSuccess;
+ // some are bad choice (when possible) but usable by
all CLS compliant languages
+ case "System.Byte":
+ case "System.Int16":
+ case "System.Int64":
+ criticality = MessageType.Warning;
+ break;
+ // while others are not usable in non-CLS compliant
languages
+ case "System.SByte":
+ case "System.UInt16":
+ case "System.UInt32":
+ case "System.UInt64":
+ criticality = MessageType.Error;
+ break;
+ default:
+ throw new NotSupportedException (value_type + "
unexpected as a Enum value type");
+ }
+
+ string text = String.Format ("Enums should use
System.Int32 instead of '{0}'.", value_type);
+ Message msg = new Message (text, new Location (type),
criticality);
+ return new MessageCollection (msg);
+ }
+ }
+}
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.mdp
===================================================================
---
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.mdp
2008-02-08 03:44:10 UTC (rev 95219)
+++
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.mdp
2008-02-08 03:44:51 UTC (rev 95220)
@@ -29,12 +29,18 @@
<File name="ConsiderConvertingMethodToPropertyRule.cs" subtype="Code"
buildaction="Compile" />
<File name="MissingAttributeUsageOnCustomAttributeRule.cs" subtype="Code"
buildaction="Compile" />
<File name="DisposableFieldsShouldBeDisposedRule.cs" subtype="Code"
buildaction="Compile" />
- <File name="DisposableHelper.cs" subtype="Code" buildaction="Compile" />
<File name="DisposableTypesShouldHaveFinalizerRule.cs" subtype="Code"
buildaction="Compile" />
<File name="TypesWithDisposableFieldsShouldBeDisposableRule.cs"
subtype="Code" buildaction="Compile" />
<File name="TypesWithNativeFieldsShouldBeDisposableRule.cs" subtype="Code"
buildaction="Compile" />
<File name="FinalizersShouldBeProtectedRule.cs" subtype="Code"
buildaction="Compile" />
<File name="FinalizersShouldCallBaseClassFinalizerRule.cs" subtype="Code"
buildaction="Compile" />
+ <File name="AttributeArgumentsShouldHaveAccessorsRule.cs" subtype="Code"
buildaction="Compile" />
+ <File name="EnsureSymmetryForOverloadedOperatorsRule.cs" subtype="Code"
buildaction="Compile" />
+ <File name="EnumsShouldUseInt32Rule.cs" subtype="Code"
buildaction="Compile" />
+ <File name="ImplementEqualsAndGetHashCodeInPairRule.cs" subtype="Code"
buildaction="Compile" />
+ <File name="OperatorEqualsShouldBeOverloadedRule.cs" subtype="Code"
buildaction="Compile" />
+ <File name="OverrideEqualsMethodRule.cs" subtype="Code"
buildaction="Compile" />
+ <File name="ProvideAlternativeNamesForOperatorOverloadsRule.cs"
subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Project" localcopy="True" refto="framework" />
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.xml.in
===================================================================
---
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.xml.in
2008-02-08 03:44:10 UTC (rev 95219)
+++
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Gendarme.Rules.Design.xml.in
2008-02-08 03:44:51 UTC (rev 95220)
@@ -65,6 +65,12 @@
<problem>The enum '{0}' should define a member with a value of
0.</problem>
<solution>Add a new member in the enum with a value of
0.</solution>
</rule>
+ <rule Name="EnumsShouldUseInt32Rule"
+ Type="Gendarme.Rules.Design.EnumsShouldUseInt32Rule,
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
+
Uri="http://www.mono-project.com/Gendarme.Rules.Design#EnumsShouldUseInt32Rule"
>
+ <problem>Unless it is required for interoperability the enum
'{0}' should use Int32 as it's underling storage type.</problem>
+ <solution>Remove the extra type from the enumeration
declaration (Int32 will be used as default).</solution>
+ </rule>
<rule Name="FinalizersShouldBeProtectedRule"
Type="Gendarme.Rules.Design.FinalizersShouldBeProtectedRule,
Gendarme.Rules.Design, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
Uri="http://www.mono-project.com/Gendarme.Rules.Design#FinalizersShouldBeProtectedRule"
>
Modified: trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Makefile.am
===================================================================
--- trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Makefile.am
2008-02-08 03:44:10 UTC (rev 95219)
+++ trunk/mono-tools/gendarme/rules/Gendarme.Rules.Design/Makefile.am
2008-02-08 03:44:51 UTC (rev 95220)
@@ -19,7 +19,8 @@
TypesWithDisposableFieldsShouldBeDisposableRule.cs
DisposableTypesShouldHaveFinalizerRule.cs \
DisposableFieldsShouldBeDisposedRule.cs
FinalizersShouldBeProtectedRule.cs
FinalizersShouldCallBaseClassFinalizerRule.cs \
EnsureSymmetryForOverloadedOperatorsRule.cs
OperatorEqualsShouldBeOverloadedRule.cs \
- OverrideEqualsMethodRule.cs
ProvideAlternativeNamesForOperatorOverloadsRule.cs
ImplementEqualsAndGetHashCodeInPairRule.cs
+ OverrideEqualsMethodRule.cs
ProvideAlternativeNamesForOperatorOverloadsRule.cs
ImplementEqualsAndGetHashCodeInPairRule.cs \
+ EnumsShouldUseInt32Rule.cs
design_rules_build_sources = $(addprefix $(srcdir)/, $(design_rules_sources))
design_rules_build_sources += $(design_rules_generated_sources)
@@ -37,7 +38,7 @@
TypesWithDisposableFieldsShouldBeDisposableTest.cs
DisposableTypesShouldHaveFinalizerTest.cs \
DisposableFieldsShouldBeDisposedTest.cs
FinalizersShouldBeProtectedTest.cs
FinalizersShouldCallBaseClassFinalizerTest.cs \
EnsureSymmetryForOverloadedOperatorsTest.cs
OperatorEqualsShouldBeOverloadedTest.cs OverrideEqualsMethodTest.cs \
- ProvideAlternativeNamesForOperatorOverloadsTest.cs
ImplementEqualsAndGetHashCodeInPairTest.cs
+ ProvideAlternativeNamesForOperatorOverloadsTest.cs
ImplementEqualsAndGetHashCodeInPairTest.cs EnumsShouldUseInt32Test.cs
design_test_build_sources = $(addprefix $(srcdir)/Test/,
$(design_test_sources))
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches