Browse Source

Code actions can now be bound to an ast node.

pull/32/merge
Mike Krüger 12 years ago
parent
commit
925de642b5
  1. 20
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeAction.cs
  2. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/AddAnotherAccessorAction.cs
  3. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/AddCatchTypeAction.cs
  4. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/AddUsingAction.cs
  5. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CheckIfParameterIsNullAction.cs
  6. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertAnonymousDelegateToLambdaAction.cs
  7. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertAsToCastAction.cs
  8. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertCastToAsAction.cs
  9. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertConditionalToIfAction.cs
  10. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertDecToHexAction.cs
  11. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertExplicitToImplicitImplementationAction.cs
  12. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertForeachToForAction.cs
  13. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertHexToDecAction.cs
  14. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertIfToConditionalAction.cs
  15. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertIfToSwitchAction.cs
  16. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertImplicitToExplicitImplementationAction.cs
  17. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertLambdaBodyExpressionToStatementAction.cs
  18. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertLambdaBodyStatementToExpressionAction.cs
  19. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertLambdaToAnonymousDelegateAction.cs
  20. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertSwitchToIfAction.cs
  21. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertToInitializer/ConvertInitializerToExplicitInitializationsAction.cs
  22. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertToInitializer/ConvertToInitializerAction.cs
  23. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateBackingStoreAction.cs
  24. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateClassDeclarationAction.cs
  25. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateConstructorDeclarationAction.cs
  26. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateCustomEventImplementationAction.cs
  27. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateDelegateAction.cs
  28. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateEnumValue.cs
  29. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateEventInvocatorAction.cs
  30. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateFieldAction.cs
  31. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateIndexerAction.cs
  32. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateLocalVariableAction.cs
  33. 7
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateMethodDeclarationAction.cs
  34. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateOverloadWithoutParameterAction.cs
  35. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreatePropertyAction.cs
  36. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/DeclareLocalVariableAction.cs
  37. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtensionMethodInvocationToStaticMethodInvocationAction.cs
  38. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractAnonymousMethodAction.cs
  39. 186
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractFieldAction.cs
  40. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractMethod/ExtractMethodAction.cs
  41. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/FlipOperatorArgumentsAction.cs
  42. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/GenerateGetterAction.cs
  43. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/GeneratePropertyAction.cs
  44. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/GenerateSwitchLabelsAction.cs
  45. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ImplementAbstractMembersAction.cs
  46. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ImplementInterfaceAction.cs
  47. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ImplementInterfaceExplicitAction.cs
  48. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/InlineLocalVariableAction.cs
  49. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/InsertAnonymousMethodSignatureAction.cs
  50. 8
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/IntroduceConstantAction.cs
  51. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/IntroduceFormatItemAction.cs
  52. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/InvertIfAction.cs
  53. 6
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/IterateViaForeachAction.cs
  54. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/JoinDeclarationAndAssignmentAction.cs
  55. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/JoinStringAction.cs
  56. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/MergeNestedIfAction.cs
  57. 6
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/MoveToOuterScopeAction.cs
  58. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/NegateRelationalExpressionAction.cs
  59. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/PutInsideUsingAction.cs
  60. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/RemoveBackingStoreAction.cs
  61. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/RemoveBracesAction.cs
  62. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/RemoveRedundantCatchTypeAction.cs
  63. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/RemoveRegionAction.cs
  64. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ReplaceEmptyStringAction.cs
  65. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/SortUsingsAction.cs
  66. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/SplitDeclarationAndAssignmentAction.cs
  67. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/SplitDeclarationListAction.cs
  68. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/SplitStringAction.cs
  69. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/StaticMethodInvocationToExtensionMethodInvocationAction.cs
  70. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/UseExplicitTypeAction.cs
  71. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/UseStringFormatAction.cs
  72. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/UseVarKeywordAction.cs
  73. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/AccessToClosureIssues/AccessToModifiedClosureIssue.cs
  74. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/AssignmentMadeToSameVariableIssue.cs
  75. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/CallToObjectEqualsViaBaseIssue.cs
  76. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/CompilerErrors/CS0127ReturnMustNotBeFollowedByAnyExpression.cs
  77. 9
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ConstantConditionIssue.cs
  78. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ExceptionRethrowIssue.cs
  79. 6
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ExplicitConversionInForEachIssue.cs
  80. 9
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ExpressionIsAlwaysOfProvidedTypeIssue.cs
  81. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/GatherVisitorBase.cs
  82. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/IdenticalConditionalBranchIssue.cs
  83. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/InconsistentNamingIssue/InconsistentNamingIssue.cs
  84. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/IncorrectExceptionParameterOrderingIssue.cs
  85. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/MissingStringComparisonIssue.cs
  86. 6
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/OptionalParameterCouldBeSkippedIssue.cs
  87. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ParameterCanBeDemotedIssue/ParameterCanBeDemotedIssue.cs
  88. 10
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/RedundantCatchIssue.cs
  89. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ReferenceEqualsCalledWithValueTypeIssue.cs
  90. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ReferenceToStaticMemberViaDerivedTypeIssue.cs
  91. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ThreadStaticOnInstanceFieldIssue.cs
  92. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/UnreachableCodeIssue.cs
  93. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/VariableDeclaredInWideScopeIssue.cs
  94. 12
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

20
ICSharpCode.NRefactory.CSharp/Refactoring/CodeAction.cs

@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -48,6 +48,15 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
private set;
}
/// <summary>
/// Gets the ast node the action acts upon.
/// Note: τhis value may be null if the action isn't specific to a single node.
/// </summary>
public AstNode AstNode {
get;
private set;
}
/// <summary>
/// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction"/> class.
/// </summary>
@ -57,16 +66,17 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -57,16 +66,17 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
/// <param name='action'>
/// The code transformation.
/// </param>
public CodeAction (string description, Action<Script> action)
public CodeAction (string description, Action<Script> action, AstNode astNode)
{
if (action == null) {
if (action == null)
throw new ArgumentNullException ("action");
}
if (description == null) {
if (description == null)
throw new ArgumentNullException ("description");
}
if (astNode == null)
throw new ArgumentNullException ("astNode");
Description = description;
Run = action;
AstNode = astNode;
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/AddAnotherAccessorAction.cs

@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (accessorStatement != null)
script.Select(accessorStatement);
script.FormatText(pdecl);
});
}, pdecl.NameToken);
}
static Statement BuildAccessorStatement (RefactoringContext context, PropertyDeclaration pdecl)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/AddCatchTypeAction.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
Body = catchClause.Body.Clone() as BlockStatement
});
script.Select(newType);
});
}, catchClause);
}
#endregion

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/AddUsingAction.cs

