public static void ComputeRefactoring(RefactoringContext context, TypeParameterConstraintClauseSyntax constraintClause) { GenericInfo genericInfo = SyntaxInfo.GenericInfo(constraintClause); if (!genericInfo.Success) { return; } SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = genericInfo.ConstraintClauses; if (constraintClauses.IsSingleLine()) { if (constraintClauses.Count > 1) { context.RegisterRefactoring( "Wrap constraints", ct => { GenericInfo newInfo = WrapConstraints(genericInfo); return(context.Document.ReplaceNodeAsync(genericInfo.Node, newInfo.Node, ct)); }, RefactoringDescriptors.WrapConstraintClauses); } } else if (constraintClause.DescendantTrivia(constraintClause.Span).All(f => f.IsWhitespaceOrEndOfLineTrivia()) && constraintClauses[0].GetFirstToken().GetPreviousToken().TrailingTrivia.IsEmptyOrWhitespace()) { context.RegisterRefactoring( "Unwrap constraints", ct => { GenericInfo newInfo = UnwrapConstraints(genericInfo); return(context.Document.ReplaceNodeAsync(genericInfo.Node, newInfo.Node, ct)); }, RefactoringDescriptors.WrapConstraintClauses); } }
public static void ComputeRefactoring(RefactoringContext context, TypeParameterConstraintClauseSyntax constraintClause) { GenericInfo genericInfo = SyntaxInfo.GenericInfo(constraintClause); if (!genericInfo.Success) { return; } SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = genericInfo.ConstraintClauses; if (constraintClauses.IsSingleLine()) { if (constraintClauses.Count > 1) { context.RegisterRefactoring( "Format constraints on separate lines", cancellationToken => { GenericInfo newInfo = ToMultiLine(genericInfo); return(context.Document.ReplaceNodeAsync(genericInfo.Node, newInfo.Node, cancellationToken)); }, RefactoringIdentifiers.FormatConstraintClauses); } } else if (constraintClause.DescendantTrivia(constraintClause.Span).All(f => f.IsWhitespaceOrEndOfLineTrivia()) && constraintClauses[0].GetFirstToken().GetPreviousToken().TrailingTrivia.IsEmptyOrWhitespace()) { context.RegisterRefactoring( "Format constraints on a single line", cancellationToken => { GenericInfo newInfo = ToSingleLine(genericInfo); return(context.Document.ReplaceNodeAsync(genericInfo.Node, newInfo.Node, cancellationToken)); }, RefactoringIdentifiers.FormatConstraintClauses); } }