Browse Source

Added CancellationToken support for the context actions.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
b4c19465bd
  1. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/AddAnotherAccessor.cs
  2. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/CheckIfParameterIsNull.cs
  3. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/ConvertDecToHex.cs
  4. 9
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/ConvertForeachToFor.cs
  5. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/ConvertHexToDec.cs
  6. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/CreateBackingStore.cs
  7. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/CreateEventInvocator.cs
  8. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/CreateField.cs
  9. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/CreateLocalVariable.cs
  10. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/CreateProperty.cs
  11. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/FlipOperatorArguments.cs
  12. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/GenerateGetter.cs
  13. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/GenerateProperty.cs
  14. 5
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/GenerateSwitchLabels.cs
  15. 11
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/InsertAnonymousMethodSignature.cs
  16. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/IntroduceFormatItem.cs
  17. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/InvertIf.cs
  18. 19
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/RemoveBackingStore.cs
  19. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/RemoveBraces.cs
  20. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/RemoveRegion.cs
  21. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/ReplaceEmptyString.cs
  22. 7
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/SplitDeclarationAndAssignment.cs
  23. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/SplitString.cs
  24. 13
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/UseExplicitType.cs
  25. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/UseVarKeyword.cs
  26. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/IContextAction.cs
  27. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/RefactoringContext.cs

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

@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
// 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.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
@ -31,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -31,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
/// </summary>
public class AddAnotherAccessor : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
var pdecl = GetPropertyDeclaration (context);
if (pdecl == null)

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

@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
// THE SOFTWARE.
using ICSharpCode.NRefactory.PatternMatching;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
@ -34,7 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -34,7 +35,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
public class CheckIfParameterIsNull : IContextAction
{
//TODO: Create 'multiple' null checks when more than 1 parameter is selected.
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
var parameter = GetParameterDeclaration (context);
if (parameter == null)

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

@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
// 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.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
@ -31,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -31,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
/// </summary>
public class ConvertDecToHex : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
var pexpr = context.GetNode<PrimitiveExpression> ();
if (pexpr == null || pexpr.LiteralValue.StartsWith ("0X", System.StringComparison.OrdinalIgnoreCase))

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

@ -26,6 +26,7 @@ @@ -26,6 +26,7 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
@ -34,9 +35,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -34,9 +35,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
/// </summary>
public class ConvertForeachToFor : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
return GetForeachStatement (context) != null;
return GetForeachStatement (context, cancellationToken) != null;
}
static string GetCountProperty (IType type)
@ -81,13 +82,13 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -81,13 +82,13 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
}
static ForeachStatement GetForeachStatement (RefactoringContext context)
static ForeachStatement GetForeachStatement (RefactoringContext context, CancellationToken cancellationToken = default (CancellationToken))
{
var astNode = context.GetNode ();
if (astNode == null)
return null;
var result = (astNode as ForeachStatement) ?? astNode.Parent as ForeachStatement;
if (result == null || context.Resolve (result.InExpression) == null)
if (result == null || context.Resolve (result.InExpression, cancellationToken) == null)
return null;
return result;
}

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

@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
// 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.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
@ -31,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -31,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
/// </summary>
public class ConvertHexToDec: IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
var pexpr = context.GetNode<PrimitiveExpression> ();
if (pexpr == null || !pexpr.LiteralValue.StartsWith ("0X", System.StringComparison.OrdinalIgnoreCase))

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

@ -24,12 +24,13 @@ @@ -24,12 +24,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class CreateBackingStore : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
var propertyDeclaration = context.GetNode<PropertyDeclaration> ();
return propertyDeclaration != null &&

3
ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/CreateEventInvocator.cs

@ -27,12 +27,13 @@ using System; @@ -27,12 +27,13 @@ using System;
using System.Linq;
using System.Collections.Generic;
using ICSharpCode.NRefactory.TypeSystem;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class CreateEventInvocator : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
VariableInitializer initializer;
var eventDeclaration = GetEventDeclaration (context, out initializer);

3
ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/CreateField.cs

@ -28,12 +28,13 @@ using System; @@ -28,12 +28,13 @@ using System;
using ICSharpCode.NRefactory.PatternMatching;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class CreateField : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
var identifier = GetIdentifier (context);
if (identifier == null)

3
ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/CreateLocalVariable.cs

@ -28,6 +28,7 @@ using ICSharpCode.NRefactory.PatternMatching; @@ -28,6 +28,7 @@ using ICSharpCode.NRefactory.PatternMatching;
using System.Linq;
using System.Collections.Generic;
using ICSharpCode.NRefactory.TypeSystem;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
@ -58,7 +59,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -58,7 +59,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
return expressions;
}
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
if (GetUnresolvedArguments (context).Count > 0)
return true;

3
ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/CreateProperty.cs

@ -26,12 +26,13 @@ @@ -26,12 +26,13 @@
using System;
using ICSharpCode.NRefactory.PatternMatching;
using System.Linq;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class CreateProperty : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
var identifier = CreateField.GetIdentifier (context);
if (identifier == null)

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

@ -24,12 +24,13 @@ @@ -24,12 +24,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class FlipOperatorArguments : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
return GetBinaryOperatorExpression (context) != null;
}

3
ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/GenerateGetter.cs

@ -27,12 +27,13 @@ @@ -27,12 +27,13 @@
using System;
using ICSharpCode.NRefactory.PatternMatching;
using System.Linq;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class GenerateGetter : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
var initializer = GetVariableInitializer (context);
if (initializer == null || !initializer.NameToken.Contains (context.Location.Line, context.Location.Column))

3
ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/GenerateProperty.cs

@ -26,12 +26,13 @@ @@ -26,12 +26,13 @@
using System;
using ICSharpCode.NRefactory.PatternMatching;
using System.Linq;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class GenerateProperty : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
var initializer = GetVariableInitializer (context);
if (initializer == null || !initializer.NameToken.Contains (context.Location.Line, context.Location.Column))

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

@ -25,17 +25,18 @@ @@ -25,17 +25,18 @@
// THE SOFTWARE.
using System;
using ICSharpCode.NRefactory.TypeSystem;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class GenerateSwitchLabels : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
var switchStatement = GetSwitchStatement (context);
if (switchStatement == null)
return false;
var result = context.Resolve (switchStatement.Expression);
var result = context.Resolve (switchStatement.Expression, cancellationToken);
if (result == null)
return false;
return result.Type.Kind == TypeKind.Enum;

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

@ -27,15 +27,16 @@ using System; @@ -27,15 +27,16 @@ using System;
using ICSharpCode.NRefactory.TypeSystem;
using System.Linq;
using System.Text;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class InsertAnonymousMethodSignature : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
IType type;
return GetAnonymousMethodExpression (context, out type) != null;
return GetAnonymousMethodExpression (context, out type, cancellationToken) != null;
}
public void Run (RefactoringContext context)
@ -63,7 +64,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -63,7 +64,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
}
static AnonymousMethodExpression GetAnonymousMethodExpression (RefactoringContext context, out IType delegateType)
static AnonymousMethodExpression GetAnonymousMethodExpression (RefactoringContext context, out IType delegateType, CancellationToken cancellationToken = default(CancellationToken))
{
delegateType = null;
@ -75,9 +76,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -75,9 +76,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var parent = anonymousMethodExpression.Parent;
if (parent is AssignmentExpression) {
resolvedType = context.Resolve (((AssignmentExpression)parent).Left).Type;
resolvedType = context.Resolve (((AssignmentExpression)parent).Left, cancellationToken).Type;
} else if (parent is VariableInitializer) {
resolvedType = context.Resolve (((VariableDeclarationStatement)parent.Parent).Type).Type;
resolvedType = context.Resolve (((VariableDeclarationStatement)parent.Parent).Type, cancellationToken).Type;
} else if (parent is InvocationExpression) {
// TODO: handle invocations
}

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

@ -28,6 +28,7 @@ using System; @@ -28,6 +28,7 @@ using System;
using ICSharpCode.NRefactory.PatternMatching;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
@ -39,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -39,7 +40,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
readonly static MemberReferenceExpression PrototypeFormatReference = new MemberReferenceExpression (new TypeReferenceExpression (new PrimitiveType ("string")), "Format");
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
if (!context.IsSomethingSelected)
return false;

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

@ -24,12 +24,13 @@ @@ -24,12 +24,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class InvertIf : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
var ifStatement = GetIfElseStatement (context);
return ifStatement != null && !ifStatement.TrueStatement.IsNull && !ifStatement.FalseStatement.IsNull;

19
ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/RemoveBackingStore.cs

@ -28,14 +28,15 @@ using System.Linq; @@ -28,14 +28,15 @@ using System.Linq;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class RemoveBackingStore : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
return GetBackingField (context) != null;
return GetBackingField (context, cancellationToken) != null;
}
public void Run (RefactoringContext context)
@ -75,7 +76,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -75,7 +76,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
// }
// }
//
static IField GetBackingField (RefactoringContext context)
static IField GetBackingField (RefactoringContext context, CancellationToken cancellationToken = default(CancellationToken))
{
var propertyDeclaration = context.GetNode<PropertyDeclaration> ();
// automatic properties always need getter & setter
@ -83,10 +84,10 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -83,10 +84,10 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
return null;
if (!context.HasCSharp3Support || propertyDeclaration.HasModifier (ICSharpCode.NRefactory.CSharp.Modifiers.Abstract) || ((TypeDeclaration)propertyDeclaration.Parent).ClassType == ClassType.Interface)
return null;
var getterField = ScanGetter (context, propertyDeclaration);
var getterField = ScanGetter (context, propertyDeclaration, cancellationToken);
if (getterField == null)
return null;
var setterField = ScanSetter (context, propertyDeclaration);
var setterField = ScanSetter (context, propertyDeclaration, cancellationToken);
if (setterField == null)
return null;
if (getterField.Region != setterField.Region)
@ -94,20 +95,20 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -94,20 +95,20 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
return getterField;
}
internal static IField ScanGetter (RefactoringContext context, PropertyDeclaration propertyDeclaration)
internal static IField ScanGetter (RefactoringContext context, PropertyDeclaration propertyDeclaration, CancellationToken cancellationToken = default(CancellationToken))
{
if (propertyDeclaration.Getter.Body.Statements.Count != 1)
return null;
var returnStatement = propertyDeclaration.Getter.Body.Statements.First () as ReturnStatement;
if (returnStatement == null)
return null;
var result = context.Resolve (returnStatement.Expression);
var result = context.Resolve (returnStatement.Expression, cancellationToken);
if (result == null || !(result is MemberResolveResult))
return null;
return ((MemberResolveResult)result).Member as IField;
}
internal static IField ScanSetter (RefactoringContext context, PropertyDeclaration propertyDeclaration)
internal static IField ScanSetter (RefactoringContext context, PropertyDeclaration propertyDeclaration, CancellationToken cancellationToken = default(CancellationToken))
{
if (propertyDeclaration.Setter.Body.Statements.Count != 1)
return null;
@ -115,7 +116,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -115,7 +116,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
var assignment = setAssignment != null ? setAssignment.Expression as AssignmentExpression : null;
if (assignment == null || assignment.Operator != AssignmentOperatorType.Assign)
return null;
var result = context.Resolve (assignment.Left);
var result = context.Resolve (assignment.Left, cancellationToken);
if (result == null || !(result is MemberResolveResult))
return null;
return ((MemberResolveResult)result).Member as IField;

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

@ -25,12 +25,13 @@ @@ -25,12 +25,13 @@
// THE SOFTWARE.
using System;
using System.Linq;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class RemoveBraces : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
return GetBlockStatement (context) != null;
}

