diff options
author | Sebastien Pouliot <sebastien@ximian.com> | 2010-06-16 06:25:25 +0400 |
---|---|---|
committer | Sebastien Pouliot <sebastien@ximian.com> | 2010-06-16 06:25:25 +0400 |
commit | 5bc4525fec00295da4d873333260e752e6c377e5 (patch) | |
tree | 5444db9b7efbd62b5c1ea52e0d5b479696ff7ce5 | |
parent | 09ca583850d0cf1698750f283813f7d3b376f8ff (diff) |
2010-06-15 Sebastien Pouliot <sebastien@ximian.com>
* DoNotHardcodePathsRule.cs:
* ExitCodeIsLimitedOnUnixRule.cs:
Apply AvoidRepetitiveCallsToPropertiesRule
svn path=/trunk/mono-tools/; revision=158995
3 files changed, 16 insertions, 7 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Portability/ChangeLog b/gendarme/rules/Gendarme.Rules.Portability/ChangeLog index 886f35b8..0dd53119 100644 --- a/gendarme/rules/Gendarme.Rules.Portability/ChangeLog +++ b/gendarme/rules/Gendarme.Rules.Portability/ChangeLog @@ -1,3 +1,9 @@ +2010-06-15 Sebastien Pouliot <sebastien@ximian.com> + + * DoNotHardcodePathsRule.cs: + * ExitCodeIsLimitedOnUnixRule.cs: + Apply AvoidRepetitiveCallsToPropertiesRule + 2010-06-04 Sebastien Pouliot <sebastien@ximian.com> * MonoCompatibilityReviewRule.cs: Rename GetLastestLocalDefinition diff --git a/gendarme/rules/Gendarme.Rules.Portability/DoNotHardcodePathsRule.cs b/gendarme/rules/Gendarme.Rules.Portability/DoNotHardcodePathsRule.cs index 1e5816f0..ed6d8300 100644 --- a/gendarme/rules/Gendarme.Rules.Portability/DoNotHardcodePathsRule.cs +++ b/gendarme/rules/Gendarme.Rules.Portability/DoNotHardcodePathsRule.cs @@ -376,10 +376,10 @@ namespace Gendarme.Rules.Portability { // see what we can learn if (target.HasParameters && (target.Parameters.Count == 1) && - target.Name.StartsWith ("set_", StringComparison.Ordinal)) { + methodName.StartsWith ("set_", StringComparison.Ordinal)) { // to improve performance, don't Resolve () to call IsSpecialName // this is a setter (in 99% cases) - CheckIdentifier (target.Name); + CheckIdentifier (methodName); } else { // we can also check parameter name CheckMethodParameterName (target, currentOffset); @@ -407,17 +407,18 @@ namespace Gendarme.Rules.Portability { void CheckMethodParameterName (MethodReference methodReference, int parameterOffset) { MethodDefinition method = methodReference.Resolve (); - if (method == null) + if ((method == null) || !method.HasParameters) return; - int parameterIndex = (method.HasParameters ? method.Parameters.Count : 0) - parameterOffset - 1; + ParameterDefinitionCollection pdc = method.Parameters; + int parameterIndex = pdc.Count - parameterOffset - 1; // to prevent some uncommon situations if (parameterIndex < 0) return; // parameterOffset is distance in instructions between ldstr and call(i|virt)? - ParameterDefinition parameter = method.Parameters [parameterIndex]; + ParameterDefinition parameter = pdc [parameterIndex]; // if its name is 'pathy', score some points! CheckIdentifier (parameter.Name); diff --git a/gendarme/rules/Gendarme.Rules.Portability/ExitCodeIsLimitedOnUnixRule.cs b/gendarme/rules/Gendarme.Rules.Portability/ExitCodeIsLimitedOnUnixRule.cs index f42670ba..95b66064 100644 --- a/gendarme/rules/Gendarme.Rules.Portability/ExitCodeIsLimitedOnUnixRule.cs +++ b/gendarme/rules/Gendarme.Rules.Portability/ExitCodeIsLimitedOnUnixRule.cs @@ -140,7 +140,8 @@ namespace Gendarme.Rules.Portability { // the rule does not apply of the entry point returns void // FIXME: entryPoint.ReturnType.ReturnType should not be null with void Main () // either bad unit tests or bug in cecil - if (entry_point.ReturnType.ReturnType == null || entry_point.ReturnType.ReturnType.FullName != "System.Int32") + TypeReference rt = entry_point.ReturnType.ReturnType; + if (rt == null || rt.FullName != "System.Int32") return RuleResult.DoesNotApply; Instruction previous = null; @@ -213,7 +214,8 @@ namespace Gendarme.Rules.Portability { case Code.Call: case Code.Callvirt: MethodReference calledMethod = (MethodReference) current.Operand; - if (calledMethod.Name != "set_ExitCode" && calledMethod.Name != "Exit") + string name = calledMethod.Name; + if ((name != "set_ExitCode") && (name != "Exit")) break; if (calledMethod.DeclaringType.FullName != "System.Environment") break; |