27 changed files with 484 additions and 814 deletions
@ -1,52 +0,0 @@
@@ -1,52 +0,0 @@
|
||||
//
|
||||
// Change.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 class for all refactoring operations that are performed.
|
||||
/// </summary>
|
||||
public abstract class Action |
||||
{ |
||||
/// <summary>
|
||||
/// Gets or sets the description.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A brief description of the refactoring change.
|
||||
/// </value>
|
||||
public string Description { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Performs the change.
|
||||
/// </summary>
|
||||
public abstract void Perform (Script script); |
||||
} |
||||
} |
||||
|
@ -1,44 +0,0 @@
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// 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; |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,39 +0,0 @@
@@ -1,39 +0,0 @@
|
||||
//
|
||||
// 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; |
||||
} |
||||
} |
||||
} |
@ -1,75 +0,0 @@
@@ -1,75 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
} |
||||
|
||||
} |
@ -1,118 +0,0 @@
@@ -1,118 +0,0 @@
|
||||
//
|
||||
// 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; |
||||
using ICSharpCode.NRefactory.Editor; |
||||
|
||||
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 void Trim () |
||||
{ |
||||
for (int i = 0; i < Text.Length; i++) { |
||||
char ch = Text [i]; |
||||
if (ch != ' ' && ch != '\t') { |
||||
if (i > 0) { |
||||
Text = Text.Substring (i); |
||||
foreach (var seg in NodeSegments.Values) { |
||||
seg.Offset -= i; |
||||
} |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public class Segment : ISegment |
||||
{ |
||||
public int Offset { |
||||
get; |
||||
internal set; |
||||
} |
||||
|
||||
public int Length { |
||||
get; |
||||
internal set; |
||||
} |
||||
|
||||
public int EndOffset { |
||||
get { |
||||
return Offset + Length; |
||||
} |
||||
} |
||||
|
||||
public Segment (int offset) |
||||
{ |
||||
this.Offset = offset; |
||||
} |
||||
|
||||
public override string ToString () |
||||
{ |
||||
return string.Format ("[NodeOutput.Segment: Offset={0}, Length={1}, EndOffset={2}]", Offset, Length, EndOffset); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
/// <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; |
||||
} |
||||
} |
||||
} |
@ -1,40 +0,0 @@
@@ -1,40 +0,0 @@
|
||||
//
|
||||
// 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; |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,134 +0,0 @@
@@ -1,134 +0,0 @@
|
||||
//
|
||||
// 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 == null ? "<null>" : InsertedText.Replace ("\t", "\\t").Replace ("\n", "\\n").Replace ("\r", "\\r")); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue