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 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring namespace ICSharpCode.NRefactory.CSharp.Refactoring
{ {
@ -31,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
/// </summary> /// </summary>
public class AddAnotherAccessor : IContextAction public class AddAnotherAccessor : IContextAction
{ {
public bool IsValid (RefactoringContext context) public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{ {
var pdecl = GetPropertyDeclaration (context); var pdecl = GetPropertyDeclaration (context);
if (pdecl == null) if (pdecl == null)

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

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

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

@ -23,6 +23,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring namespace ICSharpCode.NRefactory.CSharp.Refactoring
{ {
@ -31,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
/// </summary> /// </summary>
public class ConvertDecToHex : IContextAction public class ConvertDecToHex : IContextAction
{ {
public bool IsValid (RefactoringContext context) public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{ {
var pexpr = context.GetNode<PrimitiveExpression> (); var pexpr = context.GetNode<PrimitiveExpression> ();
if (pexpr == null || pexpr.LiteralValue.StartsWith ("0X", System.StringComparison.OrdinalIgnoreCase)) if (pexpr == null || pexpr.LiteralValue.StartsWith ("0X", System.StringComparison.OrdinalIgnoreCase))

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

@ -26,6 +26,7 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring namespace ICSharpCode.NRefactory.CSharp.Refactoring
{ {
@ -34,9 +35,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
/// </summary> /// </summary>
public class ConvertForeachToFor : IContextAction 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) static string GetCountProperty (IType type)
@ -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 (); var astNode = context.GetNode ();
if (astNode == null) if (astNode == null)
return null; return null;
var result = (astNode as ForeachStatement) ?? astNode.Parent as ForeachStatement; 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 null;
return result; return result;
} }

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

@ -23,6 +23,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring namespace ICSharpCode.NRefactory.CSharp.Refactoring
{ {
@ -31,7 +32,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
/// </summary> /// </summary>
public class ConvertHexToDec: IContextAction public class ConvertHexToDec: IContextAction
{ {
public bool IsValid (RefactoringContext context) public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{ {
var pexpr = context.GetNode<PrimitiveExpression> (); var pexpr = context.GetNode<PrimitiveExpression> ();
if (pexpr == null || !pexpr.LiteralValue.StartsWith ("0X", System.StringComparison.OrdinalIgnoreCase)) if (pexpr == null || !pexpr.LiteralValue.StartsWith ("0X", System.StringComparison.OrdinalIgnoreCase))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -28,6 +28,7 @@ using System;
using ICSharpCode.NRefactory.PatternMatching; using ICSharpCode.NRefactory.PatternMatching;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring 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"); 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) if (!context.IsSomethingSelected)
return false; return false;

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

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

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

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

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

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

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

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

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

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

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

@ -26,15 +26,16 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.PatternMatching; using ICSharpCode.NRefactory.PatternMatching;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring namespace ICSharpCode.NRefactory.CSharp.Refactoring
{ {
public class SplitDeclarationAndAssignment : IContextAction public class SplitDeclarationAndAssignment : IContextAction
{ {
public bool IsValid (RefactoringContext context) public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{ {
AstType type; AstType type;
return GetVariableDeclarationStatement (context, out type) != null; return GetVariableDeclarationStatement (context, out type, cancellationToken) != null;
} }
public void Run (RefactoringContext context) public void Run (RefactoringContext context)
@ -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> (); 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)) { 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 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using System.Threading;
namespace ICSharpCode.NRefactory.CSharp.Refactoring namespace ICSharpCode.NRefactory.CSharp.Refactoring
{ {
public class SplitString: IContextAction public class SplitString: IContextAction
{ {
public bool IsValid (RefactoringContext context) public bool IsValid (RefactoringContext context, CancellationToken cancellationToken)
{ {
if (context.IsSomethingSelected) if (context.IsSomethingSelected)
return false; return false;

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

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

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

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

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

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

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

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

Loading…
Cancel
Save