/// <summary> /// Moves the index past any whitespace characters. /// </summary> /// <param name="tokens"> /// The collection containing the start token. /// </param> /// <param name="start"> /// The first token to move past. /// </param> /// <param name="movePastTypes"> /// The types of tokens to move past. /// </param> /// <returns> /// Returns false if the end of the token list was reached. /// </returns> private static bool MovePastTokens(CsTokenList tokens, ref Node<CsToken> start, params CsTokenType[] movePastTypes) { Param.AssertNotNull(tokens, "tokens"); Param.AssertNotNull(start, "start"); Param.Ignore(movePastTypes); for (Node<CsToken> tokenNode = start; !tokens.OutOfBounds(tokenNode); tokenNode = tokenNode.Next) { bool found = false; for (int i = 0; i < movePastTypes.Length; ++i) { if (tokenNode.Value.CsTokenType == movePastTypes[i]) { found = true; break; } } if (!found) { start = tokenNode; return true; } } return false; }
/// <summary> /// Finds the end of the given name, moving past member access operators. /// </summary> /// <param name="document"> /// The document containing the name. /// </param> /// <param name="tokens"> /// The token list. /// </param> /// <param name="startTokenNode"> /// The first token of the name within the token list. /// </param> /// <returns> /// Returns the last token of the name within the token list. /// </returns> internal static Node<CsToken> FindEndOfName(CsDocument document, CsTokenList tokens, Node<CsToken> startTokenNode) { Param.AssertNotNull(document, "document"); Param.AssertNotNull(tokens, "tokens"); Param.AssertNotNull(startTokenNode, "startTokenNode"); Node<CsToken> endTokenNode = startTokenNode; Node<CsToken> tokenNode = startTokenNode; if (tokenNode == null) { CsTokenType tokenType = tokenNode.Value.CsTokenType; if (tokenType != CsTokenType.Other && tokenType != CsTokenType.Get && tokenType != CsTokenType.Set && tokenType != CsTokenType.Add && tokenType != CsTokenType.Remove) { throw new SyntaxException(document.SourceCode, tokenNode == null ? document.MasterTokenList.Last.Value.LineNumber : tokenNode.Value.LineNumber); } } bool accessSymbol = false; for (Node<CsToken> temp = tokens.First; !tokens.OutOfBounds(temp); temp = temp.Next) { CsTokenType tempTokenType = temp.Value.CsTokenType; if (tempTokenType != CsTokenType.WhiteSpace && tempTokenType != CsTokenType.EndOfLine && tempTokenType != CsTokenType.SingleLineComment && tempTokenType != CsTokenType.MultiLineComment && tempTokenType != CsTokenType.PreprocessorDirective) { if (accessSymbol) { if (tempTokenType != CsTokenType.Other) { throw new SyntaxException(document.SourceCode, temp.Value.LineNumber); } endTokenNode = tokenNode; accessSymbol = false; } else { if (temp.Value.Text == "." || temp.Value.Text == "::") { accessSymbol = true; } else { break; } } } } return endTokenNode; }
/// <summary> /// Finds the end of a name, moving past member access operators. /// </summary> /// <param name="document"> /// The document containing the tokens. /// </param> /// <param name="tokens"> /// The token list. /// </param> /// <param name="startTokenNode"> /// The first token of the name. /// </param> /// <param name="endTokenNode"> /// Returns the last token of the name. /// </param> /// <returns> /// Returns the full name. /// </returns> internal static string GetFullName(CsDocument document, CsTokenList tokens, Node<CsToken> startTokenNode, out Node<CsToken> endTokenNode) { Param.AssertNotNull(document, "document"); Param.AssertNotNull(tokens, "tokens"); Param.AssertNotNull(startTokenNode, "startToken"); endTokenNode = CodeParser.FindEndOfName(document, tokens, startTokenNode); Debug.Assert(endTokenNode != null, "Did not find the end of the name"); // Create the text string. StringBuilder text = new StringBuilder(); for (Node<CsToken> tokenNode = startTokenNode; !tokens.OutOfBounds(tokenNode); tokenNode = tokenNode.Next) { CsTokenType tokenType = tokenNode.Value.CsTokenType; if (tokenType != CsTokenType.WhiteSpace && tokenType != CsTokenType.EndOfLine && tokenType != CsTokenType.SingleLineComment && tokenType != CsTokenType.MultiLineComment && tokenType != CsTokenType.PreprocessorDirective) { text.Append(tokenNode.Value.Text); } if (tokenNode == endTokenNode) { break; } } return text.ToString(); }
private static Microsoft.StyleCop.Node<CsToken> GetOpenBracket(CsTokenList tokens) { for (Microsoft.StyleCop.Node<CsToken> node = tokens.First; !tokens.OutOfBounds(node); node = node.Next) { if (node.Value.CsTokenType == CsTokenType.OpenCurlyBracket) { return node; } } return null; }
private static bool MovePastTokens(CsTokenList tokens, ref Microsoft.StyleCop.Node<CsToken> start, params CsTokenType[] movePastTypes) { for (Microsoft.StyleCop.Node<CsToken> node = start; !tokens.OutOfBounds(node); node = node.Next) { bool flag = false; for (int i = 0; i < movePastTypes.Length; i++) { if (node.Value.CsTokenType == movePastTypes[i]) { flag = true; break; } } if (!flag) { start = node; return true; } } return false; }
internal static string GetFullName(CsDocument document, CsTokenList tokens, Microsoft.StyleCop.Node<CsToken> startTokenNode, out Microsoft.StyleCop.Node<CsToken> endTokenNode) { endTokenNode = FindEndOfName(document, tokens, startTokenNode); StringBuilder builder = new StringBuilder(); for (Microsoft.StyleCop.Node<CsToken> node = startTokenNode; !tokens.OutOfBounds(node); node = node.Next) { CsTokenType csTokenType = node.Value.CsTokenType; if ((((csTokenType != CsTokenType.WhiteSpace) && (csTokenType != CsTokenType.EndOfLine)) && ((csTokenType != CsTokenType.SingleLineComment) && (csTokenType != CsTokenType.MultiLineComment))) && (csTokenType != CsTokenType.PreprocessorDirective)) { builder.Append(node.Value.Text); } if (node == endTokenNode) { break; } } return builder.ToString(); }
internal static Microsoft.StyleCop.Node<CsToken> FindEndOfName(CsDocument document, CsTokenList tokens, Microsoft.StyleCop.Node<CsToken> startTokenNode) { Microsoft.StyleCop.Node<CsToken> node = startTokenNode; Microsoft.StyleCop.Node<CsToken> node2 = startTokenNode; if (node2 == null) { CsTokenType csTokenType = node2.Value.CsTokenType; if ((((csTokenType != CsTokenType.Other) && (csTokenType != CsTokenType.Get)) && ((csTokenType != CsTokenType.Set) && (csTokenType != CsTokenType.Add))) && (csTokenType != CsTokenType.Remove)) { throw new SyntaxException(document.SourceCode, (node2 == null) ? document.MasterTokenList.Last.Value.LineNumber : node2.Value.LineNumber); } } bool flag = false; for (Microsoft.StyleCop.Node<CsToken> node3 = tokens.First; !tokens.OutOfBounds(node3); node3 = node3.Next) { CsTokenType type2 = node3.Value.CsTokenType; switch (type2) { case CsTokenType.WhiteSpace: case CsTokenType.EndOfLine: case CsTokenType.SingleLineComment: case CsTokenType.MultiLineComment: case CsTokenType.PreprocessorDirective: break; default: if (flag) { if (type2 != CsTokenType.Other) { throw new SyntaxException(document.SourceCode, node3.Value.LineNumber); } node = node2; flag = false; } else { if (!(node3.Value.Text == ".") && !(node3.Value.Text == "::")) { return node; } flag = true; } break; } } return node; }
/// <summary> /// Gets the first open curly bracket in the token list. /// </summary> /// <param name="tokens">The list of tokens.</param> /// <returns>Returns the first open curly bracket or -1 if there are none.</returns> private static Node<CsToken> GetOpenBracket(CsTokenList tokens) { Param.AssertNotNull(tokens, "tokens"); for (Node<CsToken> tokenNode = tokens.First; !tokens.OutOfBounds(tokenNode); tokenNode = tokenNode.Next) { if (tokenNode.Value.CsTokenType == CsTokenType.OpenCurlyBracket) { return tokenNode; } } return null; }