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

github.com/mono/mono-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'gendarme')
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/AvoidCodeDuplicatedInSameClassRule.cs2
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/AvoidCodeDuplicatedInSiblingClassesRule.cs4
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/AvoidLargeClassesRule.cs2
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/AvoidLongMethodsRule.cs2
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/AvoidLongParameterListsRule.cs18
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/AvoidMessageChainsRule.cs3
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/AvoidSpeculativeGeneralityRule.cs8
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/CodeDuplicatedLocator.cs4
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/InstructionMatcher.cs19
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/Test/AvoidCodeDuplicatedInSiblingClassesTest.cs6
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLargeClassesTest.cs26
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLongMethodsTest.cs2
-rw-r--r--gendarme/rules/Gendarme.Rules.Smells/Utilities.cs3
13 files changed, 52 insertions, 47 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Smells/AvoidCodeDuplicatedInSameClassRule.cs b/gendarme/rules/Gendarme.Rules.Smells/AvoidCodeDuplicatedInSameClassRule.cs
index e7b7fadf..32154348 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/AvoidCodeDuplicatedInSameClassRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/AvoidCodeDuplicatedInSameClassRule.cs
@@ -120,7 +120,7 @@ namespace Gendarme.Rules.Smells {
return RuleResult.DoesNotApply;
locator.Clear ();
- foreach (MethodDefinition current in type.AllMethods ()) {
+ foreach (MethodDefinition current in type.Methods) {
locator.CompareMethodAgainstTypeMethods (current, type);
locator.CheckedMethods.AddIfNew (current.Name);
}
diff --git a/gendarme/rules/Gendarme.Rules.Smells/AvoidCodeDuplicatedInSiblingClassesRule.cs b/gendarme/rules/Gendarme.Rules.Smells/AvoidCodeDuplicatedInSiblingClassesRule.cs
index 21ce5cbc..57e3dbb3 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/AvoidCodeDuplicatedInSiblingClassesRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/AvoidCodeDuplicatedInSiblingClassesRule.cs
@@ -109,9 +109,9 @@ namespace Gendarme.Rules.Smells {
codeDuplicatedLocator = new CodeDuplicatedLocator (this);
}
- private void FindCodeDuplicated (TypeReference type, ICollection<TypeDefinition> siblingClasses)
+ private void FindCodeDuplicated (TypeDefinition type, ICollection<TypeDefinition> siblingClasses)
{
- foreach (MethodDefinition method in type.AllMethods ())
+ foreach (MethodDefinition method in type.Methods)
foreach (TypeDefinition sibling in siblingClasses)
codeDuplicatedLocator.CompareMethodAgainstTypeMethods (method, sibling);
}
diff --git a/gendarme/rules/Gendarme.Rules.Smells/AvoidLargeClassesRule.cs b/gendarme/rules/Gendarme.Rules.Smells/AvoidLargeClassesRule.cs
index 597311a6..25519b41 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/AvoidLargeClassesRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/AvoidLargeClassesRule.cs
@@ -139,7 +139,7 @@ namespace Gendarme.Rules.Smells {
return -1;
}
- private static string GetFieldPrefix (IMemberReference field)
+ private static string GetFieldPrefix (MemberReference field)
{
string name = field.Name;
int index = GetIndexOfFirst (name, delegate (char character) {return Char.IsNumber (character);});
diff --git a/gendarme/rules/Gendarme.Rules.Smells/AvoidLongMethodsRule.cs b/gendarme/rules/Gendarme.Rules.Smells/AvoidLongMethodsRule.cs
index 3e6379ea..67cb2748 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/AvoidLongMethodsRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/AvoidLongMethodsRule.cs
@@ -319,7 +319,7 @@ namespace Gendarme.Rules.Smells {
field_count = GetFieldCount ((method.DeclaringType as TypeDefinition), method.IsStatic);
// if we have debugging information available and we're not asked to use IL approximation
- if (!UseIlApproximation && method.DeclaringType.Module.HasDebuggingInformation ()) {
+ if (!UseIlApproximation && method.DeclaringType.Module.HasSymbols) {
// add a few extra lines to let the constructors initialize the fields
int max = MaxSourceLineOfCode + field_count;
int sloc = CountSourceLinesOfCode (method);
diff --git a/gendarme/rules/Gendarme.Rules.Smells/AvoidLongParameterListsRule.cs b/gendarme/rules/Gendarme.Rules.Smells/AvoidLongParameterListsRule.cs
index 98090ce1..6eb4648b 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/AvoidLongParameterListsRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/AvoidLongParameterListsRule.cs
@@ -29,6 +29,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Linq;
using Mono.Cecil;
using Gendarme.Framework;
@@ -94,7 +95,7 @@ namespace Gendarme.Rules.Smells {
private static MethodDefinition GetSmallestConstructorFrom (TypeDefinition type)
{
- ConstructorCollection ctors = type.Constructors;
+ IList<MethodDefinition> ctors = type.GetConstructors ().ToList ();
if (ctors.Count == 1)
return ctors [0];
@@ -145,7 +146,7 @@ namespace Gendarme.Rules.Smells {
private static IEnumerable<MethodDefinition> GetSmallestOverloaded (TypeDefinition type)
{
IDictionary<string, MethodDefinition> possibleOverloaded = new Dictionary<string, MethodDefinition> ();
- foreach (MethodDefinition method in type.Methods) {
+ foreach (MethodDefinition method in type.GetMethods ()) {
if (method.IsPInvokeImpl)
continue;
@@ -165,14 +166,14 @@ namespace Gendarme.Rules.Smells {
private static bool OnlyContainsExternalMethods (TypeDefinition type)
{
- if (!type.HasMethods)
- return false;
-
- foreach (MethodDefinition method in type.Methods)
+ bool has_methods = false;
+ foreach (MethodDefinition method in type.GetMethods ()) {
+ has_methods = true;
if (!method.IsPInvokeImpl)
return false;
+ }
// all methods are p/invoke
- return true;
+ return has_methods;
}
private RuleResult CheckDelegate (TypeReference type)
@@ -194,10 +195,9 @@ namespace Gendarme.Rules.Smells {
if (type.IsDelegate ())
return CheckDelegate (type);
- if (type.HasConstructors)
+ if (type.HasMethods) {
CheckConstructor (GetSmallestConstructorFrom (type));
- if (type.HasMethods) {
foreach (MethodDefinition method in GetSmallestOverloaded (type))
CheckMethod (method);
}
diff --git a/gendarme/rules/Gendarme.Rules.Smells/AvoidMessageChainsRule.cs b/gendarme/rules/Gendarme.Rules.Smells/AvoidMessageChainsRule.cs
index f5bc6173..8d79e771 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/AvoidMessageChainsRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/AvoidMessageChainsRule.cs
@@ -29,6 +29,7 @@
//
using System;
+using System.Collections.Generic;
using System.Diagnostics;
using Mono.Cecil;
@@ -106,7 +107,7 @@ namespace Gendarme.Rules.Smells {
// walk back so we don't process very long chains multiple times
// (we don't need to go down to zero since it would not be big enough for a chain to exists)
- InstructionCollection ic = method.Body.Instructions;
+ IList<Instruction> ic = method.Body.Instructions;
for (int i = ic.Count - 1; i >= MaxChainLength; i--) {
Instruction ins = ic [i];
// continue until we find a Call[virt] instruction
diff --git a/gendarme/rules/Gendarme.Rules.Smells/AvoidSpeculativeGeneralityRule.cs b/gendarme/rules/Gendarme.Rules.Smells/AvoidSpeculativeGeneralityRule.cs
index 599198c3..e4967786 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/AvoidSpeculativeGeneralityRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/AvoidSpeculativeGeneralityRule.cs
@@ -27,6 +27,8 @@
//
using System;
+using System.Collections.Generic;
+using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
@@ -120,7 +122,7 @@ namespace Gendarme.Rules.Smells {
int count = 0;
foreach (AssemblyDefinition assembly in Runner.Assemblies) {
foreach (ModuleDefinition module in assembly.Modules) {
- foreach (TypeDefinition type in module.Types) {
+ foreach (TypeDefinition type in module.GetAllTypes ()) {
if ((baseType == type.BaseType) || (type.BaseType != null &&
(baseType.FullName == type.BaseType.FullName))) {
count++;
@@ -173,7 +175,7 @@ namespace Gendarme.Rules.Smells {
return false; // 0 / 2 + 1 <= 0
int delegationCounter = 0;
- MethodDefinitionCollection methods = type.Methods;
+ IList<MethodDefinition> methods = type.GetMethods ().ToList ();
foreach (MethodDefinition method in methods) {
if (OnlyDelegatesCall (method))
delegationCounter++;
@@ -225,7 +227,7 @@ namespace Gendarme.Rules.Smells {
CheckAbstractClassWithoutResponsability (type);
if (avoidUnusedParameters != null) {
- foreach (MethodDefinition method in type.AllMethods ()) {
+ foreach (MethodDefinition method in type.GetMethods ()) {
avoidUnusedParameters.CheckMethod (method);
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Smells/CodeDuplicatedLocator.cs b/gendarme/rules/Gendarme.Rules.Smells/CodeDuplicatedLocator.cs
index 4d4c62b9..528922cf 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/CodeDuplicatedLocator.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/CodeDuplicatedLocator.cs
@@ -71,12 +71,12 @@ namespace Gendarme.Rules.Smells {
types.Clear ();
}
- internal void CompareMethodAgainstTypeMethods (MethodDefinition current, TypeReference targetType)
+ internal void CompareMethodAgainstTypeMethods (MethodDefinition current, TypeDefinition targetType)
{
if (CheckedTypes.Contains (targetType.Name))
return;
- foreach (MethodDefinition target in targetType.AllMethods ()) {
+ foreach (MethodDefinition target in targetType.GetMethods ()) {
if (target.IsGeneratedCode ())
continue;
diff --git a/gendarme/rules/Gendarme.Rules.Smells/InstructionMatcher.cs b/gendarme/rules/Gendarme.Rules.Smells/InstructionMatcher.cs
index a9c0e1ed..8ee732ab 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/InstructionMatcher.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/InstructionMatcher.cs
@@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
+
using Mono.Cecil;
using Mono.Cecil.Cil;
using Gendarme.Framework.Rocks;
@@ -55,26 +56,26 @@ namespace Gendarme.Rules.Smells {
}
}
- static bool AreEquivalent (ParameterReference source, ParameterReference target)
+ static bool AreEquivalent (ParameterDefinition source, ParameterDefinition target)
{
if ((source == null) || (target == null))
return false;
- int ss = source.Sequence - 1;
- int ts = target.Sequence - 1;
+ int ss = source.GetSequence () - 1;
+ int ts = target.GetSequence () - 1;
if ((ss <= 0) || (ts <= 0))
return false;
- ParameterDefinitionCollection cp = Current.Parameters;
- ParameterDefinitionCollection tp = Target.Parameters;
+ IList<ParameterDefinition> cp = Current.Parameters;
+ IList<ParameterDefinition> tp = Target.Parameters;
return ((cp.Count > ss) && (tp.Count > ts)) ?
cp [ss].ParameterType.Equals (tp [ts].ParameterType) : false;
}
static bool AreEquivalent (VariableReference source, VariableReference target)
{
- VariableDefinitionCollection cv = Current.Body.Variables;
- VariableDefinitionCollection tv = Target.Body.Variables;
+ IList<VariableDefinition> cv = Current.Body.Variables;
+ IList<VariableDefinition> tv = Target.Body.Variables;
return cv.Count > source.Index && tv.Count > target.Index ?
cv [source.Index].VariableType.Equals (tv [target.Index].VariableType) : false;
}
@@ -91,7 +92,7 @@ namespace Gendarme.Rules.Smells {
//could lead us to false positives. We need an analysis
//which depends on the context.
if (source.IsLoadArgument ()) {
- // case where 'ldarg this' is used (p.Sequence would be 0)
+ // case where 'ldarg this' is used (p.GetSequence () would be 0)
if (!Current.HasParameters && !Target.HasParameters)
return true;
return AreEquivalent (source.GetParameter (Current), target.GetParameter (Target));
@@ -132,7 +133,7 @@ namespace Gendarme.Rules.Smells {
//Mono.Cecil.Cil.Instruction instead of characters, and a
//InstructionCollection instead of string. I think it's a nice
//metaphor :)
- internal static bool Match (Pattern pattern, InstructionCollection target)
+ internal static bool Match (Pattern pattern, IList<Instruction> target)
{
int instructionsMatched = 0;
diff --git a/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidCodeDuplicatedInSiblingClassesTest.cs b/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidCodeDuplicatedInSiblingClassesTest.cs
index f5b9b6de..dad93cde 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidCodeDuplicatedInSiblingClassesTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidCodeDuplicatedInSiblingClassesTest.cs
@@ -100,7 +100,7 @@ namespace Test.Rules.Smells {
public void FixtureSetUp ()
{
string unit = Assembly.GetExecutingAssembly ().Location;
- assembly = AssemblyFactory.GetAssembly (unit);
+ assembly = AssemblyDefinition.ReadAssembly (unit);
rule = new AvoidCodeDuplicatedInSiblingClassesRule ();
runner = new TestRunner (rule);
}
@@ -108,7 +108,7 @@ namespace Test.Rules.Smells {
[Test]
public void BaseClassWithCodeDuplicatedTest ()
{
- type = assembly.MainModule.Types ["Test.Rules.Smells.BaseClassWithCodeDuplicated"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.BaseClassWithCodeDuplicated");
Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
Assert.AreEqual (1, runner.Defects.Count);
}
@@ -116,7 +116,7 @@ namespace Test.Rules.Smells {
[Test]
public void BaseClassWithoutCodeDuplicatedTest ()
{
- type = assembly.MainModule.Types ["Test.Rules.Smells.BaseClassWithoutCodeDuplicated"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.BaseClassWithoutCodeDuplicated");
Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLargeClassesTest.cs b/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLargeClassesTest.cs
index cc20d62d..b7ad803b 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLargeClassesTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLargeClassesTest.cs
@@ -124,7 +124,7 @@ namespace Test.Rules.Smells {
public void FixtureSetUp ()
{
string unit = Assembly.GetExecutingAssembly ().Location;
- assembly = AssemblyFactory.GetAssembly (unit);
+ assembly = AssemblyDefinition.ReadAssembly (unit);
rule = new AvoidLargeClassesRule ();
runner = new TestRunner (rule);
}
@@ -132,7 +132,7 @@ namespace Test.Rules.Smells {
[Test]
public void LargeClassTest ()
{
- type = assembly.MainModule.Types["Test.Rules.Smells.LargeClass"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.LargeClass");
Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
// 'x', 'foo', 'bar', 'f', 'c' and 's' are reported as prefixes
Assert.AreEqual (6, runner.Defects.Count);
@@ -141,10 +141,10 @@ namespace Test.Rules.Smells {
[Test]
public void NotLargeClassTest ()
{
- type = assembly.MainModule.Types["Test.Rules.Smells.NoFieldClass"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.NoFieldClass");
Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
- type = assembly.MainModule.Types["Test.Rules.Smells.NotLargeClass"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.NotLargeClass");
Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
@@ -152,14 +152,14 @@ namespace Test.Rules.Smells {
[Test]
public void ConstantClassTest ()
{
- type = assembly.MainModule.Types["Test.Rules.Smells.ConstantClass"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.ConstantClass");
Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void ClassWithPrefixedFieldsWithCamelCasingTest ()
{
- type = assembly.MainModule.Types["Test.Rules.Smells.ClassWithPrefixedFieldsWithCamelCasing"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.ClassWithPrefixedFieldsWithCamelCasing");
Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
Assert.AreEqual (1, runner.Defects.Count);
}
@@ -167,14 +167,14 @@ namespace Test.Rules.Smells {
[Test]
public void ClassWithoutPrefixedFieldsWithMDashCasingTest ()
{
- type = assembly.MainModule.Types["Test.Rules.Smells.ClassWithoutPrefixedFieldsWithMDashCasing"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.ClassWithoutPrefixedFieldsWithMDashCasing");
Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void ClassWithPrefixedFieldsWithDashCasingTest ()
{
- type = assembly.MainModule.Types ["Test.Rules.Smells.ClassWithPrefixedFieldsWithDashCasing"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.ClassWithPrefixedFieldsWithDashCasing");
Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
Assert.AreEqual (1, runner.Defects.Count);
}
@@ -182,7 +182,7 @@ namespace Test.Rules.Smells {
[Test]
public void ClassWithPrefixedFieldsWithMDashCasingTest ()
{
- type = assembly.MainModule.Types ["Test.Rules.Smells.ClassWithPrefixedFieldsWithMDashCasing"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.ClassWithPrefixedFieldsWithMDashCasing");
Assert.AreEqual (RuleResult.Failure, runner.CheckType (type));
Assert.AreEqual (1, runner.Defects.Count);
}
@@ -190,28 +190,28 @@ namespace Test.Rules.Smells {
[Test]
public void ClassWithSomeConstantsFields ()
{
- type = assembly.MainModule.Types ["Test.Rules.Smells.ClassWithSomeConstantsFields"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.ClassWithSomeConstantsFields");
Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void ClassWithSomeReadOnlyFields ()
{
- type = assembly.MainModule.Types ["Test.Rules.Smells.ClassWithSomeReadOnlyFields"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.ClassWithSomeReadOnlyFields");
Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void ClassWithAutoImplementedProperties ()
{
- type = assembly.MainModule.Types ["Test.Rules.Smells.AutoImplementedPropertiesClass"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.AutoImplementedPropertiesClass");
Assert.AreEqual (RuleResult.Success, runner.CheckType (type));
}
[Test]
public void EnumsShouldNotBeCheckedTest ()
{
- type = assembly.MainModule.Types ["Test.Rules.Smells.LargeEnum"];
+ type = assembly.MainModule.GetType ("Test.Rules.Smells.LargeEnum");
Assert.AreEqual (RuleResult.DoesNotApply, runner.CheckType (type));
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLongMethodsTest.cs b/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLongMethodsTest.cs
index 12147410..ded892e7 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLongMethodsTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/Test/AvoidLongMethodsTest.cs
@@ -1371,7 +1371,7 @@ namespace Test.Rules.Smells {
public void FixtureSetUp ()
{
AssemblyDefinition assembly = DefinitionLoader.GetAssemblyDefinition<AvoidLongMethodsTest> ();
- if (!assembly.MainModule.HasDebuggingInformation ())
+ if (!assembly.MainModule.HasSymbols)
Assert.Ignore ("Debugging symbols non-available to compute SLOC.");
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Smells/Utilities.cs b/gendarme/rules/Gendarme.Rules.Smells/Utilities.cs
index 3121f932..556f801b 100644
--- a/gendarme/rules/Gendarme.Rules.Smells/Utilities.cs
+++ b/gendarme/rules/Gendarme.Rules.Smells/Utilities.cs
@@ -30,6 +30,7 @@ using System;
using System.Collections.Generic;
using Gendarme.Framework;
+using Gendarme.Framework.Rocks;
using Mono.Cecil;
@@ -40,7 +41,7 @@ namespace Gendarme.Rules.Smells {
public static ICollection<TypeDefinition> GetInheritedClassesFrom (TypeReference baseType)
{
List<TypeDefinition> inheritedClasses = new List<TypeDefinition> ();
- foreach (TypeDefinition type in baseType.Module.Types) {
+ foreach (TypeDefinition type in baseType.Module.GetAllTypes ()) {
if ((type.BaseType != null) && type.BaseType.Equals (baseType))
inheritedClasses.Add (type);
}