コード例 #1
0
            private bool ApplyDynamicSpacesOperation(AdjustSpacesOperation operation, int pairIndex)
            {
                var triviaInfo = _tokenStream.GetTriviaData(pairIndex);

                if (triviaInfo.SecondTokenIsFirstTokenOnLine)
                {
                    return(false);
                }

                Contract.ThrowIfFalse(triviaInfo.LineBreaks == 0);

                var indentation = _context.GetBaseIndentation(_tokenStream.GetToken(pairIndex + 1));

                var previousToken = _tokenStream.GetToken(pairIndex);

                bool multipleLines;
                int  tokenLength;

                _tokenStream.GetTokenLength(previousToken, out tokenLength, out multipleLines);

                // get end column of previous token
                var endColumnOfPreviousToken = multipleLines ? tokenLength : _tokenStream.GetCurrentColumn(previousToken) + tokenLength;

                // check whether current position is less than indentation
                if (endColumnOfPreviousToken < indentation)
                {
                    _tokenStream.ApplyChange(pairIndex, triviaInfo.WithSpace(indentation - endColumnOfPreviousToken, _context, _formattingRules));
                    return(true);
                }

                // delegate to normal single-line space applier
                return(ApplySpaceIfSingleLine(operation, pairIndex));
            }