Exemple #1
0
        static void RetrieveRegions(ICompilationUnit cu, ICSharpCode.NRefactory.Parser.SpecialTracker tracker)
        {
            Stack <ICSharpCode.NRefactory.PreprocessingDirective> regionStartDirectives = new Stack <ICSharpCode.NRefactory.PreprocessingDirective>();

            foreach (ICSharpCode.NRefactory.PreprocessingDirective directive in tracker.CurrentSpecials.OfType <ICSharpCode.NRefactory.PreprocessingDirective>())
            {
                if (directive.Cmd.Equals("#region", StringComparison.OrdinalIgnoreCase))
                {
                    regionStartDirectives.Push(directive);
                }
                if (directive.Cmd.Equals("#end", StringComparison.OrdinalIgnoreCase)
                    // using StartsWith allows comments at end of line
                    // fixes http://community.sharpdevelop.net/forums/t/12252.aspx
                    && directive.Arg.StartsWith("region", StringComparison.OrdinalIgnoreCase) &&
                    regionStartDirectives.Any())
                {
                    ICSharpCode.NRefactory.PreprocessingDirective start = regionStartDirectives.Pop();
                    cu.FoldingRegions.Add(new FoldingRegion(start.Arg.TrimComments().Trim().Trim('"'), DomRegion.FromLocation(start.StartPosition, directive.EndPosition)));
                }
            }
        }
Exemple #2
0
        void RetrieveRegions(ICompilationUnit cu, ICSharpCode.NRefactory.Parser.SpecialTracker tracker)
        {
            for (int i = 0; i < tracker.CurrentSpecials.Count; ++i)
            {
                ICSharpCode.NRefactory.PreprocessingDirective directive = tracker.CurrentSpecials[i] as ICSharpCode.NRefactory.PreprocessingDirective;
                if (directive != null)
                {
                    if (directive.Cmd.Equals("#region", StringComparison.OrdinalIgnoreCase))
                    {
                        int deep = 1;
                        for (int j = i + 1; j < tracker.CurrentSpecials.Count; ++j)
                        {
                            ICSharpCode.NRefactory.PreprocessingDirective nextDirective = tracker.CurrentSpecials[j] as ICSharpCode.NRefactory.PreprocessingDirective;
                            if (nextDirective != null)
                            {
                                switch (nextDirective.Cmd.ToLowerInvariant())
                                {
                                case "#region":
                                    ++deep;
                                    break;

                                case "#end":
                                    if (nextDirective.Arg.Equals("region", StringComparison.OrdinalIgnoreCase))
                                    {
                                        --deep;
                                        if (deep == 0)
                                        {
                                            cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim('"'), DomRegion.FromLocation(directive.StartPosition, nextDirective.EndPosition)));
                                            goto end;
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        end :;
                    }
                }
            }
        }
Exemple #3
0
        void RetrieveRegions(ICompilationUnit cu, ICSharpCode.NRefactory.Parser.SpecialTracker tracker)
        {
            for (int i = 0; i < tracker.CurrentSpecials.Count; ++i)
            {
                ICSharpCode.NRefactory.PreprocessingDirective directive = tracker.CurrentSpecials[i] as ICSharpCode.NRefactory.PreprocessingDirective;
                if (directive != null)
                {
                    if (directive.Cmd == "#region")
                    {
                        int deep = 1;
                        for (int j = i + 1; j < tracker.CurrentSpecials.Count; ++j)
                        {
                            ICSharpCode.NRefactory.PreprocessingDirective nextDirective = tracker.CurrentSpecials[j] as ICSharpCode.NRefactory.PreprocessingDirective;
                            if (nextDirective != null)
                            {
                                switch (nextDirective.Cmd)
                                {
                                case "#region":
                                    ++deep;
                                    break;

                                case "#endregion":
                                    --deep;
                                    if (deep == 0)
                                    {
                                        cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim(), DomRegion.FromLocation(directive.StartPosition, nextDirective.EndPosition)));
                                        goto end;
                                    }
                                    break;
                                }
                            }
                        }
                        end :;
                    }
                }
            }
        }