diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/StringIsNullOrEmptyIssue.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/StringIsNullOrEmptyIssue.cs index 1ae791c1ec..9ae3453f0b 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/StringIsNullOrEmptyIssue.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/StringIsNullOrEmptyIssue.cs @@ -58,16 +58,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring } ), // str == "" || str == null - // str.Length == 0 || str == null new BinaryOperatorExpression ( - new Choice { - PatternHelper.CommutativeOperator (new AnyNode ("str"), BinaryOperatorType.Equality, new PrimitiveExpression ("")), - PatternHelper.CommutativeOperator ( - new MemberReferenceExpression (new AnyNode ("str"), "Length"), - BinaryOperatorType.Equality, - new PrimitiveExpression (0) - ) - }, + PatternHelper.CommutativeOperator (new AnyNode ("str"), BinaryOperatorType.Equality, new PrimitiveExpression ("")), BinaryOperatorType.ConditionalOr, PatternHelper.CommutativeOperator(new Backreference ("str"), BinaryOperatorType.Equality, new NullReferenceExpression ()) ) @@ -76,6 +68,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring static readonly Pattern negPattern = new Choice { // str != null && str != "" // str != null && str.Length != 0 + // str != null && str.Length > 0 new BinaryOperatorExpression ( PatternHelper.CommutativeOperator(new AnyNode ("str"), BinaryOperatorType.InEquality, new NullReferenceExpression ()), BinaryOperatorType.ConditionalAnd, @@ -85,20 +78,17 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring new MemberReferenceExpression (new Backreference ("str"), "Length"), BinaryOperatorType.InEquality, new PrimitiveExpression (0) + ), + new BinaryOperatorExpression ( + new MemberReferenceExpression (new Backreference ("str"), "Length"), + BinaryOperatorType.GreaterThan, + new PrimitiveExpression (0) ) } ), // str != "" && str != null - // str.Length != 0 && str != null new BinaryOperatorExpression ( - new Choice { - PatternHelper.CommutativeOperator (new AnyNode ("str"), BinaryOperatorType.InEquality, new PrimitiveExpression ("")), - PatternHelper.CommutativeOperator ( - new MemberReferenceExpression (new AnyNode ("str"), "Length"), - BinaryOperatorType.InEquality, - new PrimitiveExpression (0) - ) - }, + PatternHelper.CommutativeOperator (new AnyNode ("str"), BinaryOperatorType.InEquality, new PrimitiveExpression ("")), BinaryOperatorType.ConditionalAnd, PatternHelper.CommutativeOperator(new Backreference ("str"), BinaryOperatorType.InEquality, new NullReferenceExpression ()) ) diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/StringIsNullOrEmptyInspectorTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/StringIsNullOrEmptyInspectorTests.cs index 28f6431a58..ce2158685a 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/StringIsNullOrEmptyInspectorTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/StringIsNullOrEmptyInspectorTests.cs @@ -438,12 +438,8 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues [TestCase("str == null || str.Length == 0")] [TestCase("str == null || 0 == str.Length")] - [TestCase("str.Length == 0 || str == null")] - [TestCase("0 == str.Length || str == null")] [TestCase("null == str || str.Length == 0")] [TestCase("null == str || 0 == str.Length")] - [TestCase("str.Length == 0 || null == str")] - [TestCase("0 == str.Length || null == str")] public void TestInspectorCaseNL (string expression) { var input = @"class Foo @@ -470,12 +466,10 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues [TestCase("str != null && str.Length != 0")] [TestCase("str != null && 0 != str.Length")] - [TestCase("str.Length != 0 && str != null")] - [TestCase("0 != str.Length && str != null")] + [TestCase("str != null && str.Length > 0")] [TestCase("null != str && str.Length != 0")] [TestCase("null != str && 0 != str.Length")] - [TestCase("str.Length != 0 && null != str")] - [TestCase("0 != str.Length && null != str")] + [TestCase("null != str && str.Length > 0")] public void TestInspectorCaseLN (string expression) { var input = @"class Foo