3
ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/RemoveRegion.cs

@ -25,12 +25,13 @@ @@ -25,12 +25,13 @@
// THE SOFTWARE.
using System;
using System.Linq;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class RemoveRegion : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
return GetDirective (context) != null;
}

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

@ -24,12 +24,13 @@ @@ -24,12 +24,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class ReplaceEmptyString : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
return GetEmptyString (context) != null;
}

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

@ -26,15 +26,16 @@ @@ -26,15 +26,16 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.PatternMatching;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class SplitDeclarationAndAssignment : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
AstType type;
return GetVariableDeclarationStatement (context, out type) != null;
return GetVariableDeclarationStatement (context, out type, cancellationToken) != null;
}
public void Run (RefactoringContext context)
@ -57,7 +58,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -57,7 +58,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
}
}
static VariableDeclarationStatement GetVariableDeclarationStatement (RefactoringContext context, out AstType resolvedType)
static VariableDeclarationStatement GetVariableDeclarationStatement (RefactoringContext context, out AstType resolvedType, CancellationToken cancellationToken = default(CancellationToken))
{
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)) {

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

@ -24,12 +24,13 @@ @@ -24,12 +24,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class SplitString: IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
if (context.IsSomethingSelected)
return false;

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

@ -27,23 +27,24 @@ using System; @@ -27,23 +27,24 @@ using System;
using System.Linq;
using ICSharpCode.NRefactory.PatternMatching;
using ICSharpCode.NRefactory.TypeSystem;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class UseExplicitType: IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
var varDecl = GetVariableDeclarationStatement (context);
var varDecl = GetVariableDeclarationStatement (context, cancellationToken);
IType type;
if (varDecl != null) {
type = context.Resolve (varDecl.Variables.First ().Initializer).Type;
type = context.Resolve (varDecl.Variables.First ().Initializer, cancellationToken).Type;
} else {
var foreachStatement = GetForeachStatement (context);
if (foreachStatement == null)
return false;
type = context.Resolve (foreachStatement.VariableType).Type;
type = context.Resolve (foreachStatement.VariableType, cancellationToken).Type;
}
return !type.Equals (SpecialType.NullType) && !type.Equals (SpecialType.UnknownType);
@ -66,11 +67,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -66,11 +67,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
static readonly AstType varType = new SimpleType ("var");
static VariableDeclarationStatement GetVariableDeclarationStatement (RefactoringContext context)
static VariableDeclarationStatement GetVariableDeclarationStatement (RefactoringContext context, CancellationToken cancellationToken = default(CancellationToken))
{
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 (varType)) {
if (context.Resolve (result.Variables.First ().Initializer) == null)
if (context.Resolve (result.Variables.First ().Initializer, cancellationToken) == null)
return null;
return result;
}

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

@ -26,12 +26,13 @@ @@ -26,12 +26,13 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.PatternMatching;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public class UseVarKeyword : IContextAction
{
public bool IsValid (RefactoringContext context)
public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{
return GetVariableDeclarationStatement (context) != null || GetForeachStatement (context) != null;
}

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

@ -24,12 +24,13 @@ @@ -24,12 +24,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
public interface IContextAction
{
bool IsValid (RefactoringContext context);
bool IsValid (RefactoringContext context, CancellationToken cancellationToken);
void Run (RefactoringContext context);
}
}

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

@ -30,6 +30,7 @@ using ICSharpCode.NRefactory.Semantics; @@ -30,6 +30,7 @@ using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.NRefactory.Editor;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
@ -122,7 +123,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -122,7 +123,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
#endregion
#region Resolving
public abstract ResolveResult Resolve (AstNode expression);
public abstract ResolveResult Resolve (AstNode expression, CancellationToken cancellationToken = default (CancellationToken));
#endregion
public string GetNameProposal (string name, bool camelCase = true)

Loading…
Cancel
Save