예제 #1
0
        public void ComputeRefactoringsForNodeInsideTrivia()
        {
            SyntaxNode node = Root.FindNode(Span, findInsideTrivia: true, getInnermostNodeForTie: true);

            for (; node != null; node = node.Parent)
            {
                if (node is DirectiveTriviaSyntax directiveTrivia)
                {
                    DirectiveTriviaRefactoring.ComputeRefactorings(this, directiveTrivia);

                    SyntaxKind kind = node.Kind();

                    if (kind == SyntaxKind.RegionDirectiveTrivia ||
                        kind == SyntaxKind.EndRegionDirectiveTrivia)
                    {
                        RegionDirectiveTriviaRefactoring.ComputeRefactorings(this);
                    }

                    RemoveAllPreprocessorDirectivesRefactoring.ComputeRefactorings(this);

                    if (kind == SyntaxKind.RegionDirectiveTrivia)
                    {
                        RegionDirectiveTriviaRefactoring.ComputeRefactorings(this, (RegionDirectiveTriviaSyntax)node);
                    }
                    else if (kind == SyntaxKind.EndRegionDirectiveTrivia)
                    {
                        RegionDirectiveTriviaRefactoring.ComputeRefactorings(this, (EndRegionDirectiveTriviaSyntax)node);
                    }

                    break;
                }
            }
        }
예제 #2
0
        public void ComputeRefactoringsForNodeInsideTrivia()
        {
            SyntaxNode node = Root.FindNode(Span, findInsideTrivia: true, getInnermostNodeForTie: true);

            if (node == null)
            {
                return;
            }

            bool fDirectiveTrivia = false;

            using (IEnumerator <SyntaxNode> en = node.AncestorsAndSelf().GetEnumerator())
            {
                while (en.MoveNext())
                {
                    node = en.Current;

                    Debug.WriteLine(node.Kind().ToString());

                    if (!fDirectiveTrivia)
                    {
                        var directiveTrivia = node as DirectiveTriviaSyntax;
                        if (directiveTrivia != null)
                        {
                            DirectiveTriviaRefactoring.ComputeRefactorings(this, directiveTrivia);

                            SyntaxKind kind = node.Kind();

                            if (kind == SyntaxKind.RegionDirectiveTrivia ||
                                kind == SyntaxKind.EndRegionDirectiveTrivia)
                            {
                                RegionDirectiveTriviaRefactoring.ComputeRefactorings(this);
                            }

                            RemoveAllPreprocessorDirectivesRefactoring.ComputeRefactorings(this);

                            if (kind == SyntaxKind.RegionDirectiveTrivia)
                            {
                                RegionDirectiveTriviaRefactoring.ComputeRefactorings(this, (RegionDirectiveTriviaSyntax)node);
                            }
                            else if (kind == SyntaxKind.EndRegionDirectiveTrivia)
                            {
                                RegionDirectiveTriviaRefactoring.ComputeRefactorings(this, (EndRegionDirectiveTriviaSyntax)node);
                            }

                            fDirectiveTrivia = true;
                        }
                    }
                }
            }
        }
예제 #3
0
        public static void ComputeRefactoringsForNodeInsideTrivia(this RefactoringContext context)
        {
            SyntaxNode node = context.FindNode(findInsideTrivia: true);

            if (node == null)
            {
                return;
            }

            bool fDirectiveTrivia = false;

            using (IEnumerator <SyntaxNode> en = node.AncestorsAndSelf().GetEnumerator())
            {
                while (en.MoveNext())
                {
                    node = en.Current;

                    Debug.WriteLine(node.Kind().ToString());

                    if (!fDirectiveTrivia)
                    {
                        var directiveTrivia = node as DirectiveTriviaSyntax;
                        if (directiveTrivia != null)
                        {
                            DirectiveTriviaRefactoring.ComputeRefactorings(context, directiveTrivia);

                            if (node.IsKind(SyntaxKind.RegionDirectiveTrivia, SyntaxKind.EndRegionDirectiveTrivia))
                            {
                                RegionDirectiveTriviaRefactoring.ComputeRefactorings(context);
                            }

                            RemoveAllPreprocessorDirectivesRefactoring.ComputeRefactorings(context);

                            if (node.IsKind(SyntaxKind.RegionDirectiveTrivia, SyntaxKind.EndRegionDirectiveTrivia))
                            {
                                RegionDirectiveTriviaRefactoring.ComputeRefactorings(context, (RegionDirectiveTriviaSyntax)node);
                            }

                            fDirectiveTrivia = true;
                        }
                    }
                }
            }
        }