@ -85,7 +85,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -85,7 +85,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
CodeAction NewUsingAction(RefactoringContext context, AstNode node, string ns)
{
return new CodeAction("using " + ns + ";", s => UsingHelper.InsertUsingAndRemoveRedundantNamespaceUsage(context, s, ns));
return new CodeAction("using " + ns + ";", s => UsingHelper.InsertUsingAndRemoveRedundantNamespaceUsage(context, s, ns), node);
}
CodeAction ReplaceWithFullTypeNameAction(RefactoringContext context, AstNode node, ITypeDefinition typeDefinition)
@ -95,7 +95,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -95,7 +95,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
foreach (var typeArg in node.GetChildrenByRole(Roles.TypeArgument)) {
astType.AddChild(typeArg.Clone(), Roles.TypeArgument);
}
return new CodeAction(textWithoutGenerics, s => s.Replace(node, astType));
return new CodeAction(textWithoutGenerics, s => s.Replace(node, astType), node);
}
IEnumerable<CodeAction> GetActionsForExtensionMethodInvocation(RefactoringContext context, InvocationExpression invocation)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CheckIfParameterIsNullAction.cs

@ -55,7 +55,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -55,7 +55,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
TrueStatement = new ThrowStatement (new ObjectCreateExpression (context.CreateShortType("System", "ArgumentNullException"), new PrimitiveExpression (parameter.Name)))
};
script.AddTo(bodyStatement, statement);
});
}, parameter);
}
static bool HasNullCheck (ParameterDeclaration parameter)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertAnonymousDelegateToLambdaAction.cs

@ -53,7 +53,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -53,7 +53,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
}
script.Replace(node, lambda);
});
}, node);
}
#endregion
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertAsToCastAction.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
castExpr.AcceptVisitor (insertParentheses);
script.Replace (node, castExpr);
}
});
}, node);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertCastToAsAction.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -57,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
} else {
script.Replace (node, asExpr);
}
});
}, node);
}
return null;
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertConditionalToIfAction.cs

@ -114,7 +114,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -114,7 +114,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
foreach (var node in getReplacement (conditionalExpr))
script.InsertBefore (originalStatement, node);
script.Remove (originalStatement);
});
}, conditionalExpr);
}
static ConditionalExpression GetConditionalExpression (Expression expr)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertDecToHexAction.cs

@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return new CodeAction(context.TranslateString("Convert dec to hex"), script => {
script.Replace(pexpr, new PrimitiveExpression (value, string.Format("0x{0:x}", value)));
});
}, pexpr);
}
}
}

3
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertExplicitToImplicitImplementationAction.cs

@ -63,7 +63,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -63,7 +63,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
implicitImpl.Modifiers |= Modifiers.Public;
script.Replace (node, implicitImpl);
});
},
node.NameToken);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertForeachToForAction.cs

@ -116,7 +116,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -116,7 +116,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.InsertBefore (foreachStatement, declarationStatement);
script.Replace (foreachStatement, forStatement);
script.Link (initializer.Variables.First ().NameToken, id1, id2, id3);
});
}, foreachStatement);
}
static string GetCountProperty(IType type)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertHexToDecAction.cs

@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -47,7 +47,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return new CodeAction(context.TranslateString("Convert hex to dec"), script => {
script.Replace(pexpr, new PrimitiveExpression (pexpr.Value));
});
}, pexpr);
}
}
}

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertIfToConditionalAction.cs

@ -118,7 +118,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -118,7 +118,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
// remove implicit false statement
if (falseStatement != ifElseStatement.FalseStatement)
script.Remove (falseStatement);
});
},
ifElseStatement
);
}
static T GetNode<T> (Statement node, Func<Statement, T> extract)

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertIfToSwitchAction.cs

@ -54,7 +54,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -54,7 +54,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var switchStatement = new SwitchStatement { Expression = switchExpr.Clone () };
switchStatement.SwitchSections.AddRange (switchSections);
script.Replace (node, switchStatement);
});
},
node
);
}
static Expression GetSwitchExpression (RefactoringContext context, Expression expr)

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertImplicitToExplicitImplementationAction.cs

@ -54,7 +54,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -54,7 +54,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var implementedInterface = method.ImplementedInterfaceMembers [0].DeclaringType;
explicitImpl.PrivateImplementationType = context.CreateShortType (implementedInterface);
script.Replace (node, explicitImpl);
});
},
node.NameToken
);
}
}
}

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertLambdaBodyExpressionToStatementAction.cs

@ -49,7 +49,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -49,7 +49,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
body.Add (new ExpressionStatement (bodyExpr.Clone ()));
}
script.Replace (bodyExpr, body);
});
},
node
);
}
static bool RequireReturnStatement (RefactoringContext context, LambdaExpression lambda)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertLambdaBodyStatementToExpressionAction.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -51,7 +51,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
return new CodeAction (context.TranslateString ("Convert to lambda expression"),
script => script.Replace (blockStatement, expr.Clone ()));
script => script.Replace (blockStatement, expr.Clone ()), node);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertLambdaToAnonymousDelegateAction.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -57,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
var method = new AnonymousMethodExpression (newBody, GetParameters(lambdaResolveResult.Parameters, context));
script.Replace(node, method);
});
}, node);
}
#endregion

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertSwitchToIfAction.cs

@ -84,7 +84,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -84,7 +84,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
script.Replace (node, ifStatement);
script.FormatText (ifStatement);
});
}, node);
}
static Expression CollectCondition(Expression switchExpr, AstNodeCollection<CaseLabel> caseLabels)

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertToInitializer/ConvertInitializerToExplicitInitializationsAction.cs

@ -71,7 +71,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -71,7 +71,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.InsertBefore(declaration, statement);
}
script.Replace(variableInitializer.Initializer, finalExpression);
});
}, variableInitializer);
}
return null;
}
@ -96,7 +96,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -96,7 +96,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.InsertBefore(expressionStatement, statement);
}
script.Replace(assignmentExpression.Right, finalExpression);
});
}, assignmentExpression);
}
return null;
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertToInitializer/ConvertToInitializerAction.cs

@ -101,7 +101,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -101,7 +101,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
foreach (var statement in toRemove)
script.Remove(statement);
script.Replace(oldNode, replacementNode);
});
}, oldNode);
}
#endregion
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateBackingStoreAction.cs

