コード例 #1
0
 bool IsInside(NR.Location between, NR.Location start, NR.Location end)
 {
     if (between.Y < start.Y || between.Y > end.Y)
     {
         return(false);
     }
     if (between.Y > start.Y)
     {
         if (between.Y < end.Y)
         {
             return(true);
         }
         // between.Y == end.Y
         return(between.X <= end.X);
     }
     // between.Y == start.Y
     if (between.X < start.X)
     {
         return(false);
     }
     // start is OK and between.Y <= end.Y
     return(between.Y < end.Y || between.X <= end.X);
 }
コード例 #2
0
        public override DomRegion GetFullCodeRangeForType(string fileContent, IClass type)
        {
            NR.Parser.ILexer lexer = NR.ParserFactory.CreateLexer(language, new StringReader(fileContent));
            // use the lexer to determine last token position before type start
            // and next token position after type end
            Stack <NR.Location> stack = new Stack <NR.Location>();

            NR.Location     lastPos     = NR.Location.Empty;
            NR.Parser.Token t           = lexer.NextToken();
            bool            csharp      = language == NR.SupportedLanguage.CSharp;
            int             eof         = csharp ? NR.Parser.CSharp.Tokens.EOF : NR.Parser.VB.Tokens.EOF;
            int             attribStart = csharp ? NR.Parser.CSharp.Tokens.OpenSquareBracket : NR.Parser.VB.Tokens.LessThan;
            int             attribEnd   = csharp ? NR.Parser.CSharp.Tokens.CloseSquareBracket : NR.Parser.VB.Tokens.GreaterThan;

            while (t.kind != eof)
            {
                if (t.kind == attribStart)
                {
                    stack.Push(lastPos);
                }
                if (t.EndLocation.Y >= type.Region.BeginLine)
                {
                    break;
                }
                lastPos = t.EndLocation;
                if (t.kind == attribEnd && stack.Count > 0)
                {
                    lastPos = stack.Pop();
                }
                t = lexer.NextToken();
            }

            stack = null;

            // Skip until end of type
            while (t.kind != eof)
            {
                if (t.EndLocation.Y > type.BodyRegion.EndLine)
                {
                    break;
                }
                t = lexer.NextToken();
            }

            int lastLineBefore = lastPos.IsEmpty ? 0 : lastPos.Y;
            int firstLineAfter = t.EndLocation.IsEmpty ? int.MaxValue : t.EndLocation.Y;

            lexer.Dispose(); lexer = null;

            StringReader myReader = new StringReader(fileContent);

            string line;
            string mainLine;
            int    resultBeginLine       = lastLineBefore + 1;
            int    resultEndLine         = firstLineAfter - 1;
            int    lineNumber            = 0;
            int    largestEmptyLineCount = 0;
            int    emptyLinesInRow       = 0;

            while ((line = myReader.ReadLine()) != null)
            {
                lineNumber++;
                if (lineNumber <= lastLineBefore)
                {
                    continue;
                }
                if (lineNumber < type.Region.BeginLine)
                {
                    string trimLine = line.TrimStart();
                    if (trimLine.Length == 0)
                    {
                        if (++emptyLinesInRow > largestEmptyLineCount)
                        {
                            resultBeginLine = lineNumber;
                        }
                    }
                }
                else if (lineNumber == type.Region.BeginLine)
                {
                    mainLine = line;
                }
                else if (lineNumber == type.BodyRegion.EndLine)
                {
                    largestEmptyLineCount = 0;
                    emptyLinesInRow       = 0;
                    resultEndLine         = lineNumber;
                }
                else if (lineNumber > type.BodyRegion.EndLine)
                {
                    if (lineNumber >= firstLineAfter)
                    {
                        break;
                    }
                    string trimLine = line.TrimStart();
                    if (trimLine.Length == 0)
                    {
                        if (++emptyLinesInRow > largestEmptyLineCount)
                        {
                            emptyLinesInRow = largestEmptyLineCount;
                            resultEndLine   = lineNumber - emptyLinesInRow;
                        }
                    }
                }
            }

            myReader.Dispose();
            return(new DomRegion(resultBeginLine, 0, resultEndLine, int.MaxValue));
        }
コード例 #3
0
 private static DomRegion GetRegion(RefParser.Location start, RefParser.Location end)
 {
     return(new DomRegion(start, end));
 }