Browse Source

Added monodevelop context actions.

newNRvisualizers
Mike Krüger 15 years ago
parent
commit
6e1eaf15f8
  1. 13
      ICSharpCode.NRefactory/CSharp/Formatter/AstFormattingVisitor.cs
  2. 3
      ICSharpCode.NRefactory/CSharp/Formatter/ITextEditorAdapter.cs
  3. 10
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
  4. 9
      ICSharpCode.NRefactory/CSharp/OutputVisitor/TextWriterOutputFormatter.cs
  5. 2
      ICSharpCode.NRefactory/CSharp/Parser/mcs/driver.cs
  6. 63
      ICSharpCode.NRefactory/CSharp/Refactoring/Action.cs
  7. 92
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/AddAnotherAccessor.cs
  8. 114
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/CheckIfParameterIsNull.cs
  9. 52
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/ConvertDecToHex.cs
  10. 108
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/ConvertForeachToFor.cs
  11. 52
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/ConvertHexToDec.cs
  12. 78
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/CreateBackingStore.cs
  13. 59
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/FlipOperatorArguments.cs
  14. 92
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/GenerateSwitchLabels.cs
  15. 89
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/InsertAnonymousMethodSignature.cs
  16. 100
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/IntroduceFormatItem.cs
  17. 61
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/InvertIf.cs
  18. 61
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/RemoveBraces.cs
  19. 53
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/ReplaceEmptyString.cs
  20. 74
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/SplitDeclarationAndAssignment.cs
  21. 56
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/SplitString.cs
  22. 69
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/UseExplicitType.cs
  23. 56
      ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/UseVarKeyword.cs
  24. 44
      ICSharpCode.NRefactory/CSharp/Refactoring/CreateLinkAction.cs
  25. 39
      ICSharpCode.NRefactory/CSharp/Refactoring/FormatTextAction.cs
  26. 75
      ICSharpCode.NRefactory/CSharp/Refactoring/IActionFactory.cs
  27. 36
      ICSharpCode.NRefactory/CSharp/Refactoring/IContextAction.cs
  28. 120
      ICSharpCode.NRefactory/CSharp/Refactoring/NodeOutputAction.cs
  29. 40
      ICSharpCode.NRefactory/CSharp/Refactoring/NodeSelectionAction.cs
  30. 109
      ICSharpCode.NRefactory/CSharp/Refactoring/RefactoringContext.cs
  31. 156
      ICSharpCode.NRefactory/CSharp/Refactoring/Script.cs
  32. 158
      ICSharpCode.NRefactory/CSharp/Refactoring/StringBuilderOutputFormatter.cs
  33. 134
      ICSharpCode.NRefactory/CSharp/Refactoring/TextReplaceAction.cs
  34. 30
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

13
ICSharpCode.NRefactory/CSharp/Formatter/AstFormattingVisitor.cs

@ -28,6 +28,7 @@ using System.Text; @@ -28,6 +28,7 @@ using System.Text;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.CSharp.Refactoring;
namespace ICSharpCode.NRefactory.CSharp
{
@ -35,7 +36,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -35,7 +36,8 @@ namespace ICSharpCode.NRefactory.CSharp
{
CSharpFormattingOptions policy;
ITextEditorAdapter data;
List<Change> changes = new List<Change> ();
IActionFactory factory;
List<TextReplaceAction> changes = new List<TextReplaceAction> ();
Indent curIndent = new Indent ();
public int IndentLevel {
@ -52,7 +54,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -52,7 +54,7 @@ namespace ICSharpCode.NRefactory.CSharp
set;
}
public List<Change> Changes {
public List<TextReplaceAction> Changes {
get { return this.changes; }
}
@ -66,12 +68,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -66,12 +68,15 @@ namespace ICSharpCode.NRefactory.CSharp
set;
}
public AstFormattingVisitor (CSharpFormattingOptions policy, ITextEditorAdapter data)
public AstFormattingVisitor (CSharpFormattingOptions policy, ITextEditorAdapter data, IActionFactory factory)
{
if (factory == null)
throw new ArgumentNullException ("factory");
this.policy = policy;
this.data = data;
this.curIndent.TabsToSpaces = this.data.TabsToSpaces;
this.curIndent.TabSize = this.data.TabSize;
this.factory = factory;
CorrectBlankLines = true;
}
@ -963,7 +968,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -963,7 +968,7 @@ namespace ICSharpCode.NRefactory.CSharp
//Console.WriteLine ("offset={0}, removedChars={1}, insertedText={2}", offset, removedChars, insertedText == null ? "<null>" : insertedText.Replace ("\n", "\\n").Replace ("\t", "\\t").Replace (" ", "."));
//Console.WriteLine (Environment.StackTrace);
changes.Add (new Change (offset, removedChars, insertedText));
changes.Add (factory.CreateTextReplaceAction (offset, removedChars, insertedText));
}
public bool IsLineIsEmptyUpToEol (AstLocation startLocation)

3
ICSharpCode.NRefactory/CSharp/Formatter/ITextEditorAdapter.cs

@ -61,6 +61,7 @@ namespace ICSharpCode.NRefactory @@ -61,6 +61,7 @@ namespace ICSharpCode.NRefactory
void Replace (int offset, int count, string text);
}
/*
public static class ITextEditorAdapterHelperMethods
{
public static void AcceptChanges (this ITextEditorAdapter adapter, List<Change> changes)
@ -83,6 +84,6 @@ namespace ICSharpCode.NRefactory @@ -83,6 +84,6 @@ namespace ICSharpCode.NRefactory
}
}
}
}
}*/
}

10
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -70,6 +70,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -70,6 +70,15 @@ namespace ICSharpCode.NRefactory.CSharp
handler (this, e);
}
public event EventHandler<AstNodeEventArgs> OutputFinished;
protected virtual void OnOutputFinished (AstNodeEventArgs e)
{
EventHandler<AstNodeEventArgs> handler = this.OutputFinished;
if (handler != null)
handler (this, e);
}
[Serializable]
public sealed class AstNodeEventArgs : EventArgs
{
@ -104,6 +113,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -104,6 +113,7 @@ namespace ICSharpCode.NRefactory.CSharp
Debug.Assert (pos == null || pos.Parent == node);
WriteSpecials (pos, null);
containerStack.Pop ();
OnOutputFinished (new AstNodeEventArgs (node));
formatter.EndNode (node);
return null;
}

9
ICSharpCode.NRefactory/CSharp/OutputVisitor/TextWriterOutputFormatter.cs

@ -14,6 +14,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -14,6 +14,15 @@ namespace ICSharpCode.NRefactory.CSharp
readonly TextWriter textWriter;
int indentation;
bool needsIndent = true;
public int Indentation {
get {
return this.indentation;
}
set {
this.indentation = value;
}
}
public string IndentationString { get; set; }

2
ICSharpCode.NRefactory/CSharp/Parser/mcs/driver.cs

@ -418,7 +418,7 @@ namespace Mono.CSharp @@ -418,7 +418,7 @@ namespace Mono.CSharp
return ParseFile (args, input, inputFile, new StreamReportPrinter (reportStream));
}
internal static object parseLock = new object ();
public static object parseLock = new object ();
public static CompilerCompilationUnit ParseFile (string[] args, Stream input, string inputFile, ReportPrinter reportPrinter)
{

63
ICSharpCode.NRefactory/CSharp/Formatter/Change.cs → ICSharpCode.NRefactory/CSharp/Refactoring/Action.cs

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@ -25,54 +25,31 @@ @@ -25,54 +25,31 @@
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class Change
/// <summary>
/// This is the base class for all refactoring operations that are performed.
/// </summary>
public abstract class Action
{
public int Offset {
/// <summary>
/// Gets or sets the description.
/// </summary>
/// <value>
/// A brief description of the refactoring change.
/// </value>
public string Description {
get;
set;
}
int removedChars;
public int RemovedChars {
get {
return removedChars;
}
set {
if (value < 0)
throw new ArgumentOutOfRangeException ("RemovedChars", "needs to be >= 0");
removedChars = value;
}
}
public string InsertedText {
get;
set;
}
public Change (int offset, int removedChars, string insertedText)
{
if (removedChars < 0)
throw new ArgumentOutOfRangeException ("removedChars", "removedChars needs to be >= 0");
if (offset < 0)
throw new ArgumentOutOfRangeException ("offset", "offset needs to be >= 0");
this.removedChars = removedChars;
this.Offset = offset;
this.InsertedText = insertedText;
}
public void PerformChange (ITextEditorAdapter adapter)
{
adapter.Replace (Offset, RemovedChars, InsertedText);
}
public override string ToString ()
{
return string.Format ("[Change: Offset={0}, RemovedChars={1}, InsertedText={2}]", Offset, RemovedChars, InsertedText);
}
/// <summary>
/// Performs the change.
/// </summary>
/// <param name='rctx'>
/// The context on which the change should perform on.
/// </param>
public abstract void Perform (Script script);
}
}

92
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/AddAnotherAccessor.cs

@ -0,0 +1,92 @@ @@ -0,0 +1,92 @@
//
// AddAnotherAccessor.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
/// <summary>
/// Add another accessor to a property declaration that has only one.
/// </summary>
public class AddAnotherAccessor : IContextAction
{
public bool IsValid (RefactoringContext context)
{
var pdecl = GetPropertyDeclaration (context);
if (pdecl == null)
return false;
var type = pdecl.Parent as TypeDeclaration;
if (type != null && type.ClassType == ICSharpCode.NRefactory.TypeSystem.ClassType.Interface)
return false;
return pdecl.Setter.IsNull || pdecl.Getter.IsNull;
}
public void Run (RefactoringContext context)
{
var pdecl = GetPropertyDeclaration (context);
var accessorStatement = BuildAccessorStatement (context, pdecl);
Accessor accessor = new Accessor () {
Body = new BlockStatement { accessorStatement }
};
pdecl.AddChild (accessor, pdecl.Setter.IsNull ? PropertyDeclaration.SetterRole : PropertyDeclaration.GetterRole);
var offset = context.GetOffset (pdecl.RBraceToken.StartLocation) - 1;
using (var script = context.StartScript ()) {
script.Select (accessorStatement);
script.Insert (offset, accessor);
script.FormatText (ctx => GetPropertyDeclaration (context));
}
}
static Statement BuildAccessorStatement (RefactoringContext context, PropertyDeclaration pdecl)
{
// TODO:
// if (pdecl.Setter.IsNull && !pdecl.Getter.IsNull) {
// var field = RemoveBackingStore.ScanGetter (context, pdecl);
// if (field != null)
// return new ExpressionStatement (new AssignmentExpression (new IdentifierExpression (field.Name), AssignmentOperatorType.Assign, new IdentifierExpression ("value")));
// }
//
// if (!pdecl.Setter.IsNull && pdecl.Getter.IsNull) {
// var field = RemoveBackingStore.ScanSetter (context, pdecl);
// if (field != null)
// return new ReturnStatement (new IdentifierExpression (field.Name));
// }
return new ThrowStatement (new ObjectCreateExpression (context.CreateShortType ("System.NotImplementedException")));
}
static PropertyDeclaration GetPropertyDeclaration (RefactoringContext context)
{
var node = context.GetNode ();
if (node == null)
return null;
return node.Parent as PropertyDeclaration;
}
}
}

114
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/CheckIfParameterIsNull.cs

@ -0,0 +1,114 @@ @@ -0,0 +1,114 @@
//
// CheckIfParameterIsNull.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
/// <summary>
/// Creates a 'if (param == null) throw new System.ArgumentNullException ();' contruct for a parameter.
/// </summary>
public class CheckIfParameterIsNull : IContextAction
{
//TODO: Create 'multiple' null checks when more than 1 parameter is selected.
public bool IsValid (RefactoringContext context)
{
var parameter = GetParameterDeclaration (context);
if (parameter == null)
return false;
var bodyStatement = parameter.Parent.GetChildByRole (AstNode.Roles.Body);
if (bodyStatement == null)
return false;
if (parameter.Type is PrimitiveType)
return (((PrimitiveType)parameter.Type).Keyword == "object" || ((PrimitiveType)parameter.Type).Keyword == "string") && !HasNullCheck (parameter);
// TODO: check for structs
return !HasNullCheck (parameter);
}
public void Run (RefactoringContext context)
{
var parameter = GetParameterDeclaration (context);
var bodyStatement = parameter.Parent.GetChildByRole (AstNode.Roles.Body);
var statement = new IfElseStatement () {
Condition = new BinaryOperatorExpression (new IdentifierExpression (parameter.Name), BinaryOperatorType.Equality, new NullReferenceExpression ()),
TrueStatement = new ThrowStatement (new ObjectCreateExpression (context.CreateShortType ("System.ArgumentNullException"), new PrimitiveExpression (parameter.Name)))
};
var offset = context.GetOffset (bodyStatement.StartLocation) + 1;
using (var script = context.StartScript ()) {
script.Insert (offset, statement);
}
}
static ParameterDeclaration GetParameterDeclaration (RefactoringContext context)
{
return context.GetNode<ICSharpCode.NRefactory.CSharp.ParameterDeclaration> ();
}
static bool HasNullCheck (ParameterDeclaration parameter)
{
var visitor = new CheckNullVisitor (parameter);
parameter.Parent.AcceptVisitor (visitor, null);
return visitor.ContainsNullCheck;
}
class CheckNullVisitor : DepthFirstAstVisitor<object, object>
{
ParameterDeclaration parameter;
public bool ContainsNullCheck {
get;
set;
}
public CheckNullVisitor (ParameterDeclaration parameter)
{
this.parameter = parameter;
}
public object VisitIfElseStatement (IfElseStatement ifElseStatement, object data)
{
if (ifElseStatement.Condition is BinaryOperatorExpression) {
var binOp = ifElseStatement.Condition as BinaryOperatorExpression;
if ((binOp.Operator == BinaryOperatorType.Equality || binOp.Operator == BinaryOperatorType.InEquality) &&
binOp.Left.IsMatch (new IdentifierExpression (parameter.Name)) && binOp.Right.IsMatch (new NullReferenceExpression ()) ||
binOp.Right.IsMatch (new IdentifierExpression (parameter.Name)) && binOp.Left.IsMatch (new NullReferenceExpression ())) {
ContainsNullCheck = true;
}
}
return base.VisitIfElseStatement (ifElseStatement, data);
}
}
}
}

52
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/ConvertDecToHex.cs

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
//
// ConvertDecToHex.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
/// <summary>
/// Convert a dec numer to hex. For example: 16 -> 0x10
/// </summary>
public class ConvertDecToHex : IContextAction
{
public bool IsValid (RefactoringContext context)
{
var pexpr = context.GetNode<PrimitiveExpression> ();
if (pexpr == null || pexpr.LiteralValue.ToUpper ().StartsWith ("0X"))
return false;
return (pexpr.Value is int) || (pexpr.Value is long) || (pexpr.Value is short) || (pexpr.Value is sbyte) ||
(pexpr.Value is uint) || (pexpr.Value is ulong) || (pexpr.Value is ushort) || (pexpr.Value is byte);
}
public void Run (RefactoringContext context)
{
var pexpr = context.GetNode<PrimitiveExpression> ();
using (var script = context.StartScript ()) {
script.Replace (pexpr, new PrimitiveExpression (pexpr.Value, string.Format ("0x{0:x}", pexpr.Value)));
}
}
}
}

108
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/ConvertForeachToFor.cs

@ -0,0 +1,108 @@ @@ -0,0 +1,108 @@
//
// ConvertForeachToFor.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
/// <summary>
/// Converts a foreach loop to for.
/// </summary>
public class ConvertForeachToFor : IContextAction
{
public bool IsValid (RefactoringContext context)
{
return GetForeachStatement (context) != null;
}
public void Run (RefactoringContext context)
{ // TODO: Missing resolver!
// var foreachStatement = GetForeachStatement (context);
//
// var resolver = context.Resolver;
//
// var result = resolver.Resolve (foreachStatement.InExpression.ToString (), new DomLocation (foreachStatement.InExpression.StartLocation.Line, foreachStatement.InExpression.StartLocation.Column));
// string itemNumberProperty = "Count";
//
// if (result != null && result.ResolvedType != null && result.ResolvedType.ArrayDimensions > 0)
// itemNumberProperty = "Length";
//
// ForStatement forStatement = new ForStatement () {
// Initializers = {
// new VariableDeclarationStatement (new PrimitiveType ("int"), "i", new PrimitiveExpression (0))
// },
// Condition = new BinaryOperatorExpression (new IdentifierExpression ("i"), BinaryOperatorType.LessThan, new MemberReferenceExpression (foreachStatement.InExpression.Clone (), itemNumberProperty)),
// Iterators = {
// new ExpressionStatement (new UnaryOperatorExpression (UnaryOperatorType.PostIncrement, new IdentifierExpression ("i")))
// },
// EmbeddedStatement = new BlockStatement {
// new VariableDeclarationStatement (foreachStatement.VariableType.Clone (), foreachStatement.VariableName, new IndexerExpression (foreachStatement.InExpression.Clone (), new IdentifierExpression ("i")))
// }
// };
//
// var editor = context.Document.Editor;
// var offset = editor.LocationToOffset (foreachStatement.StartLocation.Line, foreachStatement.StartLocation.Column);
// var endOffset = editor.LocationToOffset (foreachStatement.EndLocation.Line, foreachStatement.EndLocation.Column);
// var offsets = new List<int> ();
// string lineIndent = editor.GetLineIndent (foreachStatement.Parent.StartLocation.Line);
// string text = context.OutputNode (forStatement, context.Document.CalcIndentLevel (lineIndent) + 1, delegate(int nodeOffset, AstNode astNode) {
// if (astNode is VariableInitializer && ((VariableInitializer)astNode).Name == "i")
// offsets.Add (nodeOffset);
// if (astNode is IdentifierExpression && ((IdentifierExpression)astNode).Identifier == "i") {
// offsets.Add (nodeOffset);
// }
// });
// string foreachBlockText;
//
// if (foreachStatement.EmbeddedStatement is BlockStatement) {
// foreachBlockText = editor.GetTextBetween (foreachStatement.EmbeddedStatement.StartLocation.Line, foreachStatement.EmbeddedStatement.StartLocation.Column + 1,
// foreachStatement.EmbeddedStatement.EndLocation.Line, foreachStatement.EmbeddedStatement.EndLocation.Column - 1);
// } else {
// foreachBlockText = editor.GetTextBetween (foreachStatement. EmbeddedStatement.StartLocation.Line, foreachStatement.EmbeddedStatement.StartLocation.Column,
// foreachStatement.EmbeddedStatement.EndLocation.Line, foreachStatement.EmbeddedStatement.EndLocation.Column);
// }
// string singeleIndent = GetSingleIndent (editor);
// string indent = lineIndent + singeleIndent;
// foreachBlockText = indent + foreachBlockText.TrimEnd () + editor.EolMarker;
// int i = text.LastIndexOf ('}');
// while (i > 1 && text[i - 1] == ' ' || text[i - 1] == '\t')
// i--;
//
// text = text.Insert (i, foreachBlockText).TrimEnd ();
// string trimmedText = text.TrimStart ();
// editor.Replace (offset, endOffset - offset + 1, trimmedText);
// context.StartTextLinkMode (offset, "i".Length, offsets.Select (o => o - (text.Length - trimmedText.Length)));
}
static ForeachStatement GetForeachStatement (RefactoringContext context)
{
var astNode = context.GetNode ();
if (astNode == null)
return null;
return (astNode as ForeachStatement) ?? astNode.Parent as ForeachStatement;
}
}
}

52
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/ConvertHexToDec.cs

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
//
// ConvertHexToDec.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
/// <summary>
/// Convert a hex numer to dec. For example: 0x10 -> 16
/// </summary>
public class ConvertHexToDec: IContextAction
{
public bool IsValid (RefactoringContext context)
{
var pexpr = context.GetNode<PrimitiveExpression> ();
if (pexpr == null || !pexpr.LiteralValue.ToUpper ().StartsWith ("0X"))
return false;
return (pexpr.Value is int) || (pexpr.Value is long) || (pexpr.Value is short) || (pexpr.Value is sbyte) ||
(pexpr.Value is uint) || (pexpr.Value is ulong) || (pexpr.Value is ushort) || (pexpr.Value is byte);
}
public void Run (RefactoringContext context)
{
var pexpr = context.GetNode<PrimitiveExpression> ();
using (var script = context.StartScript ()) {
script.Replace (pexpr, new PrimitiveExpression (pexpr.Value));
}
}
}
}

78
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/CreateBackingStore.cs

