Browse Source

Fixed some translation strings/code issues can now offer more actions.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
296fc865c9
  1. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertDecToHex.cs
  2. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertForeachToFor.cs
  3. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ConvertHexToDec.cs
  4. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/CreateBackingStore.cs
  5. 4
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/FlipOperatorArguments.cs
  6. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ReplaceEmptyString.cs
  7. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/SplitDeclarationAndAssignment.cs
  8. 8
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/SplitString.cs
  9. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/UseExplicitType.cs
  10. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/UseVarKeyword.cs
  11. 12
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssue.cs
  12. 3
      ICSharpCode.NRefactory.Tests/CSharp/Inspector/InspectionActionTestBase.cs

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

@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield break;
}
yield return new CodeAction (context.TranslateString("Add null check for parameter"), script => {
yield return new CodeAction(context.TranslateString("Convert dec to hex"), script => {
script.Replace(pexpr, new PrimitiveExpression (pexpr.Value, string.Format("0x{0:x}", pexpr.Value)));
});
}

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

@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -43,7 +43,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (foreachStatement == null) {
yield break;
}
yield return new CodeAction (context.TranslateString("Add null check for parameter"), script => {
yield return new CodeAction(context.TranslateString("Convert 'foreach' loop to 'for'"), script => {
var result = context.Resolve (foreachStatement.InExpression);
var countProperty = GetCountProperty (result.Type);

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

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

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

@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield break;
}
yield return new CodeAction (context.TranslateString("Add null check for parameter"), script => {
yield return new CodeAction(context.TranslateString("Create backing store"), script => {
string backingStoreName = context.GetNameProposal (property.Name);
// create field

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

@ -38,7 +38,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -38,7 +38,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (binop == null) {
yield break;
}
yield return new CodeAction (context.TranslateString("Swap left and right arguments"), script => {
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());
});

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

@ -38,7 +38,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -38,7 +38,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (expr == null) {
yield break;
}
yield return new CodeAction (context.TranslateString("Remove braces"), script => {
yield return new CodeAction(context.TranslateString("Use string.Empty"), script => {
script.Replace(expr, new MemberReferenceExpression (new TypeReferenceExpression (new PrimitiveType ("string")), "Empty"));
});
}

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

@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (varDecl == null) {
yield break;
}
yield return new CodeAction (context.TranslateString("Remove braces"), script => {
yield return new CodeAction(context.TranslateString("Split local variable declaration and assignment"), script => {
var assign = new AssignmentExpression (new IdentifierExpression (varDecl.Variables.First().Name), AssignmentOperatorType.Assign, varDecl.Variables.First().Initializer.Clone());
var newVarDecl = (VariableDeclarationStatement)varDecl.Clone();

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

@ -42,17 +42,17 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -42,17 +42,17 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
yield break;
}
if (pexpr.LiteralValue.StartsWith("@")) {
if (!(pexpr.StartLocation < new TextLocation (context.Location.Line, context.Location.Column - 2) &&
new TextLocation (context.Location.Line, context.Location.Column + 2) < pexpr.EndLocation)) {
if (!(pexpr.StartLocation < new TextLocation(context.Location.Line, context.Location.Column - 2) &&
new TextLocation(context.Location.Line, context.Location.Column + 2) < pexpr.EndLocation)) {
yield break;
}
} else {
if (!(pexpr.StartLocation < new TextLocation (context.Location.Line, context.Location.Column - 1) && new TextLocation (context.Location.Line, context.Location.Column + 1) < pexpr.EndLocation)) {
if (!(pexpr.StartLocation < new TextLocation(context.Location.Line, context.Location.Column - 1) && new TextLocation(context.Location.Line, context.Location.Column + 1) < pexpr.EndLocation)) {
yield break;
}
}
yield return new CodeAction (context.TranslateString("Remove braces"), script => {
yield return new CodeAction(context.TranslateString("Split string literal"), script => {
int offset = context.GetOffset (context.Location);
script.InsertText (offset, pexpr.LiteralValue.StartsWith ("@") ? "\" + @\"" : "\" + \"");
});

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

@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -52,7 +52,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (!(!type.Equals(SpecialType.NullType) && !type.Equals(SpecialType.UnknownType))) {
yield break;
}
yield return new CodeAction (context.TranslateString("Remove braces"), script => {
yield return new CodeAction (context.TranslateString("Use expcicit type"), script => {
if (varDecl != null) {
script.Replace (varDecl.Type, context.CreateShortType (type));
} else {

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

@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -41,7 +41,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (varDecl == null && foreachStmt == null) {
yield break;
}
yield return new CodeAction (context.TranslateString("Remove braces"), script => {
yield return new CodeAction(context.TranslateString("Use 'var' keyword"), script => {
if (varDecl != null) {
script.Replace(varDecl.Type, new SimpleType ("var"));
} else {

12
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssue.cs

@ -24,6 +24,8 @@ @@ -24,6 +24,8 @@
// 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;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
@ -44,17 +46,21 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -44,17 +46,21 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
private set;
}
public CodeAction Action {
public IEnumerable<CodeAction> Actions {
get;
private set;
}
public CodeIssue (string description, TextLocation start, TextLocation end, CodeAction action = null)
public CodeIssue(string description, TextLocation start, TextLocation end, IEnumerable<CodeAction> action = null)
{
Desription = description;
Start = start;
End = end;
Action = action;
Actions = action ?? Enumerable.Empty<CodeAction> ();
}
public CodeIssue(string description, TextLocation start, TextLocation end, CodeAction action) : this (description, start, end, new [] { action })
{
}
}
}

3
ICSharpCode.NRefactory.Tests/CSharp/Inspector/InspectionActionTestBase.cs

@ -30,6 +30,7 @@ using ICSharpCode.NRefactory.CSharp.Refactoring; @@ -30,6 +30,7 @@ using ICSharpCode.NRefactory.CSharp.Refactoring;
using ICSharpCode.NRefactory.CSharp.ContextActions;
using System.Collections.Generic;
using NUnit.Framework;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.Inspector
{
@ -45,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp.Inspector @@ -45,7 +46,7 @@ namespace ICSharpCode.NRefactory.CSharp.Inspector
protected static void CheckFix (TestRefactoringContext ctx, CodeIssue issue, string expectedOutput)
{
using (var script = ctx.StartScript ())
issue.Action.Run (script);
issue.Actions.First ().Run (script);
Assert.AreEqual (expectedOutput, ctx.Text);
}
}

Loading…
Cancel
Save