Ejemplo n.º 1
0
        private int GetRuleSpacesOrIndentation(
            LineColumn lineColumnBeforeTrivia1, SyntaxTrivia trivia1, LineColumn lineColumnAfterTrivia1, LineColumnDelta existingWhitespaceBetween, SyntaxTrivia trivia2, LineColumnRule rule)
        {
            var lineColumnAfterExistingWhitespace = lineColumnAfterTrivia1.With(existingWhitespaceBetween);

            // next trivia is moved to next line or already on a new line, use indentation
            if (rule.Lines > 0 || lineColumnAfterExistingWhitespace.WhitespaceOnly)
            {
                switch (rule.IndentationOperation)
                {
                case LineColumnRule.IndentationOperations.Absolute:
                    return(Math.Max(0, rule.Indentation));

                case LineColumnRule.IndentationOperations.Default:
                    return(this.Context.GetBaseIndentation(trivia2.RawKind == 0 ? this.EndPosition : trivia2.SpanStart));

                case LineColumnRule.IndentationOperations.Given:
                    return((trivia2.RawKind == 0) ? this.Spaces : Math.Max(0, this.indentation));

                case LineColumnRule.IndentationOperations.Follow:
                    return(Math.Max(0, lineColumnBeforeTrivia1.Column));

                case LineColumnRule.IndentationOperations.Preserve:
                    return(existingWhitespaceBetween.Spaces);

                default:
                    throw Contract.Unreachable;
                }
            }

            // okay, we are not on a its own line, use space information
            switch (rule.SpaceOperation)
            {
            case LineColumnRule.SpaceOperations.Preserve:
                return(Math.Max(rule.Spaces, existingWhitespaceBetween.Spaces));

            case LineColumnRule.SpaceOperations.Force:
                return(Math.Max(rule.Spaces, 0));

            default:
                throw Contract.Unreachable;
            }
        }
Ejemplo n.º 2
0
        private int GetRuleLines(LineColumnRule rule, LineColumn lineColumnAfterTrivia1, LineColumnDelta existingWhitespaceBetween)
        {
            var adjustedRuleLines = Math.Max(0, rule.Lines - GetTrailingLinesAtEndOfTrivia1(lineColumnAfterTrivia1));

            return((rule.LineOperation == LineColumnRule.LineOperations.Preserve) ? Math.Max(adjustedRuleLines, existingWhitespaceBetween.Lines) : adjustedRuleLines);
        }
Ejemplo n.º 3
0
        private LineColumnDelta Apply(
            LineColumn lineColumnBeforeTrivia1, SyntaxTrivia trivia1, LineColumn lineColumnAfterTrivia1, LineColumnDelta existingWhitespaceBetween, SyntaxTrivia trivia2, LineColumnRule rule)
        {
            // we do not touch spaces adjacent to missing token
            // [missing token] [whitespace] [trivia] or [trivia] [whitepsace] [missing token] case
            if ((this.Token1.IsMissing && trivia1.RawKind == 0) ||
                (trivia2.RawKind == 0 && this.Token2.IsMissing))
            {
                // leave things as it is
                return(existingWhitespaceBetween);
            }

            var lines = GetRuleLines(rule, lineColumnAfterTrivia1, existingWhitespaceBetween);
            var spaceOrIndentations = GetRuleSpacesOrIndentation(lineColumnBeforeTrivia1, trivia1, lineColumnAfterTrivia1, existingWhitespaceBetween, trivia2, rule);

            return(new LineColumnDelta(
                       lines,
                       spaceOrIndentations,
                       whitespaceOnly: true,
                       forceUpdate: existingWhitespaceBetween.ForceUpdate));
        }