@ -0,0 +1,78 @@ @@ -0,0 +1,78 @@
//
// CreateBackingStore.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class CreateBackingStore : IContextAction
{
public bool IsValid (RefactoringContext context)
{
var propertyDeclaration = context.GetNode<PropertyDeclaration> ();
return propertyDeclaration != null &&
!propertyDeclaration.Getter.IsNull && !propertyDeclaration.Setter.IsNull && // automatic properties always need getter & setter
propertyDeclaration.Getter.Body.IsNull &&
propertyDeclaration.Setter.Body.IsNull;
}
public void Run (RefactoringContext context)
{
var property = context.GetNode<PropertyDeclaration> ();
string backingStoreName = context.GetNameProposal (property.Name);
// create field
var backingStore = new FieldDeclaration ();
backingStore.ReturnType = property.ReturnType.Clone ();
var initializer = new VariableInitializer (backingStoreName);
backingStore.Variables.Add (initializer);
// create new property & implement the get/set bodies
var newProperty = (PropertyDeclaration)property.Clone ();
var id1 = new IdentifierExpression (backingStoreName);
var id2 = new IdentifierExpression (backingStoreName);
newProperty.Getter.Body = new BlockStatement () {
new ReturnStatement (id1)
};
newProperty.Setter.Body = new BlockStatement () {
new ExpressionStatement (new AssignmentExpression (id2, AssignmentOperatorType.Assign, new IdentifierExpression ("value")))
};
using (var script = context.StartScript ()) {
script.Replace (property, newProperty);
int offset = context.GetOffset (property.StartLocation.Line, 1);
script.Insert (offset, backingStore);
script.Link (initializer, id1, id2);
}
}
}
}

59
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/FlipOperatorArguments.cs

@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
//
// FlipOperatorArguments.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class FlipOperatorArguments : IContextAction
{
public bool IsValid (RefactoringContext context)
{
return GetBinaryOperatorExpression (context) != null;
}
public void Run (RefactoringContext context)
{
var binop = GetBinaryOperatorExpression (context);
using (var script = context.StartScript ()) {
script.Replace (binop.Left, binop.Right);
script.Replace (binop.Right, binop.Left);
}
}
public static BinaryOperatorExpression GetBinaryOperatorExpression (RefactoringContext context)
{
var node = context.GetNode<BinaryOperatorExpression> ();
if (node == null || !node.OperatorToken.Contains (context.Location))
return null;
var result = node as BinaryOperatorExpression;
if (result == null || (result.Operator != BinaryOperatorType.Equality && result.Operator != BinaryOperatorType.InEquality))
return null;
return result;
}
}
}

92
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/GenerateSwitchLabels.cs

@ -0,0 +1,92 @@ @@ -0,0 +1,92 @@
//
// GenerateSwitchLabels.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class GenerateSwitchLabels : IContextAction
{
// TODO: Resolver!
public bool IsValid (RefactoringContext context)
{
return false;
// var switchStatement = GetSwitchStatement (context);
// if (switchStatement == null)
// return false;
// var resolver = context.Resolver;
// var result = resolver.Resolve (switchStatement.Expression.ToString (), new DomLocation (switchStatement.StartLocation.Line, switchStatement.StartLocation.Column));
// if (result == null || result.ResolvedType == null)
// return false;
// var type = context.Document.Dom.GetType (result.ResolvedType);
//
// return type != null && type.ClassType == ClassType.Enum;
}
public void Run (RefactoringContext context)
{
// var switchStatement = GetSwitchStatement (context);
// var resolver = context.Resolver;
//
// var result = resolver.Resolve (switchStatement.Expression.ToString (), new DomLocation (switchStatement.StartLocation.Line, switchStatement.StartLocation.Column));
// var type = context.Document.Dom.GetType (result.ResolvedType);
//
// var target = new TypeReferenceExpression (ShortenTypeName (context.Document, result.ResolvedType));
// foreach (var field in type.Fields) {
// if (!(field.IsLiteral || field.IsConst))
// continue;
// switchStatement.SwitchSections.Add (new SwitchSection () {
// CaseLabels = {
// new CaseLabel (new MemberReferenceExpression ( target.Clone (), field.Name))
// },
// Statements = {
// new BreakStatement ()
// }
// });
// }
//
// switchStatement.SwitchSections.Add (new SwitchSection () {
// CaseLabels = {
// new CaseLabel ()
// },
// Statements = {
// new ThrowStatement (new ObjectCreateExpression (ShortenTypeName (context.Document, "System.ArgumentOutOfRangeException")))
// }
// });
//
// context.Do (switchStatement.Replace (context.Document, switchStatement));
}
static SwitchStatement GetSwitchStatement (RefactoringContext context)
{
var switchStatment = context.GetNode<SwitchStatement> ();
if (switchStatment != null && switchStatment.SwitchSections.Count == 0)
return switchStatment;
return null;
}
}
}

89
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/InsertAnonymousMethodSignature.cs

@ -0,0 +1,89 @@ @@ -0,0 +1,89 @@
//
// InsertAnonymousMethodSignature.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class InsertAnonymousMethodSignature : IContextAction
{
//TODO: Resolve
public bool IsValid (RefactoringContext context)
{
return false;
// IType type;
// return GetAnonymousMethodExpression (context, out type) != null;
}
public void Run (RefactoringContext context)
{
// IType type;
// var anonymousMethodExpression = GetAnonymousMethodExpression (context, out type);
//
// var delegateMethod = type.Methods.First ();
//
// var sb = new StringBuilder ("(");
// for (int k = 0; k < delegateMethod.Parameters.Count; k++) {
// if (k > 0)
// sb.Append (", ");
// var parameterType = context.Document.Dom.GetType (delegateMethod.Parameters [k].ReturnType);
// IReturnType returnType = parameterType != null ? new DomReturnType (parameterType) : delegateMethod.Parameters [k].ReturnType;
// sb.Append (context.OutputNode (ShortenTypeName (context.Document, returnType), 0));
// sb.Append (" ");
// sb.Append (delegateMethod.Parameters [k].Name);
// }
// sb.Append (")");
//
// context.DoInsert (context.Document.Editor.LocationToOffset (anonymousMethodExpression.DelegateToken.EndLocation.Line, anonymousMethodExpression.DelegateToken.EndLocation.Column), sb.ToString ());
}
// AnonymousMethodExpression GetAnonymousMethodExpression (RefactoringContext context, out IType delegateType)
// {
// delegateType = null;
//
// var anonymousMethodExpression = context.GetNode<AnonymousMethodExpression> ();
// if (anonymousMethodExpression == null || !anonymousMethodExpression.DelegateToken.Contains (context.Location.Line, context.Location.Column) || anonymousMethodExpression.HasParameterList)
// return null;
// MonoDevelop.Projects.Dom.ResolveResult resolveResult = null;
// var parent = anonymousMethodExpression.Parent;
// if (parent is AssignmentExpression) {
// resolveResult = context.Resolver.Resolve (((AssignmentExpression)parent).Left.ToString (), context.Location);
// } else if (parent is VariableDeclarationStatement) {
// resolveResult = context.Resolver.Resolve (((VariableDeclarationStatement)parent).Type.ToString (), context.Location);
// } else if (parent is InvocationExpression) {
// // TODO: handle invocations
// }
//
// if (resolveResult == null || resolveResult.ResolvedType == null)
// return null;
// delegateType = context.Document.Dom.GetType (resolveResult.ResolvedType);
// if (delegateType == null || delegateType.ClassType != ClassType.Delegate)
// return null;
//
// return anonymousMethodExpression;
// }
}
}

100
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/IntroduceFormatItem.cs

@ -0,0 +1,100 @@ @@ -0,0 +1,100 @@
//
// IntroduceFormatItem.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.PatternMatching;
using System.Collections.Generic;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
/// <summary>
/// Introduce format item. Works on strings that contain selections.
/// "this is <some> string" => string.Format ("this is {0} string", <some>)
/// </summary>
public class IntroduceFormatItem : IContextAction
{
readonly static MemberReferenceExpression PrototypeFormatReference = new MemberReferenceExpression (new TypeReferenceExpression (new PrimitiveType ("string")), "Format");
public bool IsValid (RefactoringContext context)
{
if (!context.IsSomethingSelected)
return false;
var pexpr = context.GetNode<PrimitiveExpression> ();
if (pexpr == null || !(pexpr.Value is string))
return false;
if (pexpr.LiteralValue.StartsWith ("@"))
return pexpr.StartLocation < new AstLocation (context.Location.Line, context.Location.Column - 1) &&
new AstLocation (context.Location.Line, context.Location.Column + 1) < pexpr.EndLocation;
return pexpr.StartLocation < context.Location && context.Location < pexpr.EndLocation;
}
public void Run (RefactoringContext context)
{
var pexpr = context.GetNode<PrimitiveExpression> ();
var invocation = context.GetNode<InvocationExpression> ();
if (invocation != null && invocation.Target.IsMatch (PrototypeFormatReference)) {
AddFormatCallToInvocation (context, pexpr, invocation);
return;
}
var arg = CreateFormatArgument (context);
var newInvocation = new InvocationExpression (PrototypeFormatReference.Clone ()) {
Arguments = { CreateFormatString (context, pexpr, 0), arg }
};
using (var script = context.StartScript ()) {
script.Replace (pexpr, newInvocation);
script.Select (arg);
}
}
void AddFormatCallToInvocation (RefactoringContext context, PrimitiveExpression pExpr, InvocationExpression invocation)
{
var newInvocation = (InvocationExpression)invocation.Clone ();
newInvocation.Arguments.First ().ReplaceWith (CreateFormatString (context, pExpr, newInvocation.Arguments.Count () - 1));
newInvocation.Arguments.Add (CreateFormatArgument (context));
using (var script = context.StartScript ()) {
script.Replace (invocation, newInvocation);
}
}
static PrimitiveExpression CreateFormatArgument (RefactoringContext context)
{
return new PrimitiveExpression (context.SelectedText);
}
static PrimitiveExpression CreateFormatString (RefactoringContext context, PrimitiveExpression pExpr, int argumentNumber)
{
var start = context.GetOffset (pExpr.StartLocation);
var end = context.GetOffset (pExpr.EndLocation);
return new PrimitiveExpression ("", context.GetText (start, context.SelectionStart - start) + "{" + argumentNumber + "}" + context.GetText (context.SelectionEnd, end - context.SelectionEnd));
}
}
}

61
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/InvertIf.cs

@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
//
// InvertIf.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class InvertIf : IContextAction
{
public bool IsValid (RefactoringContext context)
{
var ifStatement = GetIfElseStatement (context);
return ifStatement != null && !ifStatement.TrueStatement.IsNull && !ifStatement.FalseStatement.IsNull;
}
// TODO: Invert if without else
// ex. if (cond) DoSomething () == if (!cond) return; DoSomething ()
// beware of loop contexts return should be continue then.
public void Run (RefactoringContext context)
{
var ifStatement = GetIfElseStatement (context);
using (var script = context.StartScript ()) {
script.Replace (ifStatement.Condition, CSharpUtil.InvertCondition (ifStatement.Condition));
script.Replace (ifStatement.TrueStatement, ifStatement.FalseStatement);
script.Replace (ifStatement.FalseStatement, ifStatement.TrueStatement);
script.FormatText (ctx => GetIfElseStatement (ctx));
}
}
static IfElseStatement GetIfElseStatement (RefactoringContext context)
{
var result = context.GetNode<IfElseStatement> ();
if (result != null && result.IfToken.Contains (context.Location))
return result;
return null;
}
}
}

61
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/RemoveBraces.cs

@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
//
// RemoveBraces.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class RemoveBraces : IContextAction
{
public bool IsValid (RefactoringContext context)
{
return GetBlockStatement (context) != null;
}
public void Run (RefactoringContext context)
{
var block = GetBlockStatement (context);
using (var script = context.StartScript ()) {
script.Remove (block.LBraceToken);
script.Remove (block.RBraceToken);
script.FormatText (ctx => ctx.Unit.GetNodeAt (block.Parent.StartLocation));
}
}
static BlockStatement GetBlockStatement (RefactoringContext context)
{
var block = context.GetNode<BlockStatement> ();
if (block == null || block.LBraceToken.IsNull || block.RBraceToken.IsNull)
return null;
if (block.Parent.Role == TypeDeclaration.MemberRole)
return null;
if (block.Statements.Count () != 1)
return null;
return block;
}
}
}

53
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/ReplaceEmptyString.cs

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
//
// ReplaceEmptyString.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class ReplaceEmptyString : IContextAction
{
public bool IsValid (RefactoringContext context)
{
return GetEmptyString (context) != null;
}
public void Run (RefactoringContext context)
{
var expr = GetEmptyString (context);
using (var script = context.StartScript ()) {
script.Replace (expr, new MemberReferenceExpression (new TypeReferenceExpression (new PrimitiveType ("string")), "Empty"));
}
}
static PrimitiveExpression GetEmptyString (RefactoringContext context)
{
var node = context.GetNode<PrimitiveExpression> ();
if (node == null || !(node.Value is string) || node.Value.ToString () != "")
return null;
return node;
}
}
}

74
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/SplitDeclarationAndAssignment.cs

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
//
// SplitDeclarationAndAssignment.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Linq;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class SplitDeclarationAndAssignment : IContextAction
{
public bool IsValid (RefactoringContext context)
{
AstType type;
return GetVariableDeclarationStatement (context, out type) != null;
}
public void Run (RefactoringContext context)
{
AstType type;
var varDecl = GetVariableDeclarationStatement (context, out type);
var assign = new AssignmentExpression (new IdentifierExpression (varDecl.Variables.First ().Name), AssignmentOperatorType.Assign, varDecl.Variables.First ().Initializer.Clone ());
var newVarDecl = (VariableDeclarationStatement)varDecl.Clone ();
if (newVarDecl.Type.IsMatch (new SimpleType ("var")))
newVarDecl.Type = type;
newVarDecl.Variables.First ().Initializer = Expression.Null;
using (var script = context.StartScript ()) {
script.Replace (varDecl, varDecl.Parent is ForStatement ? (AstNode)assign : new ExpressionStatement (assign));
script.Insert (context.GetOffset (varDecl.StartLocation.Line, 1), newVarDecl);
}
}
static VariableDeclarationStatement GetVariableDeclarationStatement (RefactoringContext context, out AstType resolvedType)
{
var result = context.GetNode<VariableDeclarationStatement> ();
if (result != null && result.Variables.Count == 1 && !result.Variables.First ().Initializer.IsNull && result.Variables.First ().NameToken.Contains (context.Location.Line, context.Location.Column)) {
resolvedType = context.ResolveType (result.Variables.First ().Initializer);
if (resolvedType == null)
return null;
return result;
}
resolvedType = null;
return null;
}
}
}

