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:
authorSebastien Pouliot <sebastien@ximian.com>2011-01-08 04:26:53 +0300
committerSebastien Pouliot <sebastien@ximian.com>2011-01-08 04:28:52 +0300
commit76bdede936d74179df95cbd07cf8f579783d928a (patch)
tree25fc8ccdb9efb142e0d79cb02fa0390ac87980f4
parentb852c66b2e8c0501773336b8c13af4dd5c26e0cd (diff)
Fix AvoidUncalledPrivateCodeRule (and similar) wrt different assemblies
* Gendarme.Rules.Globalization/AvoidUnusedInternalResourceRule.cs: * Gendarme.Rules.Performance/AvoidUncalledPrivateCodeRule.cs: Use a ulong (instead of uint) to track the methods by combining the assembly hash code and the method RID
-rw-r--r--gendarme/rules/Gendarme.Rules.Globalization/AvoidUnusedInternalResourceRule.cs19
-rw-r--r--gendarme/rules/Gendarme.Rules.Performance/AvoidUncalledPrivateCodeRule.cs19
2 files changed, 20 insertions, 18 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Globalization/AvoidUnusedInternalResourceRule.cs b/gendarme/rules/Gendarme.Rules.Globalization/AvoidUnusedInternalResourceRule.cs
index c49ee635..937be0bc 100644
--- a/gendarme/rules/Gendarme.Rules.Globalization/AvoidUnusedInternalResourceRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Globalization/AvoidUnusedInternalResourceRule.cs
@@ -116,11 +116,11 @@ namespace Gendarme.Rules.Globalization {
return false;
}
- static Dictionary<TypeDefinition, HashSet<uint>> cache = new Dictionary<TypeDefinition, HashSet<uint>> ();
+ static Dictionary<TypeDefinition, HashSet<ulong>> cache = new Dictionary<TypeDefinition, HashSet<ulong>> ();
- private static uint GetToken (MethodReference method)
+ private static ulong GetToken (MethodReference method)
{
- return method.GetElementMethod ().MetadataToken.ToUInt32 ();
+ return (ulong) method.DeclaringType.Module.Assembly.GetHashCode () << 32 | method.GetElementMethod ().MetadataToken.ToUInt32 ();
}
private static bool CheckTypeForMethodUsage (TypeDefinition type, MethodReference method)
@@ -128,7 +128,7 @@ namespace Gendarme.Rules.Globalization {
if (type.HasGenericParameters)
type = type.GetElementType ().Resolve ();
- HashSet<uint> methods = GetCache (type);
+ HashSet<ulong> methods = GetCache (type);
if (methods.Contains (GetToken (method)))
return true;
@@ -142,11 +142,11 @@ namespace Gendarme.Rules.Globalization {
return false;
}
- private static HashSet<uint> GetCache (TypeDefinition type)
+ private static HashSet<ulong> GetCache (TypeDefinition type)
{
- HashSet<uint> methods;
+ HashSet<ulong> methods;
if (!cache.TryGetValue (type, out methods)) {
- methods = new HashSet<uint> ();
+ methods = new HashSet<ulong> ();
cache.Add (type, methods);
if (type.HasMethods) {
foreach (MethodDefinition md in type.Methods) {
@@ -159,7 +159,7 @@ namespace Gendarme.Rules.Globalization {
return methods;
}
- private static void BuildMethodUsage (HashSet<uint> methods, MethodDefinition method)
+ private static void BuildMethodUsage (HashSet<ulong> methods, MethodDefinition method)
{
foreach (Instruction ins in method.Body.Instructions) {
MethodReference mr = (ins.Operand as MethodReference);
@@ -171,8 +171,9 @@ namespace Gendarme.Rules.Globalization {
// if (type.GetElementType ().HasGenericParameters)
// the simpler ^^^ does not work under Mono but works on MS
type = type.Resolve ();
- if (type != null && type.HasGenericParameters)
+ if (type != null && type.HasGenericParameters) {
methods.Add (GetToken (type.GetMethod (mr.Name)));
+ }
}
methods.Add (GetToken (mr));
}
diff --git a/gendarme/rules/Gendarme.Rules.Performance/AvoidUncalledPrivateCodeRule.cs b/gendarme/rules/Gendarme.Rules.Performance/AvoidUncalledPrivateCodeRule.cs
index ce9242fa..a0b96fbe 100644
--- a/gendarme/rules/Gendarme.Rules.Performance/AvoidUncalledPrivateCodeRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Performance/AvoidUncalledPrivateCodeRule.cs
@@ -258,11 +258,11 @@ namespace Gendarme.Rules.Performance {
return false;
}
- static Dictionary<TypeDefinition, HashSet<uint>> cache = new Dictionary<TypeDefinition, HashSet<uint>> ();
+ static Dictionary<TypeDefinition, HashSet<ulong>> cache = new Dictionary<TypeDefinition, HashSet<ulong>> ();
- private static uint GetToken (MethodReference method)
+ private static ulong GetToken (MethodReference method)
{
- return method.GetElementMethod ().MetadataToken.ToUInt32 ();
+ return (ulong) method.DeclaringType.Module.Assembly.GetHashCode () << 32 | method.GetElementMethod ().MetadataToken.ToUInt32 ();
}
private static bool CheckTypeForMethodUsage (TypeDefinition type, MethodReference method)
@@ -270,7 +270,7 @@ namespace Gendarme.Rules.Performance {
if (type.HasGenericParameters)
type = type.GetElementType ().Resolve ();
- HashSet<uint> methods = GetCache (type);
+ HashSet<ulong> methods = GetCache (type);
if (methods.Contains (GetToken (method)))
return true;
@@ -284,11 +284,11 @@ namespace Gendarme.Rules.Performance {
return false;
}
- private static HashSet<uint> GetCache (TypeDefinition type)
+ private static HashSet<ulong> GetCache (TypeDefinition type)
{
- HashSet<uint> methods;
+ HashSet<ulong> methods;
if (!cache.TryGetValue (type, out methods)) {
- methods = new HashSet<uint> ();
+ methods = new HashSet<ulong> ();
cache.Add (type, methods);
if (type.HasMethods) {
foreach (MethodDefinition md in type.Methods) {
@@ -301,7 +301,7 @@ namespace Gendarme.Rules.Performance {
return methods;
}
- private static void BuildMethodUsage (HashSet<uint> methods, MethodDefinition method)
+ private static void BuildMethodUsage (HashSet<ulong> methods, MethodDefinition method)
{
foreach (Instruction ins in method.Body.Instructions) {
MethodReference mr = (ins.Operand as MethodReference);
@@ -313,8 +313,9 @@ namespace Gendarme.Rules.Performance {
// if (type.GetElementType ().HasGenericParameters)
// the simpler ^^^ does not work under Mono but works on MS
type = type.Resolve ();
- if (type != null && type.HasGenericParameters)
+ if (type != null && type.HasGenericParameters) {
methods.Add (GetToken (type.GetMethod (mr.Name)));
+ }
}
methods.Add (GetToken (mr));
}