This project is read-only.

Statement.Tokens.First == Last when StatementType.Return

May 31, 2010 at 10:24 AM
Edited May 31, 2010 at 12:44 PM


I'm building a custom rule and I iterate the document using:


 csharpDocument.WalkDocument(null, new CodeWalkerStatementVisitor<object>(this.VisitStatement), null);


In VisitStatement I need to check if a specific method call exists. This works great until the StatementType is Return. Then the statement.Tokens.First and statement.Tokens.Last point to the same token ({return}). But the correct tokens exist if I check statement.Tokens.Next.

Is this expected behavior?

Any clues?


I've tried to find out what is happening, and I suspect that this is the reason but I can't confirm it (It would take too much time setting up StyleCop for debug):

private ReturnStatement ParseReturnStatement(Reference<ICodePart> parentReference, bool unsafeCode)
            Param.AssertNotNull(parentReference, "parentReference");

            var statementReference = new Reference<ICodePart>();

            // Move past the return keyword.
            CsToken firstToken = this.GetToken(CsTokenType.Return, SymbolType.Return, parentReference, statementReference);
            Node<CsToken> firstTokenNode = this.tokens.InsertLast(firstToken);
insert first token to last?