@ -71,7 +71,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -71,7 +71,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Replace (property, newProperty);
script.InsertBefore (property, backingStore);
script.Link (initializer, id1, id2);
});
}, property.NameToken);
}
}
}

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateClassDeclarationAction.cs

@ -78,7 +78,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -78,7 +78,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
yield return new CodeAction(message, script => {
script.CreateNewType(CreateType(context, service, node, classType));
});
}, node);
if (node.Parent is TypeDeclaration || classType != ClassType.Class)
yield break;
@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
Script.InsertPosition.Before,
CreateType(context, service, node, classType)
);
});
}, node);
}
static void ModifyClassTypeBasedOnTypeGuessing(RefactoringContext context, AstNode node, ref ClassType classType)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateConstructorDeclarationAction.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -57,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
resolveResult.Member.DeclaringTypeDefinition,
decl
);
});
}, createExpression);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateCustomEventImplementationAction.cs

@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.InsertBefore (eventDecl, newEventDecl);
}
script.Replace (eventDecl, e);
});
}, node.NameToken);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateDelegateAction.cs

@ -50,7 +50,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -50,7 +50,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return new CodeAction(context.TranslateString("Create delegate"), script => {
script.CreateNewType(CreateType(context, node));
});
}, node);
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateEnumValue.cs

@ -77,7 +77,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -77,7 +77,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
Name = propertyName
};
script.InsertWithCursor(context.TranslateString("Create enum value"), guessedType.GetDefinition (), decl);
});
}, expr);
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateEventInvocatorAction.cs

@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
Script.InsertPosition.After,
methodDeclaration
);
});
}, initializer);
}

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateFieldAction.cs

@ -83,14 +83,14 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -83,14 +83,14 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
// }
yield return new CodeAction(context.TranslateString("Create field"), script => {
var decl = new FieldDeclaration() {
var decl = new FieldDeclaration {
ReturnType = guessedType,
Variables = { new VariableInitializer(propertyName) }
};
if (isStatic)
decl.Modifiers |= Modifiers.Static;
script.InsertWithCursor(context.TranslateString("Create field"), Script.InsertPosition.Before, decl);
});
}, expr);
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateIndexerAction.cs

@ -95,7 +95,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -95,7 +95,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
script.InsertWithCursor(context.TranslateString("Create indexer"), Script.InsertPosition.Before, decl);
});
}, indexer);
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateLocalVariableAction.cs

@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -66,7 +66,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
} else {
script.InsertBefore(statement, decl);
}
});
}, identifier);
}
}
}

7
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateMethodDeclarationAction.cs

@ -87,6 +87,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -87,6 +87,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return CreateAction(
context,
invocation,
methodName,
context.CreateShortType(invocationMethod.ReturnType),
invocationMethod.Parameters.Select(parameter => new ParameterDeclaration(context.CreateShortType(parameter.Type), parameter.Name) {
@ -119,6 +120,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -119,6 +120,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return CreateAction(
context,
identifier,
methodName,
context.CreateShortType(invocationMethod.ReturnType),
invocationMethod.Parameters.Select(parameter => new ParameterDeclaration(context.CreateShortType(parameter.Type), parameter.Name) {
@ -168,6 +170,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -168,6 +170,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return CreateAction(
context,
invocation,
methodName,
guessedType,
GenerateParameters(context, invocation.Arguments),
@ -187,7 +190,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -187,7 +190,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
return ParameterModifier.None;
}
static CodeAction CreateAction(RefactoringContext context, string methodName, AstType returnType, IEnumerable<ParameterDeclaration> parameters, bool createInOtherType, bool isStatic, ResolveResult targetResolveResult)
static CodeAction CreateAction(RefactoringContext context, AstNode createFromNode, string methodName, AstType returnType, IEnumerable<ParameterDeclaration> parameters, bool createInOtherType, bool isStatic, ResolveResult targetResolveResult)
{
return new CodeAction(context.TranslateString("Create method"), script => {
var decl = new MethodDeclaration() {
@ -215,7 +218,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -215,7 +218,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
script.InsertWithCursor(context.TranslateString("Create method"), Script.InsertPosition.Before, decl);
});
}, createFromNode);
}
public static IEnumerable<ParameterDeclaration> GenerateParameters(RefactoringContext context, IEnumerable<Expression> arguments)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateOverloadWithoutParameterAction.cs

@ -84,7 +84,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -84,7 +84,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
//if (node.ParameterModifier != ParameterModifier.Out)
// script.Link (defaultExpr);
});
}, node);
}
static Expression GetArgumentExpression(ParameterDeclaration parameter)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreatePropertyAction.cs

@ -112,7 +112,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -112,7 +112,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.InsertWithCursor(context.TranslateString("Create property"), Script.InsertPosition.Before, decl);
});
}, identifier);
}
internal static string GetPropertyName(Expression expr)

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/DeclareLocalVariableAction.cs

@ -78,7 +78,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -78,7 +78,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Replace(replaceNode, identifierExpression);
script.Link(varDecl.Variables.First().NameToken, identifierExpression);
}
});
}, expr);
if (visitor.Matches.Count > 1) {
yield return new CodeAction(string.Format(context.TranslateString("Declare local variable (replace '{0}' occurrences)"), visitor.Matches.Count), script => {
@ -112,7 +112,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -112,7 +112,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Replace(visitor.Matches [i], identifierExpression);
}
script.Link(linkedNodes.ToArray ());
});
}, expr);
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtensionMethodInvocationToStaticMethodInvocationAction.cs

@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (invocationRR.IsExtensionMethodInvocation)
yield return new CodeAction(context.TranslateString("Convert to call to static method"), script => {
script.Replace(invocation, ToStaticMethodInvocation(invocation, memberReference, invocationRR));
});
}, invocation);
}
#endregion

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractAnonymousMethodAction.cs