56
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/SplitString.cs

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
//
// SplitString.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class SplitString: IContextAction
{
public bool IsValid (RefactoringContext context)
{
if (context.IsSomethingSelected)
return false;
var pexpr = context.GetNode<PrimitiveExpression> ();
if (pexpr == null || !(pexpr.Value is string))
return false;
if (pexpr.LiteralValue.StartsWith ("@"))
return pexpr.StartLocation < new AstLocation (context.Location.Line, context.Location.Column - 2) &&
new AstLocation (context.Location.Line, context.Location.Column + 2) < pexpr.EndLocation;
return pexpr.StartLocation < new AstLocation (context.Location.Line, context.Location.Column - 1) &&
new AstLocation (context.Location.Line, context.Location.Column + 1) < pexpr.EndLocation;
}
public void Run (RefactoringContext context)
{
var pexpr = context.GetNode<PrimitiveExpression> ();
int offset = context.GetOffset (context.Location);
using (var script = context.StartScript ()) {
script.Insert (offset, pexpr.LiteralValue.StartsWith ("@") ? "\" + @\"" : "\" + \"");
}
}
}
}

69
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/UseExplicitType.cs

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
//
// UseExplicitType.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class UseExplicitType: IContextAction
{
public bool IsValid (RefactoringContext context)
{
return GetVariableDeclarationStatement (context) != null;
}
// TODO: Resolving
public void Run (RefactoringContext context)
{
// var varDecl = GetVariableDeclarationStatement (context);
// var resolver = context.Resolver;
// var resolveResult = resolver.Resolve (varDecl.Variables.First ().Initializer.ToString (), context.Location);
//
// int offset = context.Document.Editor.LocationToOffset (varDecl.Type.StartLocation.Line, varDecl.Type.StartLocation.Column);
// int endOffset = context.Document.Editor.LocationToOffset (varDecl.Type.EndLocation.Line, varDecl.Type.EndLocation.Column);
// string text = context.OutputNode (ShortenTypeName (context.Document, resolveResult.ResolvedType), 0).Trim ();
// context.DoReplace (offset, endOffset - offset, text);
// context.CommitChanges ();
// context.Document.Editor.Caret.Offset = offset + text.Length;
}
static VariableDeclarationStatement GetVariableDeclarationStatement (RefactoringContext context)
{
// var result = context.GetNode<VariableDeclarationStatement> ();
// if (result != null && result.Variables.Count == 1 && !result.Variables.First ().Initializer.IsNull && result.Type.Contains (context.Location.Line, context.Location.Column) && result.Type.IsMatch (new SimpleType ("var"))) {
// var resolver = context.Resolver;
// var resolveResult = resolver.Resolve (result.Variables.First ().Initializer.ToString (), context.Location);
// if (resolveResult == null || resolveResult.ResolvedType == null || string.IsNullOrEmpty (resolveResult.ResolvedType.FullName))
// return null;
// return result;
//
// }
return null;
}
}
}

56
ICSharpCode.NRefactory/CSharp/Refactoring/ContextAction/UseVarKeyword.cs

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
//
// UseVarKeyword.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Linq;
using ICSharpCode.NRefactory.PatternMatching;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class UseVarKeyword: IContextAction
{
public bool IsValid (RefactoringContext context)
{
return GetVariableDeclarationStatement (context) != null;
}
public void Run (RefactoringContext context)
{
var varDecl = GetVariableDeclarationStatement (context);
using (var script = context.StartScript ()) {
script.Replace (varDecl.Type, new SimpleType ("var"));
}
}
static VariableDeclarationStatement GetVariableDeclarationStatement (RefactoringContext context)
{
var result = context.GetNode<VariableDeclarationStatement> ();
if (result != null && result.Variables.Count == 1 && !result.Variables.First ().Initializer.IsNull && result.Type.Contains (context.Location.Line, context.Location.Column) && !result.Type.IsMatch (new SimpleType ("var")))
return result;
return null;
}
}
}

44
ICSharpCode.NRefactory/CSharp/Refactoring/CreateLinkAction.cs

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
//
// CreateLinkAction.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public abstract class CreateLinkAction : Action
{
public IEnumerable<AstNode> Linked {
get;
private set;
}
public CreateLinkAction (IEnumerable<AstNode> linked)
{
this.Linked = linked;
}
}
}

39
ICSharpCode.NRefactory/CSharp/Refactoring/FormatTextAction.cs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
//
// FormatTextAction.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public abstract class FormatTextAction : Action
{
public Func<RefactoringContext, AstNode> Callback { get; private set; }
public FormatTextAction (Func<RefactoringContext, AstNode> callback)
{
this.Callback = callback;
}
}
}

75
ICSharpCode.NRefactory/CSharp/Refactoring/IActionFactory.cs

@ -0,0 +1,75 @@ @@ -0,0 +1,75 @@
//
// IChangeFactory.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
/// <summary>
/// A factory that creates the changes.
/// </summary>
public interface IActionFactory
{
TextReplaceAction CreateTextReplaceAction (int offset, int removedChars, string insertedText);
NodeOutputAction CreateNodeOutputAction (int offset, int removedChars, NodeOutput output);
NodeSelectionAction CreateNodeSelectionAction (AstNode node);
FormatTextAction CreateFormatTextAction (Func<RefactoringContext, AstNode> callback);
CreateLinkAction CreateLinkAction (IEnumerable<AstNode> linkedNodes);
}
public abstract class AbstractActionFactory : IActionFactory
{
#region IActionFactory implementation
public virtual TextReplaceAction CreateTextReplaceAction (int offset, int removedChars, string insertedText)
{
throw new NotImplementedException ();
}
public virtual NodeOutputAction CreateNodeOutputAction (int offset, int removedChars, NodeOutput output)
{
throw new NotImplementedException ();
}
public virtual NodeSelectionAction CreateNodeSelectionAction (AstNode node)
{
throw new NotImplementedException ();
}
public virtual FormatTextAction CreateFormatTextAction (Func<RefactoringContext, AstNode> callback)
{
throw new NotImplementedException ();
}
public virtual CreateLinkAction CreateLinkAction (IEnumerable<AstNode> linkedNodes)
{
throw new NotImplementedException ();
}
#endregion
}
}

36
ICSharpCode.NRefactory/CSharp/Refactoring/IContextAction.cs

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
//
// ContextAction.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public interface IContextAction
{
bool IsValid (RefactoringContext context);
void Run (RefactoringContext context);
}
}

120
ICSharpCode.NRefactory/CSharp/Refactoring/NodeOutputAction.cs

@ -0,0 +1,120 @@ @@ -0,0 +1,120 @@
//
// NodeOutputChange.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
/// <summary>
/// This is the node that should be outputted at a position.
/// </summary>
public class NodeOutput
{
public readonly Dictionary<AstNode, Segment> NodeSegments = new Dictionary<AstNode, Segment> ();
public string Text {
get;
set;
}
public class Segment : ISegment
{
public int Offset {
get;
set;
}
public int Length {
get {
return EndOffset - Offset;
}
}
public int EndOffset {
get;
set;
}
public Segment (int offset)
{
this.Offset = offset;
}
}
}
/// <summary>
/// Outputs an Ast node at a specific offset.
/// </summary>
public abstract class NodeOutputAction : TextReplaceAction
{
public NodeOutput NodeOutput {
get;
private set;
}
public override string InsertedText {
get {
return NodeOutput.Text;
}
set {
throw new NotSupportedException ("Changing text with this propery is not supported on NodeOutputChange.");
}
}
public NodeOutputAction (int offset, int removedChars, NodeOutput output) : base (offset, removedChars)
{
if (output == null)
throw new ArgumentNullException ("output");
this.NodeOutput = output;
}
}
/// <summary>
/// An (Offset,Length)-pair.
/// </summary>
public interface ISegment
{
/// <summary>
/// Gets the start offset of the segment.
/// </summary>
int Offset { get; }
/// <summary>
/// Gets the length of the segment.
/// </summary>
/// <remarks>Must not be negative.</remarks>
int Length { get; }
/// <summary>
/// Gets the end offset of the segment.
/// </summary>
/// <remarks>EndOffset = Offset + Length;</remarks>
int EndOffset { get; }
}
}

40
ICSharpCode.NRefactory/CSharp/Refactoring/NodeSelectionAction.cs

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
//
// SelectionAction.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public abstract class NodeSelectionAction : Action
{
public AstNode AstNode { get; private set; }
public NodeSelectionAction (AstNode astNode)
{
this.AstNode = astNode;
}
}
}

109
ICSharpCode.NRefactory/CSharp/Refactoring/RefactoringContext.cs

@ -0,0 +1,109 @@ @@ -0,0 +1,109 @@
//
// RefactoringContext.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public abstract class RefactoringContext : AbstractActionFactory
{
public CompilationUnit Unit {
get;
protected set;
}
public AstLocation Location {
get;
protected set;
}
public abstract bool HasCSharp3Support {
get;
}
public abstract CSharpFormattingOptions FormattingOptions {
get;
}
public abstract AstType CreateShortType (AstType fullType);
public abstract AstType CreateShortType (string fullTypeName);
public AstNode GetNode ()
{
return Unit.GetNodeAt (Location);
}
public T GetNode<T> () where T : AstNode
{
return Unit.GetNodeAt<T> (Location);
}
public abstract Script StartScript ();
#region Text stuff
public abstract string EolMarker { get; }
public abstract bool IsSomethingSelected { get; }
public abstract string SelectedText { get; }
public abstract int SelectionStart { get; }
public abstract int SelectionEnd { get; }
public abstract int SelectionLength { get; }
public abstract int GetOffset (AstLocation location);
public int GetOffset (int line, int col)
{
return GetOffset (new AstLocation (line, col));
}
public abstract AstLocation GetLocation (int offset);
public abstract string GetText (int offset, int length);
#endregion
#region Resolving
public abstract AstType ResolveType (AstNode node);
#endregion
public string GetNameProposal (string name, bool camelCase = true)
{
string baseName = (camelCase ? char.ToLower (name [0]) : char.ToUpper (name [0])) + name.Substring (1);
var type = GetNode<TypeDeclaration> ();
if (type == null)
return baseName;
int number = -1;
string proposedName;
do {
proposedName = AppendNumberToName (baseName, number++);
} while (type.Members.Select (m => m.GetChildByRole (AstNode.Roles.Identifier)).Any (n => n.Name == proposedName));
return proposedName;
}
static string AppendNumberToName (string baseName, int number)
{
return baseName + (number > 0 ? (number + 1).ToString () : "");
}
}
}

156
ICSharpCode.NRefactory/CSharp/Refactoring/Script.cs

@ -0,0 +1,156 @@ @@ -0,0 +1,156 @@
//
// Script.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public abstract class Script : IDisposable
{
public RefactoringContext Context {
get;
private set;
}
protected readonly List<Action> changes = new List<Action> ();
public IEnumerable<Action> Actions {
get {
return changes;
}
}
public Script (RefactoringContext context)
{
if (context == null)
throw new ArgumentNullException ("context");
this.Context = context;
}
public void Queue (Action change)
{
changes.Add (change);
}
public void Insert (int offset, string text)
{
Queue (Context.CreateTextReplaceAction (offset, 0, text));
}
public void Insert (int offset, AstNode node)
{
var output = OutputNode (GetIndentLevelAt (offset), node);
Queue (Context.CreateNodeOutputAction (offset, 0, output));
}
public void Link (params AstNode[] nodes)
{
Queue (Context.CreateLinkAction (nodes));
}
public void Link (IEnumerable<AstNode> nodes)
{
Queue (Context.CreateLinkAction (nodes));
}
public void Remove (AstNode node)
{
var startOffset = Context.GetOffset (node.StartLocation);
var endOffset = Context.GetOffset (node.EndLocation);
Remove (startOffset, endOffset - startOffset);
}
public void Remove (int offset, int length)
{
Queue (Context.CreateTextReplaceAction (offset, length, null));
}
public void Replace (int offset, int length, string text)
{
Queue (Context.CreateTextReplaceAction (offset, length, text));
}
public void Replace (AstNode node, AstNode replaceWith)
{
var startOffset = Context.GetOffset (node.StartLocation);
var endOffset = Context.GetOffset (node.EndLocation);
int level = 0;
// if (!(replaceWith is Expression))
// level = GetIndentLevelAt (startOffset);
Queue (Context.CreateNodeOutputAction (startOffset, endOffset - startOffset, OutputNode (level, replaceWith)));
}
public void FormatText (Func<RefactoringContext, AstNode> callback)
{
Queue (Context.CreateFormatTextAction (callback));
}
public void Select (AstNode node)
{
Queue (Context.CreateNodeSelectionAction (node));
}
int GetIndentLevelAt (int offset)
{
var node = Context.Unit.GetNodeAt (Context.GetLocation (offset));
int level = 0;
while (node != null) {
if (node is BlockStatement || node is TypeDeclaration || node is NamespaceDeclaration)
level++;
node = node.Parent;
}
return level;
}
NodeOutput OutputNode (int indentLevel, AstNode node)
{
NodeOutput result = new NodeOutput ();
var formatter = new StringBuilderOutputFormatter ();
formatter.Indentation = indentLevel;
formatter.EolMarker = Context.EolMarker;
if (node is Statement)
formatter.NewLine ();
var visitor = new OutputVisitor (formatter, Context.FormattingOptions);
visitor.OutputStarted += (sender, e) => {
result.NodeSegments [e.AstNode] = new NodeOutput.Segment (formatter.Length);
};
visitor.OutputFinished += (sender, e) => {
result.NodeSegments [e.AstNode].EndOffset = formatter.Length;
};
node.AcceptVisitor (visitor, null);
result.Text = formatter.ToString ().TrimEnd ();
if (node is FieldDeclaration)
result.Text += Context.EolMarker;
return result;
}
#region IDisposable implementation
public abstract void Dispose ();
#endregion
}
}

158
ICSharpCode.NRefactory/CSharp/Refactoring/StringBuilderOutputFormatter.cs

@ -0,0 +1,158 @@ @@ -0,0 +1,158 @@
//
// StringBuilderOutputFormatter.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Text;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class StringBuilderOutputFormatter : IOutputFormatter
{
readonly StringBuilder sb = new StringBuilder ();
int indentation;
bool needsIndent = true;
public int Length {
get {
WriteIndentation ();
return sb.Length;
}
}
public int Indentation {
get {
return this.indentation;
}
set {
indentation = value;
}
}
public string EolMarker {
get;
set;
}
public override string ToString ()
{
return sb.ToString ();
}
public void WriteIdentifier (string ident)
{
WriteIndentation ();
sb.Append (ident);
}
public void WriteKeyword (string keyword)
{
WriteIndentation ();
sb.Append (keyword);
}
public void WriteToken (string token)
{
WriteIndentation ();
sb.Append (token);
}
public void Space ()
{
WriteIndentation ();
sb.Append (' ');
}
public void OpenBrace (BraceStyle style)
{
WriteIndentation ();
sb.Append (' ');
sb.Append ('{');
Indent ();
NewLine ();
}
public void CloseBrace (BraceStyle style)
{
Unindent ();
WriteIndentation ();
sb.Append ('}');
}
void WriteIndentation ()
{
if (needsIndent) {
needsIndent = false;
for (int i = 0; i < indentation; i++) {
sb.Append ('\t');
}
}
}
public void NewLine ()
{
sb.Append (EolMarker);
needsIndent = true;
}
public void Indent ()
{
indentation++;
}
public void Unindent ()
{
indentation--;
}
public void WriteComment (CommentType commentType, string content)
{
WriteIndentation ();
switch (commentType) {
case CommentType.SingleLine:
sb.Append ("//");
sb.AppendLine (content);
break;
case CommentType.MultiLine:
sb.Append ("/*");
sb.Append (content);
sb.Append ("*/");
break;
case CommentType.Documentation:
sb.Append ("///");
sb.AppendLine (content);
break;
}
}
public virtual void StartNode (AstNode node)
{
}
public virtual void EndNode (AstNode node)
{
}
}
}

134
ICSharpCode.NRefactory/CSharp/Refactoring/TextReplaceAction.cs

@ -0,0 +1,134 @@ @@ -0,0 +1,134 @@
//
// TextReplaceChange.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
/// <summary>
/// This is the base action for changes in a text document.
/// </summary>
public abstract class TextReplaceAction : Action
{
/// <summary>
/// Gets or sets the offset.
/// </summary>
/// <value>
/// The offset of the replace.
/// </value>
public int Offset {
get;
set;
}
int removedChars;
/// <summary>
/// Gets or sets the numer of chars to removed.
/// </summary>
/// <value>
/// The numer of chars to remove.
/// </value>
/// <exception cref='ArgumentOutOfRangeException'>
/// Is thrown when an argument passed to a method is invalid because it is outside the allowable range of values as
/// specified by the method.
/// </exception>
public int RemovedChars {
get {
return removedChars;
}
set {
if (value < 0)
throw new ArgumentOutOfRangeException ("RemovedChars", "needs to be >= 0");
removedChars = value;
}
}
/// <summary>
/// Gets or sets the inserted text.
/// </summary>
/// <value>
/// The text to insert.
/// </value>
public virtual string InsertedText {
get;
set;
}
/// <summary>
/// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.TextReplaceAction"/> class.
/// </summary>
/// <param name='offset'>
/// The offset of the replace.
/// </param>
/// <param name='removedChars'>
/// The numer of chars to remove.
/// </param>
/// <exception cref='ArgumentOutOfRangeException'>
/// Is thrown when an argument passed to a method is invalid because it is outside the allowable range of values as
/// specified by the method.
/// </exception>
protected TextReplaceAction (int offset, int removedChars)
{
if (removedChars < 0)
throw new ArgumentOutOfRangeException ("removedChars", "removedChars needs to be >= 0");
if (offset < 0)
throw new ArgumentOutOfRangeException ("offset", "offset needs to be >= 0");
this.removedChars = removedChars;
this.Offset = offset;
}
/// <summary>
/// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.TextReplaceAction"/> class.
/// </summary>
/// <param name='offset'>
/// The offset of the replace.
/// </param>
/// <param name='removedChars'>
/// The numer of chars to remove.
/// </param>
/// <param name='insertedText'>
/// The text to insert.
/// </param>
/// <exception cref='ArgumentOutOfRangeException'>
/// Is thrown when an argument passed to a method is invalid because it is outside the allowable range of values as
/// specified by the method.
public TextReplaceAction (int offset, int removedChars, string insertedText) : this (offset, removedChars)
{
this.InsertedText = insertedText;
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents the current <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.TextReplaceAction"/>.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents the current <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.TextReplaceAction"/>.
/// </returns>
public override string ToString ()
{
return string.Format ("[TextReplaceAction: Offset={0}, RemovedChars={1}, InsertedText={2}]", Offset, RemovedChars, InsertedText);
}
}
}

30
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</ProjectGuid>
@ -347,7 +347,6 @@ @@ -347,7 +347,6 @@
<Compile Include="CSharp\Ast\Expressions\EmptyExpression.cs" />
<Compile Include="CSharp\Formatter\AstFormattingVisitor.cs" />
<Compile Include="CSharp\Formatter\ITextEditorAdapter.cs" />
<Compile Include="CSharp\Formatter\Change.cs" />
<Compile Include="CSharp\Ast\TypeMembers\FixedFieldDeclaration.cs" />
<Compile Include="CSharp\Ast\TypeMembers\FixedVariableInitializer.cs" />
<Compile Include="CSharp\Ast\GeneralScope\ExternAliasDeclaration.cs" />
@ -358,6 +357,33 @@ @@ -358,6 +357,33 @@
<Compile Include="CSharp\Ast\ObservableAstVisitor.cs" />
<Compile Include="CSharp\Ast\CSharpUtil.cs" />
<Compile Include="CSharp\Parser\mcs\async.cs" />
<Compile Include="CSharp\Refactoring\Action.cs" />
<Compile Include="CSharp\Refactoring\CreateLinkAction.cs" />
<Compile Include="CSharp\Refactoring\FormatTextAction.cs" />
<Compile Include="CSharp\Refactoring\IActionFactory.cs" />
<Compile Include="CSharp\Refactoring\IContextAction.cs" />
<Compile Include="CSharp\Refactoring\NodeOutputAction.cs" />
<Compile Include="CSharp\Refactoring\NodeSelectionAction.cs" />
<Compile Include="CSharp\Refactoring\RefactoringContext.cs" />
<Compile Include="CSharp\Refactoring\Script.cs" />
<Compile Include="CSharp\Refactoring\StringBuilderOutputFormatter.cs" />
<Compile Include="CSharp\Refactoring\TextReplaceAction.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\AddAnotherAccessor.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\CheckIfParameterIsNull.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\ConvertDecToHex.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\ConvertForeachToFor.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\ConvertHexToDec.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\CreateBackingStore.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\FlipOperatorArguments.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\GenerateSwitchLabels.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\InsertAnonymousMethodSignature.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\IntroduceFormatItem.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\InvertIf.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\RemoveBraces.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\ReplaceEmptyString.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\SplitDeclarationAndAssignment.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\SplitString.cs" />
<Compile Include="CSharp\Refactoring\ContextAction\UseExplicitType.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="CSharp\" />

Loading…
Cancel
Save