protected void ProcessAndNormalizeTokenRange(int startindex, int endIndex, NormalizeWhitespace normalizer, bool areAllTokensWhitespace) { for (int i = startindex; i < endIndex; i++) { ProcessTokenAndNormalize(i, normalizer, areAllTokensWhitespace); } }
private int ProcessQueryExpression(int nextToken) { NormalizeWhitespace normalizer = GetColumnWhitespaceNormalizer(); nextToken = ProcessSectionInsideParentheses(nextToken, normalizer: FormatterUtilities.NormalizeNewLinesEnsureOneNewLineMinimum, isNewlineRequired: true, processSection: (n) => ProcessQuerySection(n, CodeObject.QueryExpression)); return(nextToken); }
protected void ProcessTokenAndNormalize(int tokenIndex, NormalizeWhitespace normalizeFunction, bool areAllTokensWhitespace = true) { TokenData iTokenData = GetTokenData(tokenIndex); if (areAllTokensWhitespace) { DebugAssertTokenIsWhitespaceOrComment(iTokenData, tokenIndex); } normalizeFunction = normalizeFunction ?? FormatterUtilities.NormalizeNewLinesEnsureOneNewLineMinimum; SimpleProcessToken(tokenIndex, normalizeFunction); }
private int ProcessColumns(int nextToken) { if (CodeObject.ColumnList != null && CodeObject.ColumnList.Count > 0) { NormalizeWhitespace normalizer = GetColumnWhitespaceNormalizer(); nextToken = ProcessSectionInsideParentheses(nextToken, normalizer, isNewlineRequired: FormatOptions.PlaceEachReferenceOnNewLineInQueryStatements, processSection: (n) => ProcessColumnList(n, CodeObject.ColumnList, normalizer)); } return(nextToken); }
private void ProcessWhitespaceInRange(int commaToken, int end) { NormalizeWhitespace f = FormatterUtilities.NormalizeNewLinesOrCondenseToOneSpace; if (PlaceEachElementOnNewLine) { f = FormatterUtilities.NormalizeNewLinesEnsureOneNewLineMinimum; } for (int i = commaToken + 1; i <= end; i++) { SimpleProcessToken(i, f); } }
internal override void ProcessPrefixRegion(int startTokenNumber, int firstChildStartTokenNumber) { IncrementIndentLevel(); NormalizeWhitespace f = FormatterUtilities.NormalizeNewLinesOrCondenseToOneSpace; if (PlaceEachElementOnNewLine) { f = FormatterUtilities.NormalizeNewLinesEnsureOneNewLineMinimum; } for (int i = startTokenNumber; i < firstChildStartTokenNumber; i++) { SimpleProcessToken(i, f); } }
protected void SimpleProcessToken(int currentToken, NormalizeWhitespace normalizeFunction) { TokenData t = GetTokenData(currentToken); if (IsTokenWhitespace(t)) { ProcessWhitepace(currentToken, normalizeFunction, t); } else if (t.TokenId == FormatterTokens.LEX_END_OF_LINE_COMMENT) { ProcessEndOfLine(currentToken, t); } else { ProcessTokenRange(currentToken, currentToken + 1); } }
protected int ProcessSectionInsideParentheses(int nextToken, NormalizeWhitespace normalizer, bool isNewlineRequired, Func <int, int> processSection) { int openParenIndex = FindOpenParenthesis(nextToken); ProcessAndNormalizeWhitespaceRange(nextToken, openParenIndex, normalizer); nextToken = ProcessOpenParenthesis(nextToken, openParenIndex, isNewlineRequired); nextToken = processSection(nextToken); int closedParenIndex = FindClosedParenthesis(nextToken); ProcessRegionBeforeClosedParenthesis(nextToken, closedParenIndex, normalizer, isNewlineRequired); // Process closed parenthesis ProcessTokenRange(closedParenIndex, closedParenIndex + 1); nextToken = closedParenIndex + 1; return(nextToken); }
private void ProcessWhitepace(int currentToken, NormalizeWhitespace normalizeFunction, TokenData token) { string originalWhiteSpace = GetTextForCurrentToken(currentToken); if (HasPreviousToken(currentToken)) { TokenData previousToken = PreviousTokenData(currentToken); if (previousToken.TokenId == FormatterTokens.LEX_END_OF_LINE_COMMENT) { if (originalWhiteSpace.StartsWith("\n", StringComparison.OrdinalIgnoreCase) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // Replace \n with \r\n on Windows platforms originalWhiteSpace = Environment.NewLine + originalWhiteSpace.Substring(1); } } } string newWhiteSpace = normalizeFunction(originalWhiteSpace, Visitor.Context); AddReplacement(new Replacement(token.StartIndex, GetTextForCurrentToken(currentToken), newWhiteSpace)); }
private int ProcessColumns(int nextToken) { if (CodeObject.TargetColumns != null) { if (CodeObject.TargetColumns.Count > 0) { IncrementIndentLevel(); // if the next token is not a whitespace, a newline is enforced. TokenData nextTokenData = GetTokenData(nextToken); if (!IsTokenWhitespace(nextTokenData)) { AddIndentedNewLineReplacement(nextTokenData.StartIndex); } NormalizeWhitespace f = FormatterUtilities.NormalizeNewLinesEnsureOneNewLineMinimum; // process tokens until we reach the closed parenthesis (with id 41) for (int id = TokenManager.TokenList[nextToken].TokenId; id != 41; id = TokenManager.TokenList[++nextToken].TokenId) { SimpleProcessToken(nextToken, f); if (id == 40) // open parenthesis (id == 40) changes the formatting { f = FormatterUtilities.NormalizeNewLinesOrCondenseToOneSpace; } } // process the cosed paren SimpleProcessToken(nextToken, f); nextToken++; DecrementIndentLevel(); } } return(nextToken); }
internal override void ProcessSuffixRegion(int lastChildEndTokenNumber, int endTokenNumber) { DecrementIndentLevel(); NormalizeWhitespace f = FormatterUtilities.NormalizeNewLinesEnsureOneNewLineMinimum; for (int i = lastChildEndTokenNumber; i < endTokenNumber; i++) { if (TokenManager.TokenList[i].TokenId == FormatterTokens.TOKEN_AS && !TokenManager.IsTokenWhitespace(TokenManager.TokenList[i - 1].TokenId)) { TokenData td = TokenManager.TokenList[i]; AddIndentedNewLineReplacement(td.StartIndex); } if (TokenManager.TokenList[i].TokenId == FormatterTokens.TOKEN_FOR) { f = FormatterUtilities.NormalizeNewLinesOrCondenseToOneSpace; } else if (TokenManager.TokenList[i].TokenId == FormatterTokens.TOKEN_REPLICATION) { f = FormatterUtilities.NormalizeNewLinesEnsureOneNewLineMinimum; } SimpleProcessToken(i, f); } }
protected void ProcessAndNormalizeWhitespaceRange(int startindex, int endIndex, NormalizeWhitespace normalizer) { ProcessAndNormalizeTokenRange(startindex, endIndex, normalizer, true); }
protected int ProcessColumnList(int nextToken, SqlIdentifierCollection columnList, NormalizeWhitespace normalizer) { // find where the columns start IEnumerator <SqlIdentifier> columnEnum = columnList.GetEnumerator(); if (columnEnum.MoveNext()) { ProcessAndNormalizeWhitespaceRange(nextToken, columnEnum.Current.Position.startTokenNumber, normalizer); ProcessChild(columnEnum.Current); SqlIdentifier previousColumn = columnEnum.Current; while (columnEnum.MoveNext()) { CommaSeparatedList.ProcessInterChildRegion(previousColumn, columnEnum.Current); ProcessChild(columnEnum.Current); previousColumn = columnEnum.Current; } nextToken = previousColumn.Position.endTokenNumber; } return(nextToken); }
protected void ProcessRegionBeforeClosedParenthesis(int startIndex, int closedParenIndex, NormalizeWhitespace normalizer, bool isNewlineRequired) { for (int i = startIndex; i < closedParenIndex - 1; i++) { ProcessTokenAndNormalize(i, normalizer); } DecrementIndentLevel(); if (startIndex < closedParenIndex) { SimpleProcessToken(closedParenIndex - 1, normalizer); } // Enforce a whitespace before the closing parenthesis TokenData td = PreviousTokenData(closedParenIndex); if (isNewlineRequired && !IsTokenWhitespace(td)) { td = GetTokenData(closedParenIndex); AddIndentedNewLineReplacement(td.StartIndex); } }