@ -82,7 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -82,7 +82,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Replace (node, identifier);
script.InsertBefore (node.GetParent<EntityDeclaration> (), method);
script.Link (method.NameToken, identifier);
});
}, method.NameToken);
}
static MethodDeclaration GetMethod (RefactoringContext context, LambdaResolveResult lambda, BlockStatement body,

186
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractFieldAction.cs

@ -1,93 +1,93 @@ @@ -1,93 +1,93 @@
//
// ExtractFieldAction.cs
//
// Author:
// Nieve <>
//
// Copyright (c) 2012 Nieve
//
// 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 System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory.PatternMatching;
using Mono.CSharp;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
[ContextAction("Extract field", Description = "Extracts a field from a local variable declaration.")]
public class ExtractFieldAction : ICodeActionProvider
{
public IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
//TODO: implement variable assignment & ctor param
var varInit = context.GetNode<VariableInitializer>();
if (varInit != null) {
AstType type = varInit.GetPrevNode() as AstType;
if (type == null) yield break;
if (varInit.Parent is FieldDeclaration) yield break;
if (CannotExtractField(varInit)) yield break;
yield return new CodeAction(context.TranslateString("Assign to new field"), s=>{
var name = varInit.Name;
FieldDeclaration field = new FieldDeclaration(){
ReturnType = type.Clone(),
Variables = { new VariableInitializer(name) }
};
AstNode nodeToRemove = RemoveDeclaration(varInit) ? varInit.Parent : type;
s.Remove(nodeToRemove, true);
s.InsertWithCursor(context.TranslateString("Insert new field"),Script.InsertPosition.Before,field);
s.FormatText(varInit.Parent);
});
}
var idntf = context.GetNode<Identifier>();
if (idntf == null) yield break;
var paramDec = idntf.Parent as ParameterDeclaration;
if (paramDec != null) {
var ctor = paramDec.Parent as ConstructorDeclaration;
if (ctor == null) yield break;
MemberReferenceExpression thisField = new MemberReferenceExpression(new ThisReferenceExpression(), idntf.Name, new AstType[]{});
var assign = new AssignmentExpression(thisField, AssignmentOperatorType.Assign, new IdentifierExpression(idntf.Name));
var statement = new ExpressionStatement(assign);
var type = (idntf.GetPrevNode() as AstType).Clone();
FieldDeclaration field = new FieldDeclaration(){
ReturnType = type.Clone(),
Variables = { new VariableInitializer(idntf.Name) }
};
yield return new CodeAction(context.TranslateString("Assign to new field"), s=>{
s.InsertWithCursor(context.TranslateString("Insert new field"),Script.InsertPosition.Before,field);
s.AddTo(ctor.Body, statement);
});
}
}
static bool RemoveDeclaration (VariableInitializer varInit){
var result = varInit.Parent as VariableDeclarationStatement;
return result.Variables.First ().Initializer.IsNull;
}
static bool CannotExtractField (VariableInitializer varInit)
{
var result = varInit.Parent as VariableDeclarationStatement;
return result == null || result.Variables.Count != 1;
}
}
}
//
// ExtractFieldAction.cs
//
// Author:
// Nieve <>
//
// Copyright (c) 2012 Nieve
//
// 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 System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory.PatternMatching;
using Mono.CSharp;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
[ContextAction("Extract field", Description = "Extracts a field from a local variable declaration.")]
public class ExtractFieldAction : ICodeActionProvider
{
public IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
//TODO: implement variable assignment & ctor param
var varInit = context.GetNode<VariableInitializer>();
if (varInit != null) {
AstType type = varInit.GetPrevNode() as AstType;
if (type == null) yield break;
if (varInit.Parent is FieldDeclaration) yield break;
if (CannotExtractField(varInit)) yield break;
yield return new CodeAction(context.TranslateString("Assign to new field"), s=>{
var name = varInit.Name;
FieldDeclaration field = new FieldDeclaration(){
ReturnType = type.Clone(),
Variables = { new VariableInitializer(name) }
};
AstNode nodeToRemove = RemoveDeclaration(varInit) ? varInit.Parent : type;
s.Remove(nodeToRemove, true);
s.InsertWithCursor(context.TranslateString("Insert new field"),Script.InsertPosition.Before,field);
s.FormatText(varInit.Parent);
}, varInit);
}
var idntf = context.GetNode<Identifier>();
if (idntf == null) yield break;
var paramDec = idntf.Parent as ParameterDeclaration;
if (paramDec != null) {
var ctor = paramDec.Parent as ConstructorDeclaration;
if (ctor == null) yield break;
MemberReferenceExpression thisField = new MemberReferenceExpression(new ThisReferenceExpression(), idntf.Name, new AstType[]{});
var assign = new AssignmentExpression(thisField, AssignmentOperatorType.Assign, new IdentifierExpression(idntf.Name));
var statement = new ExpressionStatement(assign);
var type = (idntf.GetPrevNode() as AstType).Clone();
FieldDeclaration field = new FieldDeclaration(){
ReturnType = type.Clone(),
Variables = { new VariableInitializer(idntf.Name) }
};
yield return new CodeAction(context.TranslateString("Assign to new field"), s=>{
s.InsertWithCursor(context.TranslateString("Insert new field"),Script.InsertPosition.Before,field);
s.AddTo(ctor.Body, statement);
}, paramDec);
}
}
static bool RemoveDeclaration (VariableInitializer varInit){
var result = varInit.Parent as VariableDeclarationStatement;
return result.Variables.First ().Initializer.IsNull;
}
static bool CannotExtractField (VariableInitializer varInit)
{
var result = varInit.Parent as VariableDeclarationStatement;
return result == null || result.Variables.Count != 1;
}
}
}

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractMethod/ExtractMethodAction.cs

@ -112,7 +112,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod @@ -112,7 +112,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod
} else {
task.ContinueWith (replaceStatements, TaskScheduler.FromCurrentSynchronizationContext ());
}
});
}, null);
}
CodeAction CreateFromStatements(RefactoringContext context, List<AstNode> statements)
@ -225,7 +225,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod @@ -225,7 +225,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod
} else {
task.ContinueWith (replaceStatements, TaskScheduler.FromCurrentSynchronizationContext ());
}
});
}, null);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/FlipOperatorArgumentsAction.cs

@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return new CodeAction(string.Format(context.TranslateString("Flip '{0}' operator arguments"), binop.OperatorToken.GetText()), script => {
script.Replace(binop.Left, binop.Right.Clone());
script.Replace(binop.Right, binop.Left.Clone());
});
}, binop.OperatorToken);
}
public static BinaryOperatorExpression GetBinaryOperatorExpression (RefactoringContext context)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/GenerateGetterAction.cs

@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
context.TranslateString("Create getter"),
Script.InsertPosition.After,
GeneratePropertyDeclaration(context, field, initializer));
});
}, initializer);
}
static PropertyDeclaration GeneratePropertyDeclaration (RefactoringContext context, FieldDeclaration field, VariableInitializer initializer)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/GeneratePropertyAction.cs

@ -65,7 +65,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -65,7 +65,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.InsertWithCursor(
context.TranslateString("Create property"),
Script.InsertPosition.After, GeneratePropertyDeclaration(context, field, fieldName));
});
}, initializer);
}
static PropertyDeclaration GeneratePropertyDeclaration (RefactoringContext context, FieldDeclaration field, string fieldName)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/GenerateSwitchLabelsAction.cs

@ -72,7 +72,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -72,7 +72,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
});
script.Replace(switchStatement, newSwitch);
});
}, switchStatement);
}
static SwitchStatement GetSwitchStatement (RefactoringContext context)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ImplementAbstractMembersAction.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
return entity;
})
);
});
}, type);
}
public static List<IMember> CollectMembersToImplement(ITypeDefinition implementingType, IType abstractType)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ImplementInterfaceAction.cs

@ -58,7 +58,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -58,7 +58,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
state.CurrentTypeDefinition,
GenerateImplementation(context, toImplement)
);
});
}, type);
}
public static IEnumerable<AstNode> GenerateImplementation(RefactoringContext context, IEnumerable<Tuple<IMember, bool>> toImplement)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ImplementInterfaceExplicitAction.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
state.CurrentTypeDefinition,
ImplementInterfaceAction.GenerateImplementation (context, toImplement.Select (t => Tuple.Create (t.Item1, true)))
);
});
}, type);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/InlineLocalVariableAction.cs

@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return new CodeAction(context.TranslateString("Inline local variable"), script => {
refFinder.FindLocalReferences(resolveResult.Variable, context.UnresolvedFile, unit, context.Compilation, (n, r) => script.Replace(n, AddParensIfRequired (n, initializer.Initializer.Clone())), default(CancellationToken));
script.Remove(node);
});
}, initializer);
}
public static bool RequiresParens(AstNode replaceNode, AstNode replaceWithNode)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/InsertAnonymousMethodSignatureAction.cs

@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -60,7 +60,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
sb.Append(")");
script.InsertText(context.GetOffset(anonymousMethodExpression.DelegateToken.EndLocation), sb.ToString());
});
}, anonymousMethodExpression);
}
static AnonymousMethodExpression GetAnonymousMethodExpression (RefactoringContext context, out IType delegateType)

8
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/IntroduceConstantAction.cs

@ -68,7 +68,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -68,7 +68,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var variableUsage = new IdentifierExpression(name);
script.Replace(pexpr, variableUsage);
script.Link(initializer.NameToken, variableUsage);
});
}, pexpr);
yield return new CodeAction(context.TranslateString("Create constant field"), script => {
string name = CreateMethodDeclarationAction.CreateBaseName(pexpr, resolveResult.Type);
@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Replace(pexpr, variableUsage);
// script.Link(initializer.NameToken, variableUsage);
script.InsertWithCursor(context.TranslateString("Create constant"), Script.InsertPosition.Before, decl);
});
}, pexpr);
if (visitor.Matches.Count > 1) {
yield return new CodeAction(string.Format(context.TranslateString("Create local constant (replace '{0}' occurrences)"), visitor.Matches.Count), script => {
@ -114,7 +114,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -114,7 +114,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Replace(visitor.Matches [i], identifierExpression);
}
script.Link(linkedNodes.ToArray ());
});
}, pexpr);
yield return new CodeAction(string.Format(context.TranslateString("Create constant field (replace '{0}' occurrences)"), visitor.Matches.Count), script => {
string name = CreateMethodDeclarationAction.CreateBaseName(pexpr, resolveResult.Type);
@ -138,7 +138,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -138,7 +138,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Replace(visitor.Matches [i], identifierExpression);
}
script.InsertWithCursor(context.TranslateString("Create constant"), Script.InsertPosition.Before, decl);
});
}, pexpr);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/IntroduceFormatItemAction.cs

@ -74,7 +74,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -74,7 +74,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Replace(pexpr, newInvocation);
script.Select(arg);
});
}, pexpr);
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/InvertIfAction.cs

@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -48,7 +48,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Replace(ifStatement.TrueStatement, ifStatement.FalseStatement.Clone());
script.Replace(ifStatement.FalseStatement, ifStatement.TrueStatement.Clone());
script.FormatText(ifStatement);
});
}, ifStatement);
}
static IfElseStatement GetIfElseStatement (RefactoringContext context)

6
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/IterateViaForeachAction.cs

@ -76,7 +76,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -76,7 +76,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.InsertAfter(anchorNode, iterator);
script.FormatText(usingStatement.EmbeddedStatement);
}
});
}, initializer);
}
CodeAction ActionFromVariableInitializer(RefactoringContext context)
@ -94,7 +94,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -94,7 +94,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
return new CodeAction(context.TranslateString("Iterate via foreach"), script => {
var iterator = MakeForeach(new IdentifierExpression(initializer.Name), elementType, context);
script.InsertAfter(context.GetNode<Statement>(), iterator);
});
}, initializer);
}
CodeAction ActionFromExpressionStatement(RefactoringContext context)
@ -117,7 +117,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -117,7 +117,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Replace(expressionStatement, iterator);
else
script.InsertAfter(expressionStatement, iterator);
});
}, expression);
}
static ForeachStatement MakeForeach(Expression node, IType type, RefactoringContext context)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/JoinDeclarationAndAssignmentAction.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -57,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
newVariableDecl.Variables.Add ((VariableInitializer) variable.Clone ());
script.Replace (variableDecl, newVariableDecl);
}
});
}, node.NameToken);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/JoinStringAction.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var start = context.GetOffset (left.EndLocation) - 1;
var end = context.GetOffset (right.StartLocation) + (isLeftVerbatim ? 2 : 1);
script.RemoveText (start, end - start);
});
}, node.OperatorToken);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/MergeNestedIfAction.cs

@ -63,7 +63,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -63,7 +63,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
};
mergedIfStatement.Condition.AcceptVisitor (insertParenthesesVisitor);
script.Replace (outerIfStatement, mergedIfStatement);
});
}, node);
}
static IfElseStatement GetOuterIfStatement (IfElseStatement node)

6
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/MoveToOuterScopeAction.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return new CodeAction(context.TranslateString("Move declaration to outer scope"), script => {
script.Remove(variableDeclaration);
script.InsertBefore(entryNode, variableDeclaration.Clone());
});
}, variableDeclaration);
}
}
@ -73,7 +73,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -73,7 +73,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Remove(declaration);
var outerDeclaration = new VariableDeclarationStatement(type, name, initializer.Initializer.Clone());
script.InsertBefore(insertAnchor, outerDeclaration);
});
}, declaration);
}
static CodeAction MoveDeclarationAction(RefactoringContext context, AstNode insertAnchor,
@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
});
script.Remove(declarationStatement);
script.InsertBefore(insertAnchor, new VariableDeclarationStatement(type, name, Expression.Null));
});
}, declarationStatement);
}
bool HasDependency(RefactoringContext context, AstNode firstSearchNode, AstNode targetNode)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/NegateRelationalExpressionAction.cs

@ -39,7 +39,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -39,7 +39,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script => {
var expr = new BinaryOperatorExpression (node.Left.Clone (), newOp, node.Right.Clone ());
script.Replace (node, expr);
});
}, node.OperatorToken);
}
return null;
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/PutInsideUsingAction.cs

@ -120,7 +120,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -120,7 +120,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
remainingVariables.Variables.Remove (
remainingVariables.Variables.FirstOrDefault (v => v.Name == node.Name));
script.InsertBefore (usingStatement, remainingVariables);
});
}, node.NameToken);
}
static bool IsIDisposable (IType type)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/RemoveBackingStoreAction.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Rename((IEntity)field, newProperty.Name);
script.Remove (context.RootNode.GetNodeAt<FieldDeclaration> (field.Region.Begin));
script.Replace (property, newProperty);
});
}, property.NameToken);
}
// void ReplaceBackingFieldReferences (MDRefactoringContext context, IField backingStore, PropertyDeclaration property)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/RemoveBracesAction.cs

@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Remove(block.LBraceToken);
script.Remove(block.RBraceToken);
script.FormatText(block.Parent);
});
}, block);
}
static BlockStatement GetBlockStatement(RefactoringContext context)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/RemoveRedundantCatchTypeAction.cs

@ -59,7 +59,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -59,7 +59,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.Replace(catchClause, new CatchClause() {
Body = catchClause.Body.Clone() as BlockStatement
});
});
}, catchClause.Type);
}
bool IsReferenced(IVariable variable, AstNode node, SyntaxTree syntaxTree, RefactoringContext context)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/RemoveRegionAction.cs

@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return new CodeAction (context.TranslateString("Remove region"), script => {
script.Remove (directive);
script.Remove (endDirective);
});
}, directive);
}
class DirectiveSearcher : DepthFirstAstVisitor

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ReplaceEmptyStringAction.cs

@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -40,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
yield return new CodeAction(context.TranslateString("Use string.Empty"), script => {
script.Replace(expr, new MemberReferenceExpression (new TypeReferenceExpression (new PrimitiveType ("string")), "Empty"));
});
}, expr);
}
static PrimitiveExpression GetEmptyString (RefactoringContext context)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/SortUsingsAction.cs

@ -54,7 +54,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -54,7 +54,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
for (var i = 0; i < originalNodes.Length; ++i)
script.Replace(originalNodes[i], sortedNodes[i].Clone());
}
});
}, usingNode);
}
private static AstNode FindUsingNodeAtCursor(RefactoringContext context)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/SplitDeclarationAndAssignmentAction.cs

@ -59,7 +59,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -59,7 +59,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.InsertBefore(varDecl, newVarDecl);
script.Replace(varDecl, varDecl.Parent is ForStatement ? (AstNode)assign : new ExpressionStatement (assign));
});
}, varDecl.Variables.First ().AssignToken);
}
static VariableDeclarationStatement GetVariableDeclarationStatement (RefactoringContext context, out AstType resolvedType, CancellationToken cancellationToken = default(CancellationToken))

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/SplitDeclarationListAction.cs

@ -87,7 +87,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -87,7 +87,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
foreach (var singleDecl in declList)
script.InsertBefore (decl, singleDecl);
script.Remove (decl);
});
}, decl);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/SplitStringAction.cs

@ -55,7 +55,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -55,7 +55,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield return new CodeAction(context.TranslateString("Split string literal"), script => {
int offset = context.GetOffset (context.Location);
script.InsertText (offset, pexpr.LiteralValue.StartsWith("@", StringComparison.Ordinal) ? "\" + @\"" : "\" + \"");
});
}, pexpr);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/StaticMethodInvocationToExtensionMethodInvocationAction.cs

@ -59,7 +59,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -59,7 +59,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var newTarget = memberReference.Clone() as MemberReferenceExpression;
newTarget.Target = firstArgument.Clone();
script.Replace(invocation, new InvocationExpression(newTarget, newArgumentList));
});
}, invocation);
}
#endregion

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/UseExplicitTypeAction.cs

@ -59,7 +59,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -59,7 +59,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var foreachStatement = GetForeachStatement (context);
script.Replace (foreachStatement.VariableType, context.CreateShortType (type));
}
});
}, varDecl);
}
static readonly AstType varType = new SimpleType ("var");

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/UseStringFormatAction.cs

@ -96,7 +96,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -96,7 +96,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
format.Insert (0, '@');
formatLiteral.LiteralValue = format.ToString ();
script.Replace (expr, formatInvocation);
});
}, node);
}
static int IndexOf (IList<Expression> arguments, Expression item)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/UseVarKeywordAction.cs

@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
} else {
script.Replace(foreachStmt.VariableType, new SimpleType ("var"));
}
});
}, varDecl);
}
static readonly AstType varType = new SimpleType ("var");

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/AccessToClosureIssues/AccessToModifiedClosureIssue.cs

@ -109,7 +109,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -109,7 +109,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
script.Link (textNodes.ToArray ());
};
yield return new CodeAction (context.TranslateString ("Copy to local variable"), action);
yield return new CodeAction (context.TranslateString ("Copy to local variable"), action, env.AstNode);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/AssignmentMadeToSameVariableIssue.cs

@ -85,7 +85,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -85,7 +85,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
action = script => script.Replace (assignmentExpression, assignmentExpression.Left.Clone ());
}
AddIssue (node, ctx.TranslateString ("CS1717:Assignment made to same variable"),
new [] { new CodeAction (ctx.TranslateString ("Remove assignment"), action) });
new [] { new CodeAction (ctx.TranslateString ("Remove assignment"), action, node) });
}
static bool AreEquivalent(ResolveResult first, ResolveResult second)

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/CallToObjectEqualsViaBaseIssue.cs

@ -73,11 +73,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -73,11 +73,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var args = Enumerable.Concat(new [] { new ThisReferenceExpression() }, invocationExpression.Arguments.Select(arg => arg.Clone()));
var newInvocation = MakeInvocation("object.ReferenceEquals", args);
script.Replace(invocationExpression, newInvocation);
});
}, invocationExpression);
yield return new CodeAction(ctx.TranslateString("Remove 'base.'"), script => {
var newInvocation = MakeInvocation("Equals", invocationExpression.Arguments.Select(arg => arg.Clone()));
script.Replace(invocationExpression, newInvocation);
});
}, invocationExpression);
}
static InvocationExpression MakeInvocation(string memberName, IEnumerable<Expression> unClonedArguments)

3
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/CompilerErrors/CS0127ReturnMustNotBeFollowedByAnyExpression.cs

@ -104,7 +104,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -104,7 +104,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
ctx.TranslateString("Remove returned expression"),
script => {
script.Remove(returnStatement.Expression);
}
},
returnStatement
)
);
}

9
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ConstantConditionIssue.cs

@ -101,7 +101,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -101,7 +101,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var replaceExpr = value ? conditionalExpr.TrueExpression : conditionalExpr.FalseExpression;
action = new CodeAction (
string.Format (ctx.TranslateString ("Replace '?:' with '{0}' branch"), valueStr),
script => script.Replace (conditionalExpr, replaceExpr.Clone ()));
script => script.Replace (conditionalExpr, replaceExpr.Clone ()),
condition);
} else if (ifElseStatement != null) {
action = new CodeAction (
string.Format (ctx.TranslateString ("Replace 'if' with '{0}' branch"), valueStr),
@ -124,11 +125,13 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -124,11 +125,13 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
RemoveText (script, ifElseStatement.StartLocation, start);
RemoveText (script, end, ifElseStatement.EndLocation);
script.FormatText (ifElseStatement.Parent);
});
}, condition);
} else {
action = new CodeAction (
string.Format (ctx.TranslateString ("Replace expression with '{0}'"), valueStr),
script => script.Replace (condition, new PrimitiveExpression (value)));
script => script.Replace (condition, new PrimitiveExpression (value)),
condition
);
}
AddIssue (condition, string.Format (ctx.TranslateString ("Condition is always '{0}'"), valueStr),
new [] { action });

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ExceptionRethrowIssue.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var title = ctx.TranslateString("The exception is rethrown with explicit usage of the variable");
var action = new CodeAction(ctx.TranslateString("Change to 'throw;'"), script => {
script.Replace(localThrowStatement, new ThrowStatement());
});
}, catchClause);
AddIssue(localThrowStatement, title, action);
}
}

6
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ExplicitConversionInForEachIssue.cs

@ -66,8 +66,10 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -66,8 +66,10 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
string issueText = ctx.TranslateString("Collection element type '{0}' is not implicitly convertible to '{1}'");
string fixText = ctx.TranslateString("Use type '{0}'");
AddIssue(variableType, string.Format(issueText, elementType.GetText(), variableType.GetText()),
new CodeAction(string.Format(fixText, elementType.GetText()),
script => script.Replace(variableType, elementType)));
new CodeAction(
string.Format(fixText, elementType.GetText()),
script => script.Replace(variableType, elementType),
foreachStatement));
}
}
}

9
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ExpressionIsAlwaysOfProvidedTypeIssue.cs

@ -63,9 +63,12 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -63,9 +63,12 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (!IsValidReferenceOrBoxingConversion(type, providedType))
return;
var action = new CodeAction (ctx.TranslateString ("Compare with 'null'"),
scrpit => scrpit.Replace (isExpression, new BinaryOperatorExpression (
isExpression.Expression.Clone (), BinaryOperatorType.InEquality, new PrimitiveExpression (null))));
var action = new CodeAction (
ctx.TranslateString ("Compare with 'null'"),
script => script.Replace (isExpression, new BinaryOperatorExpression (
isExpression.Expression.Clone (), BinaryOperatorType.InEquality, new PrimitiveExpression (null))),
isExpression
);
AddIssue (isExpression, ctx.TranslateString ("Given expression is always of the provided type. " +
"Consider comparing with 'null' instead"), new [] { action });
}

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/GatherVisitorBase.cs

@ -70,12 +70,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -70,12 +70,12 @@ namespace ICSharpCode.NRefactory.CSharp
protected void AddIssue(AstNode node, string title, System.Action<Script> fix = null)
{
FoundIssues.Add(new CodeIssue (title, node.StartLocation, node.EndLocation, fix != null ? new CodeAction (title, fix) : null));
FoundIssues.Add(new CodeIssue (title, node.StartLocation, node.EndLocation, fix != null ? new CodeAction (title, fix, node) : null));
}
protected void AddIssue(TextLocation start, TextLocation end, string title, System.Action<Script> fix = null)
{
FoundIssues.Add(new CodeIssue(title, start, end, fix != null ? new CodeAction(title, fix) : null));
FoundIssues.Add(new CodeIssue(title, start, end, fix != null ? new CodeAction(title, fix, null) : null));
}
protected void AddIssue(AstNode node, string title, CodeAction fix)

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/IdenticalConditionalBranchIssue.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -56,7 +56,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (!conditionalExpression.TrueExpression.Match (conditionalExpression.FalseExpression).Success)
return;
var action = new CodeAction (ctx.TranslateString ("Replace '?:' with branch"),
script => script.Replace (conditionalExpression, conditionalExpression.TrueExpression.Clone ()));
script => script.Replace (conditionalExpression, conditionalExpression.TrueExpression.Clone ()), conditionalExpression.QuestionMarkToken);
AddIssue (conditionalExpression,
ctx.TranslateString ("'?:' expression has identical true and false branches"), new [] { action });
}

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/InconsistentNamingIssue/InconsistentNamingIssue.cs

@ -156,7 +156,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -156,7 +156,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
} else {
script.Replace(identifier, Identifier.Create(n));
}
})));
}, identifier)));
if (entity != AffectedEntity.Namespace && entity != AffectedEntity.Label) {
actions.Add(new CodeAction(string.Format(ctx.TranslateString("Rename '{0}'..."), identifier.Name), (Script script) => {
@ -174,7 +174,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -174,7 +174,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
} else if (resolveResult is LocalResolveResult) {
script.Rename(((LocalResolveResult)resolveResult).Variable);
}
}));
}, identifier));
}
AddIssue(identifier, msg, actions);

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/IncorrectExceptionParameterOrderingIssue.cs

@ -90,7 +90,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -90,7 +90,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
newOCE.Arguments.Add(secondParam.Clone());
newOCE.Arguments.Add(firstParam.Clone());
script.Replace(objectCreateExpression, newOCE);
});
}, objectCreateExpression);
}
}
}

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/MissingStringComparisonIssue.cs

@ -88,8 +88,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -88,8 +88,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
AddIssue(invocationExpression.LParToken.StartLocation, invocationExpression.RParToken.EndLocation,
mre.MemberName + "() call is missing StringComparison argument",
new [] {
new CodeAction("Use ordinal comparison", script => AddArgument(script, invocationExpression, "Ordinal")),
new CodeAction("Use culture-aware comparison", script => AddArgument(script, invocationExpression, "CurrentCulture")),
new CodeAction("Use ordinal comparison", script => AddArgument(script, invocationExpression, "Ordinal"), invocationExpression),
new CodeAction("Use culture-aware comparison", script => AddArgument(script, invocationExpression, "CurrentCulture"), invocationExpression)
});
}

6
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/OptionalParameterCouldBeSkippedIssue.cs

@ -90,7 +90,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -90,7 +90,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
.Select(arg => arg.Clone());
var newInvocation = generateReplacement(node, newArgumentList);
script.Replace(node, newInvocation);
});
}, node);
var issueMessage = ctx.TranslateString("Argument is identical to the default value");
var lastPositionalArgument = redundantArguments.FirstOrDefault(expression => !(expression is NamedArgumentExpression));
@ -107,7 +107,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -107,7 +107,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
.Select(arg => arg.Clone());
var newInvocation = generateReplacement(node, newArgumentList);
script.Replace(node, newInvocation);
}));
}, node));
} else {
var title = ctx.TranslateString("Remove this and the following positional arguments");
actions.Add(new CodeAction(title, script => {
@ -116,7 +116,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -116,7 +116,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
.Select(arg => arg.Clone());
var newInvocation = generateReplacement(node, newArgumentList);
script.Replace(node, newInvocation);
}));
}, node));
}
AddIssue(localArgument, issueMessage, actions);

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ParameterCanBeDemotedIssue/ParameterCanBeDemotedIssue.cs

@ -181,7 +181,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -181,7 +181,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var message = string.Format(ctx.TranslateString("Demote parameter to '{0}'"), type.FullName);
yield return new CodeAction(message, script => {
script.Replace(parameter.Type, astBuilder.ConvertType(localType));
});
}, parameter.NameToken);
}
}
}

10
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/RedundantCatchIssue.cs

@ -59,27 +59,27 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -59,27 +59,27 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
if (hasNonRedundantCatch || !tryCatchStatement.FinallyBlock.IsNull) {
AddIssuesForClauses(redundantCatchClauses);
AddIssuesForClauses(tryCatchStatement, redundantCatchClauses);
} else {
AddIssueForTryCatchStatement(tryCatchStatement);
}
}
void AddIssuesForClauses(List<CatchClause> redundantCatchClauses)
void AddIssuesForClauses(AstNode node, List<CatchClause> redundantCatchClauses)
{
var allCatchClausesMessage = ctx.TranslateString("Remove all '{0}' redundant catches");
var removeAllRedundantClausesAction = new CodeAction(allCatchClausesMessage, script => {
foreach (var redundantCatchClause in redundantCatchClauses) {
script.Remove(redundantCatchClause);
}
});
}, node);
var singleCatchClauseMessage = ctx.TranslateString("Remove redundant catch clause");
var redundantCatchClauseMessage = ctx.TranslateString("A catch clause containing a single empty throw statement is redundant.");
foreach (var redundantCatchClause in redundantCatchClauses) {
var closureLocalCatchClause = redundantCatchClause;
var removeRedundantClauseAction = new CodeAction(singleCatchClauseMessage, script => {
script.Remove(closureLocalCatchClause);
});
}, node);
var actions = new List<CodeAction>();
actions.Add(removeRedundantClauseAction);
if (redundantCatchClauses.Count > 1) {
@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
// The replace and insert script functions does not format these things well on their own
script.FormatText(tryCatchStatement.Parent);
});
}, tryCatchStatement);
var fixes = new [] {
removeTryStatementAction

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ReferenceEqualsCalledWithValueTypeIssue.cs

@ -69,7 +69,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -69,7 +69,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var action = new CodeAction (ctx.TranslateString ("Use Equals()"),
script => script.Replace (invocationExpression.Target, new MemberReferenceExpression (
new TypeReferenceExpression (new PrimitiveType ("object")), "Equals")));
new TypeReferenceExpression (new PrimitiveType ("object")), "Equals")), invocationExpression);
AddIssue (invocationExpression,
ctx.TranslateString ("'Object.ReferenceEquals' is always false because it is called with value type"),
new [] { action });

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ReferenceToStaticMemberViaDerivedTypeIssue.cs

@ -107,7 +107,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -107,7 +107,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
string description = string.Format("{0} '{1}'", context.TranslateString("Use base class"), newType.GetText());
return new CodeAction(description, script => {
script.Replace(targetExpression, newType);
});
}, targetExpression);
}
sealed class ContainsTypeVisitor : TypeVisitor

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/ThreadStaticOnInstanceFieldIssue.cs

@ -88,14 +88,14 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -88,14 +88,14 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
} else {
script.Remove(attributeSection);
}
});
}, attribute);
var makeStaticMessage = ctx.TranslateString("Make the field static");
yield return new CodeAction(makeStaticMessage, script => {
var newDeclaration = (FieldDeclaration)fieldDeclaration.Clone();
newDeclaration.Modifiers |= Modifiers.Static;
script.Replace(fieldDeclaration, newDeclaration);
});
}, fieldDeclaration.NameToken);
}
}
}

4
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/UnreachableCodeIssue.cs

@ -158,7 +158,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -158,7 +158,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var startOffset = script.GetCurrentOffset (prevEnd);
var endOffset = script.GetCurrentOffset (end);
script.RemoveText (startOffset, endOffset - startOffset);
});
}, null);
var commentAction = new CodeAction (visitor.ctx.TranslateString ("Comment unreachable code"),
script =>
{
@ -166,7 +166,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -166,7 +166,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.InsertText (startOffset, Environment.NewLine + "/*");
var endOffset = script.GetCurrentOffset (end);
script.InsertText (endOffset, Environment.NewLine + "*/");
});
}, null);
var actions = new [] { removeAction, commentAction };
visitor.AddIssue (start, end, visitor.ctx.TranslateString ("Code is unreachable"), actions);
return true;

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/VariableDeclaredInWideScopeIssue.cs

@ -341,7 +341,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -341,7 +341,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
script.FormatText(parent);
}
script.Remove(oldStatement);
});
}, oldStatement);
}
AstNode GetDeepestCommonAncestor(AstNode assumedRoot, IEnumerable<AstNode> leaves)

12
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -273,12 +273,6 @@ @@ -273,12 +273,6 @@
<Folder Include="TypeSystem\" />
<Folder Include="Utils\CompositeFormatStringParser\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\cecil\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="..\doc\Pattern Matching.html">
<Link>PatternMatching\Pattern Matching.html</Link>
@ -288,4 +282,10 @@ @@ -288,4 +282,10 @@
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\..\cecil\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
</ItemGroup>
</Project>
Loading…
Cancel
Save