Exemplo n.º 1
0
        public static void ComputeRefactoring(RefactoringContext context, TypeParameterConstraintClauseSyntax constraintClause)
        {
            SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = constraintClause.GetContainingList();

            if (constraintClauses.IsSingleLine())
            {
                if (constraintClauses.Count > 1)
                {
                    context.RegisterRefactoring(
                        "Format constraints on separate lines",
                        cancellationToken =>
                    {
                        SyntaxNode parent = constraintClause.Parent;

                        SyntaxNode newNode = ToMultiLine(parent, constraintClauses);

                        return(context.Document.ReplaceNodeAsync(parent, newNode, cancellationToken));
                    });
                }
            }
            else
            {
                context.RegisterRefactoring(
                    "Format constraints on a single line",
                    cancellationToken =>
                {
                    SyntaxNode parent = constraintClause.Parent;

                    SyntaxNode newNode = ToSingleLine(parent, constraintClauses);

                    return(context.Document.ReplaceNodeAsync(parent, newNode, cancellationToken));
                });
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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));
                    });
                }
            }
            else
            {
                context.RegisterRefactoring(
                    "Format constraints on a single line",
                    cancellationToken =>
                {
                    GenericInfo newInfo = ToSingleLine(genericInfo);

                    return(context.Document.ReplaceNodeAsync(genericInfo.Node, newInfo.Node, cancellationToken));
                });
            }
        }