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

github.com/xamarin/NRefactory.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Krüger <mkrueger@xamarin.com>2014-02-28 12:23:25 +0400
committerMike Krüger <mkrueger@xamarin.com>2014-02-28 12:23:25 +0400
commit61c10b114b1e1ecb858013167cef1c98174b31a7 (patch)
tree5e071749a6e26697e517171b56d8b45a654b3826 /ICSharpCode.NRefactory.CSharp.Refactoring
parent2b5476034d8dcfd18e99b717583bffdd36169b1c (diff)
Categorized some code issues.
Diffstat (limited to 'ICSharpCode.NRefactory.CSharp.Refactoring')
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CallToObjectEqualsViaBaseIssue.cs (renamed from ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CallToObjectEqualsViaBaseIssue.cs)0
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CastExpressionOfIncompatibleTypeIssue.cs (renamed from ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CastExpressionOfIncompatibleTypeIssue.cs)0
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CheckNamespaceIssue.cs (renamed from ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CheckNamespaceIssue.cs)0
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/CS0659OverrideEqualWithoutGetHashCode.cs (renamed from ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CompilerErrors/CS0659OverrideEqualWithoutGetHashCode.cs)0
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/CS1729TypeHasNoConstructorWithNArgumentsIssue.cs (renamed from ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CompilerErrors/CS1729TypeHasNoConstructorWithNArgumentsIssue.cs)0
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/ExpressionIsNeverOfProvidedTypeIssue.cs (renamed from ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/ExpressionIsNeverOfProvidedTypeIssue.cs)0
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/ConstantConditionIssue.cs (renamed from ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/ConstantConditionIssue.cs)0
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/ParameterOnlyAssignedIssue.cs (renamed from ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/VariableOnlyAssignedIssues/ParameterOnlyAssignedIssue.cs)0
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/RedundantAssignmentIssue.cs (renamed from ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/RedundantAssignmentIssue.cs)0
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/UnreachableCodeIssue.cs (renamed from ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/UnreachableCodeIssue.cs)0
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/VariableOnlyAssignedIssue.cs (renamed from ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/VariableOnlyAssignedIssues/VariableOnlyAssignedIssue.cs)0
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/RedundanciesInCode/RedundantArgumentDefaultValueIssue.cs141
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/OptionalParameterCouldBeSkippedIssue.cs175
-rw-r--r--ICSharpCode.NRefactory.CSharp.Refactoring/ICSharpCode.NRefactory.CSharp.Refactoring.csproj23
14 files changed, 152 insertions, 187 deletions
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CallToObjectEqualsViaBaseIssue.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CallToObjectEqualsViaBaseIssue.cs
index ccda1e65..ccda1e65 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CallToObjectEqualsViaBaseIssue.cs
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CallToObjectEqualsViaBaseIssue.cs
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CastExpressionOfIncompatibleTypeIssue.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CastExpressionOfIncompatibleTypeIssue.cs
index 2682a147..2682a147 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CastExpressionOfIncompatibleTypeIssue.cs
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CastExpressionOfIncompatibleTypeIssue.cs
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CheckNamespaceIssue.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CheckNamespaceIssue.cs
index 5b9a86f0..5b9a86f0 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CheckNamespaceIssue.cs
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CheckNamespaceIssue.cs
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CompilerErrors/CS0659OverrideEqualWithoutGetHashCode.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/CS0659OverrideEqualWithoutGetHashCode.cs
index 490ec086..490ec086 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CompilerErrors/CS0659OverrideEqualWithoutGetHashCode.cs
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/CS0659OverrideEqualWithoutGetHashCode.cs
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CompilerErrors/CS1729TypeHasNoConstructorWithNArgumentsIssue.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/CS1729TypeHasNoConstructorWithNArgumentsIssue.cs
index 54d71273..54d71273 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/CompilerErrors/CS1729TypeHasNoConstructorWithNArgumentsIssue.cs
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/CS1729TypeHasNoConstructorWithNArgumentsIssue.cs
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/ExpressionIsNeverOfProvidedTypeIssue.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/ExpressionIsNeverOfProvidedTypeIssue.cs
index e920c4fb..e920c4fb 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/ExpressionIsNeverOfProvidedTypeIssue.cs
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/CompilerErrors/ExpressionIsNeverOfProvidedTypeIssue.cs
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/ConstantConditionIssue.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/ConstantConditionIssue.cs
index c6a901e1..c6a901e1 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/ConstantConditionIssue.cs
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/ConstantConditionIssue.cs
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/VariableOnlyAssignedIssues/ParameterOnlyAssignedIssue.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/ParameterOnlyAssignedIssue.cs
index aa2c9231..aa2c9231 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/VariableOnlyAssignedIssues/ParameterOnlyAssignedIssue.cs
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/ParameterOnlyAssignedIssue.cs
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/RedundantAssignmentIssue.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/RedundantAssignmentIssue.cs
index b1d215c5..b1d215c5 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/RedundantAssignmentIssue.cs
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/RedundantAssignmentIssue.cs
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/UnreachableCodeIssue.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/UnreachableCodeIssue.cs
index 75817fdb..75817fdb 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/UnreachableCodeIssue.cs
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/UnreachableCodeIssue.cs
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/VariableOnlyAssignedIssues/VariableOnlyAssignedIssue.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/VariableOnlyAssignedIssue.cs
index d5897d2b..d5897d2b 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/VariableOnlyAssignedIssues/VariableOnlyAssignedIssue.cs
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Custom/VariableOnlyAssignedIssue.cs
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/RedundanciesInCode/RedundantArgumentDefaultValueIssue.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/RedundanciesInCode/RedundantArgumentDefaultValueIssue.cs
index 2b0907cd..c0269a76 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/RedundanciesInCode/RedundantArgumentDefaultValueIssue.cs
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/RedundanciesInCode/RedundantArgumentDefaultValueIssue.cs
@@ -127,4 +127,145 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
}
}
+
+ /* TODO: Merge:
+[IssueDescription("Optional argument has default value and can be skipped",
+ Description = "Finds calls to functions where optional parameters are used and the passed argument is the same as the default.",
+ Category = IssueCategories.RedundanciesInCode,
+ Severity = Severity.Hint)]
+ public class OptionalParameterCouldBeSkippedIssue : GatherVisitorCodeIssueProvider
+ {
+ protected override IGatherVisitor CreateVisitor(BaseRefactoringContext context)
+ {
+ return new GatherVisitor(context);
+ }
+
+ class GatherVisitor : GatherVisitorBase<OptionalParameterCouldBeSkippedIssue>
+ {
+ static readonly object removeAllRedundantArgumentsKey = new object ();
+
+ public GatherVisitor(BaseRefactoringContext context) : base (context)
+ {
+ }
+
+ public override void VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression)
+ {
+ base.VisitObjectCreateExpression(objectCreateExpression);
+
+ CheckMethodCall(objectCreateExpression, objectCreateExpression.Arguments,
+ (objectCreation, args) => new ObjectCreateExpression(objectCreation.Type.Clone(), args));
+ }
+
+ public override void VisitInvocationExpression(InvocationExpression invocationExpression)
+ {
+ base.VisitInvocationExpression(invocationExpression);
+
+ CheckMethodCall(invocationExpression, invocationExpression.Arguments,
+ (invocation, args) => new InvocationExpression(invocation.Target.Clone(), args));
+ }
+
+ void CheckMethodCall<T> (T node, IEnumerable<Expression> args, Func<T, IEnumerable<Expression>, T> generateReplacement) where T: AstNode
+ {
+ // The first two checks are unnecessary, but eliminates the majority of calls early,
+ // improving performance.
+ var arguments = args.ToArray();
+ if (arguments.Length == 0)
+ return;
+ var lastArg = arguments[arguments.Length - 1];
+ if (!(lastArg is PrimitiveExpression || lastArg is NamedArgumentExpression))
+ return;
+
+ var invocationResolveResult = ctx.Resolve(node) as CSharpInvocationResolveResult;
+ if (invocationResolveResult == null)
+ return;
+
+ string actionMessage = ctx.TranslateString("Remove redundant arguments");
+
+ var redundantArguments = GetRedundantArguments(arguments, invocationResolveResult);
+ var action = new CodeAction(actionMessage, script => {
+ var newArgumentList = arguments
+ .Where(arg => !redundantArguments.Contains(arg))
+ .Select(arg => arg.Clone());
+ var newInvocation = generateReplacement(node, newArgumentList);
+ script.Replace(node, newInvocation);
+ }, node, removeAllRedundantArgumentsKey);
+ var issueMessage = ctx.TranslateString("Argument is identical to the default value");
+ var lastPositionalArgument = redundantArguments.FirstOrDefault(expression => !(expression is NamedArgumentExpression));
+
+ foreach (var argument in redundantArguments) {
+ var localArgument = argument;
+ var actions = new List<CodeAction>();
+ actions.Add(action);
+
+ if (localArgument is NamedArgumentExpression || localArgument == lastPositionalArgument) {
+ var title = ctx.TranslateString("Remove this argument");
+ actions.Add(new CodeAction(title, script => {
+ var newArgumentList = arguments
+ .Where(arg => arg != localArgument)
+ .Select(arg => arg.Clone());
+ var newInvocation = generateReplacement(node, newArgumentList);
+ script.Replace(node, newInvocation);
+ }, node, null));
+ } else {
+ var title = ctx.TranslateString("Remove this and the following positional arguments");
+ actions.Add(new CodeAction(title, script => {
+ var newArgumentList = arguments
+ .Where(arg => arg.StartLocation < localArgument.StartLocation && !(arg is NamedArgumentExpression))
+ .Select(arg => arg.Clone());
+ var newInvocation = generateReplacement(node, newArgumentList);
+ script.Replace(node, newInvocation);
+ }, node, null));
+ }
+
+ AddIssue(new CodeIssue(localArgument, issueMessage, actions) { IssueMarker = IssueMarker.GrayOut });
+ }
+ }
+
+ IList<Expression> GetRedundantArguments(Expression[] arguments, CSharpInvocationResolveResult invocationResolveResult)
+ {
+ var argumentToParameterMap = invocationResolveResult.GetArgumentToParameterMap();
+ var resolvedParameters = invocationResolveResult.Member.Parameters;
+
+ IList<Expression> redundantArguments = new List<Expression>();
+
+ for (int i = arguments.Length - 1; i >= 0; i--) {
+ var parameterIndex = argumentToParameterMap[i];
+ if (parameterIndex == -1)
+ // This particular parameter is an error, but keep trying the other ones
+ continue;
+ var parameter = resolvedParameters[parameterIndex];
+ var argument = arguments[i];
+ if (argument is PrimitiveExpression) {
+ if (parameter.IsParams)
+ // before positional params arguments all optional arguments are needed, otherwise some of the
+ // param arguments will be shifted out of the params into the fixed parameters
+ break;
+ if (!parameter.IsOptional)
+ // There can be no optional parameters preceding a required one
+ break;
+ var argumentResolveResult = ctx.Resolve(argument) as ConstantResolveResult;
+ if (argumentResolveResult == null || parameter.ConstantValue != argumentResolveResult.ConstantValue)
+ // Stop here since any arguments before this one has to be there
+ // to enable the passing of this argument
+ break;
+ redundantArguments.Add(argument);
+ } else if (argument is NamedArgumentExpression) {
+ var expression = ((NamedArgumentExpression)argument).Expression as PrimitiveExpression;
+ if (expression == null)
+ continue;
+ var expressionResolveResult = ctx.Resolve(expression) as ConstantResolveResult;
+ if (expressionResolveResult == null || parameter.ConstantValue != expressionResolveResult.ConstantValue)
+ // continue, since there can still be more arguments that are redundant
+ continue;
+ redundantArguments.Add(argument);
+ } else {
+ // This is a non-constant positional argument => no more redundancies are possible
+ break;
+ }
+ }
+ return redundantArguments;
+ }
+ }
+ }
+*/
} \ No newline at end of file
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/OptionalParameterCouldBeSkippedIssue.cs b/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/OptionalParameterCouldBeSkippedIssue.cs
deleted file mode 100644
index 7599150e..00000000
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Uncategorized/OptionalParameterCouldBeSkippedIssue.cs
+++ /dev/null
@@ -1,175 +0,0 @@
-//
-// OptionalParameterCouldBeSkippedIssue.cs
-//
-// Author:
-// Simon Lindgren <simon.n.lindgren@gmail.com>
-//
-// Copyright (c) 2012 Simon Lindgren
-//
-// 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.Collections.Generic;
-using ICSharpCode.NRefactory.CSharp.Resolver;
-using System.Linq;
-using ICSharpCode.NRefactory.Semantics;
-using ICSharpCode.NRefactory.TypeSystem;
-using System;
-using ICSharpCode.NRefactory.Refactoring;
-
-namespace ICSharpCode.NRefactory.CSharp.Refactoring
-{
- [IssueDescription("Optional argument has default value and can be skipped",
- Description = "Finds calls to functions where optional parameters are used and the passed argument is the same as the default.",
- Category = IssueCategories.RedundanciesInCode,
- Severity = Severity.Hint)]
- public class OptionalParameterCouldBeSkippedIssue : GatherVisitorCodeIssueProvider
- {
- protected override IGatherVisitor CreateVisitor(BaseRefactoringContext context)
- {
- return new GatherVisitor(context);
- }
-
- class GatherVisitor : GatherVisitorBase<OptionalParameterCouldBeSkippedIssue>
- {
- static readonly object removeAllRedundantArgumentsKey = new object ();
-
- public GatherVisitor(BaseRefactoringContext context) : base (context)
- {
- }
-
- public override void VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression)
- {
- base.VisitObjectCreateExpression(objectCreateExpression);
-
- CheckMethodCall(objectCreateExpression, objectCreateExpression.Arguments,
- (objectCreation, args) => new ObjectCreateExpression(objectCreation.Type.Clone(), args));
- }
-
- public override void VisitInvocationExpression(InvocationExpression invocationExpression)
- {
- base.VisitInvocationExpression(invocationExpression);
-
- CheckMethodCall(invocationExpression, invocationExpression.Arguments,
- (invocation, args) => new InvocationExpression(invocation.Target.Clone(), args));
- }
-
- void CheckMethodCall<T> (T node, IEnumerable<Expression> args, Func<T, IEnumerable<Expression>, T> generateReplacement) where T: AstNode
- {
- // The first two checks are unnecessary, but eliminates the majority of calls early,
- // improving performance.
- var arguments = args.ToArray();
- if (arguments.Length == 0)
- return;
- var lastArg = arguments[arguments.Length - 1];
- if (!(lastArg is PrimitiveExpression || lastArg is NamedArgumentExpression))
- return;
-
- var invocationResolveResult = ctx.Resolve(node) as CSharpInvocationResolveResult;
- if (invocationResolveResult == null)
- return;
-
- string actionMessage = ctx.TranslateString("Remove redundant arguments");
-
- var redundantArguments = GetRedundantArguments(arguments, invocationResolveResult);
- var action = new CodeAction(actionMessage, script => {
- var newArgumentList = arguments
- .Where(arg => !redundantArguments.Contains(arg))
- .Select(arg => arg.Clone());
- var newInvocation = generateReplacement(node, newArgumentList);
- script.Replace(node, newInvocation);
- }, node, removeAllRedundantArgumentsKey);
- var issueMessage = ctx.TranslateString("Argument is identical to the default value");
- var lastPositionalArgument = redundantArguments.FirstOrDefault(expression => !(expression is NamedArgumentExpression));
-
- foreach (var argument in redundantArguments) {
- var localArgument = argument;
- var actions = new List<CodeAction>();
- actions.Add(action);
-
- if (localArgument is NamedArgumentExpression || localArgument == lastPositionalArgument) {
- var title = ctx.TranslateString("Remove this argument");
- actions.Add(new CodeAction(title, script => {
- var newArgumentList = arguments
- .Where(arg => arg != localArgument)
- .Select(arg => arg.Clone());
- var newInvocation = generateReplacement(node, newArgumentList);
- script.Replace(node, newInvocation);
- }, node, null));
- } else {
- var title = ctx.TranslateString("Remove this and the following positional arguments");
- actions.Add(new CodeAction(title, script => {
- var newArgumentList = arguments
- .Where(arg => arg.StartLocation < localArgument.StartLocation && !(arg is NamedArgumentExpression))
- .Select(arg => arg.Clone());
- var newInvocation = generateReplacement(node, newArgumentList);
- script.Replace(node, newInvocation);
- }, node, null));
- }
-
- AddIssue(new CodeIssue(localArgument, issueMessage, actions) { IssueMarker = IssueMarker.GrayOut });
- }
- }
-
- IList<Expression> GetRedundantArguments(Expression[] arguments, CSharpInvocationResolveResult invocationResolveResult)
- {
- var argumentToParameterMap = invocationResolveResult.GetArgumentToParameterMap();
- var resolvedParameters = invocationResolveResult.Member.Parameters;
-
- IList<Expression> redundantArguments = new List<Expression>();
-
- for (int i = arguments.Length - 1; i >= 0; i--) {
- var parameterIndex = argumentToParameterMap[i];
- if (parameterIndex == -1)
- // This particular parameter is an error, but keep trying the other ones
- continue;
- var parameter = resolvedParameters[parameterIndex];
- var argument = arguments[i];
- if (argument is PrimitiveExpression) {
- if (parameter.IsParams)
- // before positional params arguments all optional arguments are needed, otherwise some of the
- // param arguments will be shifted out of the params into the fixed parameters
- break;
- if (!parameter.IsOptional)
- // There can be no optional parameters preceding a required one
- break;
- var argumentResolveResult = ctx.Resolve(argument) as ConstantResolveResult;
- if (argumentResolveResult == null || parameter.ConstantValue != argumentResolveResult.ConstantValue)
- // Stop here since any arguments before this one has to be there
- // to enable the passing of this argument
- break;
- redundantArguments.Add(argument);
- } else if (argument is NamedArgumentExpression) {
- var expression = ((NamedArgumentExpression)argument).Expression as PrimitiveExpression;
- if (expression == null)
- continue;
- var expressionResolveResult = ctx.Resolve(expression) as ConstantResolveResult;
- if (expressionResolveResult == null || parameter.ConstantValue != expressionResolveResult.ConstantValue)
- // continue, since there can still be more arguments that are redundant
- continue;
- redundantArguments.Add(argument);
- } else {
- // This is a non-constant positional argument => no more redundancies are possible
- break;
- }
- }
- return redundantArguments;
- }
- }
- }
-}
-
diff --git a/ICSharpCode.NRefactory.CSharp.Refactoring/ICSharpCode.NRefactory.CSharp.Refactoring.csproj b/ICSharpCode.NRefactory.CSharp.Refactoring/ICSharpCode.NRefactory.CSharp.Refactoring.csproj
index 97115ff6..71d8f559 100644
--- a/ICSharpCode.NRefactory.CSharp.Refactoring/ICSharpCode.NRefactory.CSharp.Refactoring.csproj
+++ b/ICSharpCode.NRefactory.CSharp.Refactoring/ICSharpCode.NRefactory.CSharp.Refactoring.csproj
@@ -303,24 +303,13 @@
<Compile Include="CodeIssues\Synced\RedundanciesInDeclaration\RedundantDefaultFieldInitializerIssue.cs" />
<Compile Include="CodeIssues\Synced\RedundanciesInDeclaration\RedundantOverridenMemberIssue.cs" />
<Compile Include="CodeIssues\Synced\RedundanciesInDeclaration\UnusedTypeParameterIssue.cs" />
- <Compile Include="CodeIssues\Uncategorized\CallToObjectEqualsViaBaseIssue.cs" />
- <Compile Include="CodeIssues\Uncategorized\CastExpressionOfIncompatibleTypeIssue.cs" />
- <Compile Include="CodeIssues\Uncategorized\CompilerErrors\CS0659OverrideEqualWithoutGetHashCode.cs" />
- <Compile Include="CodeIssues\Uncategorized\CompilerErrors\CS1729TypeHasNoConstructorWithNArgumentsIssue.cs" />
- <Compile Include="CodeIssues\Uncategorized\ConstantConditionIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\DisposeMethodInNonIDisposableTypeIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\DuplicatedLinqToListOrArrayIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\ExceptionRethrowIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\ExplicitConversionInForEachIssue.cs" />
- <Compile Include="CodeIssues\Uncategorized\ExpressionIsNeverOfProvidedTypeIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\IncorrectCallToObjectGetHashCodeIssue.cs" />
- <Compile Include="CodeIssues\Uncategorized\OptionalParameterCouldBeSkippedIssue.cs" />
- <Compile Include="CodeIssues\Uncategorized\RedundantAssignmentIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\ResultOfAsyncCallShouldNotBeIgnoredIssue.cs" />
- <Compile Include="CodeIssues\Uncategorized\UnreachableCodeIssue.cs" />
<Compile Include="CodeIssues\Uncategorized\UseOfMemberOfNullReference.cs" />
- <Compile Include="CodeIssues\Uncategorized\VariableOnlyAssignedIssues\ParameterOnlyAssignedIssue.cs" />
- <Compile Include="CodeIssues\Uncategorized\VariableOnlyAssignedIssues\VariableOnlyAssignedIssue.cs" />
<Compile Include="CodeActions\AddExceptionDescriptionAction.cs" />
<Compile Include="CodeIssues\Uncategorized\DontUseLinqWhenItsVerboseAndInefficientIssue.cs" />
<Compile Include="CodeActions\ConvertIfStatementToConditionalTernaryExpressionAction.cs" />
@@ -384,7 +373,6 @@
<Compile Include="CodeIssues\Synced\PracticesAndImprovements\UseIsOperatorIssue.cs" />
<Compile Include="CodeIssues\Synced\CodeQuality\FormatStringProblemIssue.cs" />
<Compile Include="CodeIssues\Synced\RedundanciesInCode\RedundantCatchClauseIssue.cs" />
- <Compile Include="CodeIssues\Uncategorized\CheckNamespaceIssue.cs" />
<Compile Include="CodeIssues\Synced\CodeQuality\PossibleMultipleEnumerationIssue.cs" />
<Compile Include="CodeIssues\Synced\RedundanciesInCode\ConditionIsAlwaysTrueOrFalseIssue.cs" />
<Compile Include="CodeIssues\Synced\RedundanciesInDeclaration\UnusedLabelIssue.cs" />
@@ -428,6 +416,17 @@
<Compile Include="CodeIssues\Custom\CompilerErrors\CS0169FieldIsNeverUsedIssue.cs" />
<Compile Include="CodeIssues\Custom\StaticEventSubscriptionIssue.cs" />
<Compile Include="CodeActions\CS1105ExtensionMethodMustBeDeclaredStaticAction.cs" />
+ <Compile Include="CodeIssues\Custom\CompilerErrors\CS0659OverrideEqualWithoutGetHashCode.cs" />
+ <Compile Include="CodeIssues\Custom\CompilerErrors\CS1729TypeHasNoConstructorWithNArgumentsIssue.cs" />
+ <Compile Include="CodeIssues\Custom\ParameterOnlyAssignedIssue.cs" />
+ <Compile Include="CodeIssues\Custom\VariableOnlyAssignedIssue.cs" />
+ <Compile Include="CodeIssues\Custom\CallToObjectEqualsViaBaseIssue.cs" />
+ <Compile Include="CodeIssues\Custom\ConstantConditionIssue.cs" />
+ <Compile Include="CodeIssues\Custom\CheckNamespaceIssue.cs" />
+ <Compile Include="CodeIssues\Custom\CastExpressionOfIncompatibleTypeIssue.cs" />
+ <Compile Include="CodeIssues\Custom\CompilerErrors\ExpressionIsNeverOfProvidedTypeIssue.cs" />
+ <Compile Include="CodeIssues\Custom\RedundantAssignmentIssue.cs" />
+ <Compile Include="CodeIssues\Custom\UnreachableCodeIssue.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>