Author: nestor
Date: 2008-02-07 12:47:50 -0500 (Thu, 07 Feb 2008)
New Revision: 95169
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/AvoidLargeClassesRule.cs
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/ChangeLog
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLargeClassesTest.cs
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog
Log:
2008-02-07 Nestor Salceda <[EMAIL PROTECTED]>
* AvoidLargeClassesRule.cs: Avoid positive when a class contains
constants or readonly fields.
* Test/AvoidLargeClassesTest.cs: Added a test for class storing
common constant values.
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/AvoidLargeClassesRule.cs
===================================================================
---
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/AvoidLargeClassesRule.cs
2008-02-07 17:47:32 UTC (rev 95168)
+++
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/AvoidLargeClassesRule.cs
2008-02-07 17:47:50 UTC (rev 95169)
@@ -53,7 +53,18 @@
private static bool IsTooLarge (TypeDefinition type)
{
- return type.Fields.Count >= MaxFields;
+ int counter = 0;
+ //Skip the constants and others related from this check.
+ //It's common use a class for store constants, by
+ //example: Gendarme.Framework.MethodSignatures.
+ foreach (FieldDefinition field in type.Fields) {
+ if (field.IsSpecialName || field.HasConstant ||
field.IsInitOnly)
+ continue;
+ if (field.IsGeneratedCode ())
+ continue;
+ counter++;
+ }
+ return counter >= MaxFields;
}
private void CheckForClassFields (TypeDefinition type)
Modified: trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/ChangeLog
===================================================================
--- trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/ChangeLog
2008-02-07 17:47:32 UTC (rev 95168)
+++ trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/ChangeLog
2008-02-07 17:47:50 UTC (rev 95169)
@@ -1,5 +1,10 @@
-2008-07-07 Nestor Salceda <[EMAIL PROTECTED]>
+2008-02-07 Nestor Salceda <[EMAIL PROTECTED]>
+ * AvoidLargeClassesRule.cs: Avoid positive when a class contains
+ constants or readonly fields.
+
+2008-02-07 Nestor Salceda <[EMAIL PROTECTED]>
+
* ExpressionFillerVisitor.cs, CodeDuplicatedLocator.cs, Expression.cs:
For performance issues types which aren't visible outside of the
assembly and haven't subclasses should be sealed.
Modified:
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLargeClassesTest.cs
===================================================================
---
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLargeClassesTest.cs
2008-02-07 17:47:32 UTC (rev 95168)
+++
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLargeClassesTest.cs
2008-02-07 17:47:50 UTC (rev 95169)
@@ -59,6 +59,16 @@
string[] array;
}
+ public class ConstantClass {
+ const int x = 0, x1 = 1, x2 = 2, x3 = 3;
+ static readonly string foo, foo1, foo2, foo3;
+ static readonly DateTime bar, bar1, bar2, bar3;
+ float one, two, three, four;
+ const char c = 'c', c1 = 'b', c2 = 'a', c3 = 'z';
+ const short s = 2, s1 = 4, s2 = 6, s3 = 8;
+ static readonly string[] array;
+ }
+
public class ClassWithPrefixedFieldsWithCamelCasing {
int fooBar;
int fooBaz;
@@ -131,7 +141,17 @@
Assert.IsNull (messageCollection);
}
+
[Test]
+ public void ConstantClassTest ()
+ {
+ type =
assembly.MainModule.Types["Test.Rules.Smells.ConstantClass"];
+ messageCollection = rule.CheckType (type, new
MinimalRunner ());
+ Assert.IsNull (messageCollection);
+ }
+
+
+ [Test]
public void ClassWithPrefixedFieldsWithCamelCasingTest ()
{
type =
assembly.MainModule.Types["Test.Rules.Smells.ClassWithPrefixedFieldsWithCamelCasing"];
Modified: trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog
===================================================================
--- trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog
2008-02-07 17:47:32 UTC (rev 95168)
+++ trunk/mono-tools/gendarme/rules/Gendarme.Rules.Smells/Test/ChangeLog
2008-02-07 17:47:50 UTC (rev 95169)
@@ -1,5 +1,10 @@
2008-02-07 Nestor Salceda <[EMAIL PROTECTED]>
+ * AvoidLargeClassesTest.cs: Added a test for class storing common
+ constant values.
+
+2008-02-07 Nestor Salceda <[EMAIL PROTECTED]>
+
* AvoidLongMethodsTest.cs: Added a test for the new strategy for static
constructors.
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches