Browse Source
9d875d3 Bump NRefactory version number to 5.4. ebe00cc ConsistencyCheck: Ensure mscorlib is added to the compilation (MSBuild doesn't return it for .NET 2.0 projects like IKVM) d68853d Fix missing FreezeList() call to DefaultUnresolvedTypeParameter.Freeze(). a71bf19 Merge several bugfixes from SharpDevelop repository to NRefactory. 6856bd1 Remove System.Runtime hack -- type forwarding should handle this case. 17aefe2 Handle blob decoding errors in the type system instead of placing catch-all handlers in random spots. 877394a Mark DefaultAssemblyReference.Corlib as obsolete f70e546 Updated mcs. 7a2614d Fixed null check 48bdfd7 Merge pull request #405 from DavidKarlas/paramBug e6ce1e6 Fixing parameter code completion after using '>' e.g. if(a>b)Method( 6da0a7b Ignored failing unit test. 4d0b4a4 Fixed 'Bug 20110 - [Forms] Autocomplete doesn't work for the Placeholder property'. e5958a8 Fixed another completion bug case. 37368af Fixed completion bug. 67a1d11 Disabled uncategorized/notworking code issues. cf4fc70 Disabled notworking code issue. That's fixed in .NET 4.5 anyways and this code issue was very, very slow. 39bb34a Remap failing system.runtime references to mscorlib. Use case: Reference portable.NET assemblies from non portable .NET code. 44e1ff1 Fixed Bug 20125 - Fails to show abstract method when writing "override" c47e3d1 Fixed little bug in resolver. It incorrectly resolved internal types sometimes. 6c4c6d3 Fixed wrong end location of RedundantAttributeParenthesesIssue. Due to a drawing error in monodevelop that wasn't visible before. 2b69be0 Fixed bug in inconsistent naming tests. 3c9256f Merge pull request #404 from mono-soc-2013/MateY-IndentEngine 4733874 Fixed issue 389. c0aebb7 Fixed issue in ResolveAtLocation. On indexer 'this' the indexer should be resolved. 1c48cd2 Merge pull request #400 from DavidKarlas/parseExpression 242c141 Fixed parser bug when using ParseExpression 9d1cc09 Fixed parser bug. 13b0928 Catches exception for the IsBrowsable extension method. Fixed monodevelop bug https://bugzilla.xamarin.com/show_bug.cgi?id=18706. 3f78bdb Merge pull request #397 from khellang/patch-1 f6e7c08 Update README 0b743ac Merge pull request #396 from Therzok/master 36d6246 Optimize some Linq. 75640bf Merge pull request #395 from Therzok/master 5789870 [CodeIssues] Add simplified versions Math functions. 28d04ae Fixed potential blob reader exception. 22d8bc2 Fixed failing unit tests. e2dced7 Merge branch 'master' of github.com:icsharpcode/NRefactory 705590d Merge pull request #392 from DavidKarlas/paramInfoAnywhere 800296d Merge pull request #393 from DavidKarlas/failRevert 63a63f2 Correcting bad revert. Sometimes it was returing 0 instead of -1. 27590b5 Improved resolving of target method for ParameterInfo so it can be triggered in middle of parameter and not only after '(',',','[' or '<'. 7aef513 Merge pull request #391 from DavidKarlas/revertPull390 a8141ef Reverting Pull #390 2132edc Merge pull request #390 from DavidKarlas/firstParameter b6ccdb9 Always displaying first parameter discription in ParameterInfo tooltippull/507/head
87 changed files with 8124 additions and 5601 deletions
@ -0,0 +1,123 @@ |
|||||||
|
//
|
||||||
|
// ReplaceWithSingleCallToAverageIssue.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Marius Ungureanu <marius.ungureanu@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Xamarin <http://xamarin.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
using System.Linq; |
||||||
|
using ICSharpCode.NRefactory.Semantics; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.NRefactory.PatternMatching; |
||||||
|
using ICSharpCode.NRefactory.Refactoring; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
||||||
|
{ |
||||||
|
[IssueDescription("Replace with single call to Average(...)", |
||||||
|
Description = "Replace with single call to Average(...)", |
||||||
|
Category = IssueCategories.PracticesAndImprovements, |
||||||
|
Severity = Severity.Suggestion, |
||||||
|
AnalysisDisableKeyword = "ReplaceWithSingleCallToAverage")] |
||||||
|
public class ReplaceWithSingleCallToAverageIssue : GatherVisitorCodeIssueProvider |
||||||
|
{ |
||||||
|
static readonly AstNode pattern = |
||||||
|
new InvocationExpression ( |
||||||
|
new MemberReferenceExpression ( |
||||||
|
new NamedNode ("selectInvoke", |
||||||
|
new InvocationExpression ( |
||||||
|
new MemberReferenceExpression (new AnyNode ("target"), "Select"), |
||||||
|
new AnyNode ())), |
||||||
|
Pattern.AnyString)); |
||||||
|
|
||||||
|
protected override IGatherVisitor CreateVisitor(BaseRefactoringContext context) |
||||||
|
{ |
||||||
|
return new GatherVisitor<ReplaceWithSingleCallToAverageIssue>(context, "Average"); |
||||||
|
} |
||||||
|
|
||||||
|
internal class GatherVisitor<T> : GatherVisitorBase<T> where T : GatherVisitorCodeIssueProvider |
||||||
|
{ |
||||||
|
readonly string member; |
||||||
|
|
||||||
|
public GatherVisitor (BaseRefactoringContext ctx, string member) : base (ctx) |
||||||
|
{ |
||||||
|
this.member = member; |
||||||
|
} |
||||||
|
|
||||||
|
public override void VisitInvocationExpression (InvocationExpression invocationExpression) |
||||||
|
{ |
||||||
|
base.VisitInvocationExpression (invocationExpression); |
||||||
|
|
||||||
|
var match = pattern.Match (invocationExpression); |
||||||
|
if (!match.Success) |
||||||
|
return; |
||||||
|
|
||||||
|
var averageResolve = ctx.Resolve (invocationExpression) as InvocationResolveResult; |
||||||
|
if (averageResolve == null || !HasPredicateVersion(averageResolve.Member)) |
||||||
|
return; |
||||||
|
var selectInvoke = match.Get<InvocationExpression> ("selectInvoke").Single (); |
||||||
|
var selectResolve = ctx.Resolve (selectInvoke) as InvocationResolveResult; |
||||||
|
if (selectResolve == null || selectResolve.Member.Name != "Select" || !IsQueryExtensionClass(selectResolve.Member.DeclaringTypeDefinition)) |
||||||
|
return; |
||||||
|
if (selectResolve.Member.Parameters.Count != 2) |
||||||
|
return; |
||||||
|
var predResolve = selectResolve.Member.Parameters [1]; |
||||||
|
if (predResolve.Type.TypeParameterCount != 2) |
||||||
|
return; |
||||||
|
|
||||||
|
AddIssue(new CodeIssue( |
||||||
|
invocationExpression, string.Format(ctx.TranslateString("Redundant Select() call with predicate followed by {0}()"), averageResolve.Member.Name), |
||||||
|
new CodeAction ( |
||||||
|
string.Format(ctx.TranslateString("Replace with single call to '{0}'"), averageResolve.Member.Name), |
||||||
|
script => { |
||||||
|
var arg = selectInvoke.Arguments.Single ().Clone (); |
||||||
|
var target = match.Get<Expression> ("target").Single ().Clone (); |
||||||
|
script.Replace (invocationExpression, new InvocationExpression (new MemberReferenceExpression (target, averageResolve.Member.Name), arg)); |
||||||
|
}, |
||||||
|
invocationExpression |
||||||
|
) |
||||||
|
)); |
||||||
|
} |
||||||
|
|
||||||
|
static bool IsQueryExtensionClass(ITypeDefinition typeDef) |
||||||
|
{ |
||||||
|
if (typeDef == null || typeDef.Namespace != "System.Linq") |
||||||
|
return false; |
||||||
|
switch (typeDef.Name) { |
||||||
|
case "Enumerable": |
||||||
|
case "ParallelEnumerable": |
||||||
|
case "Queryable": |
||||||
|
return true; |
||||||
|
default: |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bool HasPredicateVersion(IParameterizedMember member) |
||||||
|
{ |
||||||
|
if (!IsQueryExtensionClass(member.DeclaringTypeDefinition)) |
||||||
|
return false; |
||||||
|
return member.Name == this.member; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,43 @@ |
|||||||
|
//
|
||||||
|
// ReplaceWithSingleCallToMaxIssue.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Marius Ungureanu <marius.ungureanu@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Xamarin <http://xamarin.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
using ICSharpCode.NRefactory.Refactoring; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
||||||
|
{ |
||||||
|
[IssueDescription("Replace with single call to Max(...)", |
||||||
|
Description = "Replace with single call to Max(...)", |
||||||
|
Category = IssueCategories.PracticesAndImprovements, |
||||||
|
Severity = Severity.Suggestion, |
||||||
|
AnalysisDisableKeyword = "ReplaceWithSingleCallToMax")] |
||||||
|
public class ReplaceWithSingleCallToMaxIssue : GatherVisitorCodeIssueProvider |
||||||
|
{ |
||||||
|
protected override IGatherVisitor CreateVisitor(BaseRefactoringContext context) |
||||||
|
{ |
||||||
|
return new ReplaceWithSingleCallToAverageIssue.GatherVisitor<ReplaceWithSingleCallToMaxIssue>(context, "Max"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,43 @@ |
|||||||
|
//
|
||||||
|
// ReplaceWithSingleCallToMinIssue.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Marius Ungureanu <marius.ungureanu@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Xamarin <http://xamarin.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
using ICSharpCode.NRefactory.Refactoring; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
||||||
|
{ |
||||||
|
[IssueDescription("Replace with single call to Min(...)", |
||||||
|
Description = "Replace with single call to Min(...)", |
||||||
|
Category = IssueCategories.PracticesAndImprovements, |
||||||
|
Severity = Severity.Suggestion, |
||||||
|
AnalysisDisableKeyword = "ReplaceWithSingleCallToMin")] |
||||||
|
public class ReplaceWithSingleCallToMinIssue : GatherVisitorCodeIssueProvider |
||||||
|
{ |
||||||
|
protected override IGatherVisitor CreateVisitor(BaseRefactoringContext context) |
||||||
|
{ |
||||||
|
return new ReplaceWithSingleCallToAverageIssue.GatherVisitor<ReplaceWithSingleCallToMinIssue>(context, "Min"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,43 @@ |
|||||||
|
//
|
||||||
|
// ReplaceWithSingleCallToSumIssue.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Marius Ungureanu <marius.ungureanu@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Xamarin <http://xamarin.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
using ICSharpCode.NRefactory.Refactoring; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
||||||
|
{ |
||||||
|
[IssueDescription("Replace with single call to Sum(...)", |
||||||
|
Description = "Replace with single call to Sum(...)", |
||||||
|
Category = IssueCategories.PracticesAndImprovements, |
||||||
|
Severity = Severity.Suggestion, |
||||||
|
AnalysisDisableKeyword = "ReplaceWithSingleCallToSum")] |
||||||
|
public class ReplaceWithSingleCallToSumIssue : GatherVisitorCodeIssueProvider |
||||||
|
{ |
||||||
|
protected override IGatherVisitor CreateVisitor(BaseRefactoringContext context) |
||||||
|
{ |
||||||
|
return new ReplaceWithSingleCallToAverageIssue.GatherVisitor<ReplaceWithSingleCallToSumIssue>(context, "Sum"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,77 @@ |
|||||||
|
//
|
||||||
|
// ReplaceWithSingleCallToAverageTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Marius Ungureanu <marius.ungureanu@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Xamarin <http://xamarin.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System; |
||||||
|
using NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.CodeActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.CodeIssues |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ReplaceWithSingleCallToAverageIssueTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestSimpleCase() |
||||||
|
{ |
||||||
|
var input = @"using System.Linq;
|
||||||
|
public class CSharpDemo { |
||||||
|
public void Bla () { |
||||||
|
int[] arr; |
||||||
|
var bla = arr.Select (x => x * 2).Average (); |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues(new ReplaceWithSingleCallToAverageIssue(), input, out context); |
||||||
|
Assert.AreEqual(1, issues.Count); |
||||||
|
CheckFix(context, issues, @"using System.Linq;
|
||||||
|
public class CSharpDemo { |
||||||
|
public void Bla () { |
||||||
|
int[] arr; |
||||||
|
var bla = arr.Average (x => x * 2); |
||||||
|
} |
||||||
|
}");
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestDisable() |
||||||
|
{ |
||||||
|
var input = @"using System.Linq;
|
||||||
|
public class CSharpDemo { |
||||||
|
public void Bla () { |
||||||
|
int[] arr; |
||||||
|
// ReSharper disable ReplaceWithSingleCallToAverage
|
||||||
|
var bla = arr.Select (x => x * 2).Average (); |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues(new ReplaceWithSingleCallToAverageIssue(), input, out context); |
||||||
|
Assert.AreEqual(0, issues.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,77 @@ |
|||||||
|
//
|
||||||
|
// ReplaceWithSingleCallToMaxTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Marius Ungureanu <marius.ungureanu@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Xamarin <http://xamarin.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System; |
||||||
|
using NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.CodeActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.CodeIssues |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ReplaceWithSingleCallToMaxIssueTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestSimpleCase() |
||||||
|
{ |
||||||
|
var input = @"using System.Linq;
|
||||||
|
public class CSharpDemo { |
||||||
|
public void Bla () { |
||||||
|
int[] arr; |
||||||
|
var bla = arr.Select (x => x * 2).Max (); |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues(new ReplaceWithSingleCallToMaxIssue(), input, out context); |
||||||
|
Assert.AreEqual(1, issues.Count); |
||||||
|
CheckFix(context, issues, @"using System.Linq;
|
||||||
|
public class CSharpDemo { |
||||||
|
public void Bla () { |
||||||
|
int[] arr; |
||||||
|
var bla = arr.Max (x => x * 2); |
||||||
|
} |
||||||
|
}");
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestDisable() |
||||||
|
{ |
||||||
|
var input = @"using System.Linq;
|
||||||
|
public class CSharpDemo { |
||||||
|
public void Bla () { |
||||||
|
int[] arr; |
||||||
|
// ReSharper disable ReplaceWithSingleCallToMax
|
||||||
|
var bla = arr.Select (x => x * 2).Max (); |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues(new ReplaceWithSingleCallToMaxIssue(), input, out context); |
||||||
|
Assert.AreEqual(0, issues.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,77 @@ |
|||||||
|
//
|
||||||
|
// ReplaceWithSingleCallToMinTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Marius Ungureanu <marius.ungureanu@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Xamarin <http://xamarin.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System; |
||||||
|
using NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.CodeActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.CodeIssues |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ReplaceWithSingleCallToMinIssueTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestSimpleCase() |
||||||
|
{ |
||||||
|
var input = @"using System.Linq;
|
||||||
|
public class CSharpDemo { |
||||||
|
public void Bla () { |
||||||
|
int[] arr; |
||||||
|
var bla = arr.Select (x => x * 2).Min (); |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues(new ReplaceWithSingleCallToMinIssue(), input, out context); |
||||||
|
Assert.AreEqual(1, issues.Count); |
||||||
|
CheckFix(context, issues, @"using System.Linq;
|
||||||
|
public class CSharpDemo { |
||||||
|
public void Bla () { |
||||||
|
int[] arr; |
||||||
|
var bla = arr.Min (x => x * 2); |
||||||
|
} |
||||||
|
}");
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestDisable() |
||||||
|
{ |
||||||
|
var input = @"using System.Linq;
|
||||||
|
public class CSharpDemo { |
||||||
|
public void Bla () { |
||||||
|
int[] arr; |
||||||
|
// ReSharper disable ReplaceWithSingleCallToMin
|
||||||
|
var bla = arr.Select (x => x * 2).Min (); |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues(new ReplaceWithSingleCallToMinIssue(), input, out context); |
||||||
|
Assert.AreEqual(0, issues.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,77 @@ |
|||||||
|
//
|
||||||
|
// ReplaceWithSingleCallToSumTests.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Marius Ungureanu <marius.ungureanu@xamarin.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Xamarin <http://xamarin.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System; |
||||||
|
using NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
using ICSharpCode.NRefactory.CSharp.CodeActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.CodeIssues |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ReplaceWithSingleCallToSumIssueTests : InspectionActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestSimpleCase() |
||||||
|
{ |
||||||
|
var input = @"using System.Linq;
|
||||||
|
public class CSharpDemo { |
||||||
|
public void Bla () { |
||||||
|
int[] arr; |
||||||
|
var bla = arr.Select (x => x * 2).Sum (); |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues(new ReplaceWithSingleCallToSumIssue(), input, out context); |
||||||
|
Assert.AreEqual(1, issues.Count); |
||||||
|
CheckFix(context, issues, @"using System.Linq;
|
||||||
|
public class CSharpDemo { |
||||||
|
public void Bla () { |
||||||
|
int[] arr; |
||||||
|
var bla = arr.Sum (x => x * 2); |
||||||
|
} |
||||||
|
}");
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestDisable() |
||||||
|
{ |
||||||
|
var input = @"using System.Linq;
|
||||||
|
public class CSharpDemo { |
||||||
|
public void Bla () { |
||||||
|
int[] arr; |
||||||
|
// ReSharper disable ReplaceWithSingleCallToSum
|
||||||
|
var bla = arr.Select (x => x * 2).Sum (); |
||||||
|
} |
||||||
|
}";
|
||||||
|
|
||||||
|
TestRefactoringContext context; |
||||||
|
var issues = GetIssues(new ReplaceWithSingleCallToSumIssue(), input, out context); |
||||||
|
Assert.AreEqual(0, issues.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue