private DirectiveTriviaSyntax GetPreviousPossiblyRelatedDirective()
        {
            DirectiveTriviaSyntax d = this;

            while (d != null)
            {
                d = d.GetPreviousDirective();
                if (d != null)
                {
                    // skip matched sets
                    switch (d.Kind())
                    {
                    case SyntaxKind.EndIfDirectiveTrivia:
                        while (d != null && d.Kind() != SyntaxKind.IfDirectiveTrivia)
                        {
                            d = d.GetPreviousRelatedDirective();
                        }

                        continue;

                    case SyntaxKind.EndRegionDirectiveTrivia:
                        while (d != null && d.Kind() != SyntaxKind.RegionDirectiveTrivia)
                        {
                            d = d.GetPreviousRelatedDirective();
                        }

                        continue;
                    }
                }

                return(d);
            }

            return(null);
        }
Beispiel #2
0
        private static bool IsActiveConditionalDirective(DirectiveTriviaSyntax directive)
        {
            switch (directive.Kind())
            {
            case SyntaxKind.DefineDirectiveTrivia:
                return(((DefineDirectiveTriviaSyntax)directive).IsActive);

            case SyntaxKind.UndefDirectiveTrivia:
                return(((UndefDirectiveTriviaSyntax)directive).IsActive);

            default:
                return(false);
            }
        }
Beispiel #3
0
            private static bool HasRelatedDirectives(DirectiveTriviaSyntax directive)
            {
                switch (directive.Kind())
                {
                case SyntaxKind.IfDirectiveTrivia:
                case SyntaxKind.ElseDirectiveTrivia:
                case SyntaxKind.ElifDirectiveTrivia:
                case SyntaxKind.EndIfDirectiveTrivia:
                case SyntaxKind.RegionDirectiveTrivia:
                case SyntaxKind.EndRegionDirectiveTrivia:
                    return(true);

                default:
                    return(false);
                }
            }
        private DirectiveTriviaSyntax GetPreviousRelatedDirective()
        {
            DirectiveTriviaSyntax d = this;

            switch (d.Kind())
            {
            case SyntaxKind.EndIfDirectiveTrivia:
                while (d != null)
                {
                    switch (d.Kind())
                    {
                    case SyntaxKind.IfDirectiveTrivia:
                    case SyntaxKind.ElifDirectiveTrivia:
                    case SyntaxKind.ElseDirectiveTrivia:
                        return(d);
                    }

                    d = d.GetPreviousPossiblyRelatedDirective();
                }

                break;

            case SyntaxKind.ElifDirectiveTrivia:
                d = d.GetPreviousPossiblyRelatedDirective();

                while (d != null)
                {
                    switch (d.Kind())
                    {
                    case SyntaxKind.IfDirectiveTrivia:
                    case SyntaxKind.ElifDirectiveTrivia:
                        return(d);
                    }

                    d = d.GetPreviousPossiblyRelatedDirective();
                }

                break;

            case SyntaxKind.ElseDirectiveTrivia:
                while (d != null)
                {
                    switch (d.Kind())
                    {
                    case SyntaxKind.IfDirectiveTrivia:
                    case SyntaxKind.ElifDirectiveTrivia:
                        return(d);
                    }

                    d = d.GetPreviousPossiblyRelatedDirective();
                }

                break;

            case SyntaxKind.EndRegionDirectiveTrivia:
                while (d != null)
                {
                    if (d.Kind() == SyntaxKind.RegionDirectiveTrivia)
                    {
                        return(d);
                    }

                    d = d.GetPreviousPossiblyRelatedDirective();
                }

                break;
            }

            return(null);
        }