/// <summary> /// Checks the positioning of method parameters which are split across multiple lines. /// </summary> /// <param name="element">The element.</param> /// <param name="parameterList">The argument list.</param> /// <param name="arguments">The method arguments.</param> /// <param name="openingBracket">The opening bracket token.</param> private void CheckSplitMethodArgumentList(Element element, CodeUnit parameterList, IArgumentList arguments, OpenBracketToken openingBracket) { Param.AssertNotNull(element, "element"); Param.AssertNotNull(parameterList, "parameterList"); Param.AssertNotNull(arguments, "arguments"); Param.AssertNotNull(openingBracket, "openingBracket"); Token previousComma = null; bool commaOnSameLineAsPreviousParameterViolation = false; for (int i = 0; i < arguments.Count; ++i) { CodeLocation location = arguments.Location(i); int argumentStartLine = location.LineNumber; CodeUnit argument = arguments.Argument(i); // Some types of parameters or arguments are not allowed to span across multiple lines. if (location.LineSpan > 1 && !arguments.MaySpanMultipleLines(i)) { this.AddViolation(element, argumentStartLine, Rules.ParameterMustNotSpanMultipleLines); } if (i == 0) { // The first argument must start on the line after the opening bracket if (argumentStartLine != openingBracket.LineNumber + 1) { int commentLineSpan = MeasureCommentLinesAfter(openingBracket); if (argumentStartLine != openingBracket.LineNumber + commentLineSpan + 1) { this.AddViolation(element, argumentStartLine, Rules.SplitParametersMustStartOnLineAfterDeclaration, element.FriendlyTypeText); } } } else { // The argument must begin on the line after the previous comma. Debug.Assert(previousComma != null, "The previous comma should have been set."); if (!commaOnSameLineAsPreviousParameterViolation) { if (argumentStartLine != previousComma.LineNumber + 1) { int commentLineSpan = MeasureCommentLinesAfter(previousComma); if (argumentStartLine != previousComma.LineNumber + commentLineSpan + 1) { this.AddViolation(element, argumentStartLine, Rules.ParameterMustFollowComma); } } } } commaOnSameLineAsPreviousParameterViolation = false; // Find the comma after the token list. if (i < arguments.Count - 1) { Token lastTokenInArgument = argument.FindLastDescendentToken(); if (lastTokenInArgument != null) { for (Token token = lastTokenInArgument.FindNextDescendentTokenOf(parameterList); token != null; token = token.FindNextDescendentTokenOf(parameterList)) { if (token.TokenType == TokenType.Comma) { previousComma = token; // The comma must be on the same line as the previous argument. if (previousComma.LineNumber != location.EndPoint.LineNumber) { int commentLineSpan = MeasureCommentLinesBetween(argument.FindLastChildToken(), previousComma, false); if (previousComma.LineNumber != location.EndPoint.LineNumber + commentLineSpan) { this.AddViolation(element, token.LineNumber, Rules.CommaMustBeOnSameLineAsPreviousParameter); commaOnSameLineAsPreviousParameterViolation = true; } } break; } } } } } }
/// <summary> /// Checks the positioning of method parameters which are split across multiple lines. /// </summary> /// <param name="element"> /// The element. /// </param> /// <param name="arguments"> /// The method arguments. /// </param> /// <param name="openingBracketNode"> /// The opening bracket token. /// </param> /// <param name="friendlyTypeText"> /// The friendly type text to use in reporting violations. /// </param> private void CheckSplitMethodArgumentList(CsElement element, IArgumentList arguments, Node <CsToken> openingBracketNode, string friendlyTypeText) { Param.AssertNotNull(element, "element"); Param.AssertNotNull(arguments, "arguments"); Param.AssertNotNull(openingBracketNode, "openingBracketNode"); Node <CsToken> previousComma = null; bool commaOnSameLineAsPreviousParameterViolation = false; for (int i = 0; i < arguments.Count; ++i) { CodeLocation location = arguments.Location(i); int argumentStartLine = location.LineNumber; CsTokenList tokens = arguments.Tokens(i); // Some types of parameters or arguments are not allowed to span across multiple lines. if (location.LineSpan > 1 && !arguments.MaySpanMultipleLines(i)) { this.AddViolation(element, argumentStartLine, Rules.ParameterMustNotSpanMultipleLines); } if (i == 0) { // The first argument must start on the line after the opening bracket if (argumentStartLine != openingBracketNode.Value.LineNumber + 1) { int commentLineSpan = MeasureCommentLinesAfter(openingBracketNode); if (argumentStartLine != openingBracketNode.Value.LineNumber + commentLineSpan + 1) { this.AddViolation(element, argumentStartLine, Rules.SplitParametersMustStartOnLineAfterDeclaration, friendlyTypeText); } } } else { // The parameter must begin on the line after the previous comma. Debug.Assert(previousComma != null, "The previous comma should have been set."); if (!commaOnSameLineAsPreviousParameterViolation) { if (argumentStartLine != previousComma.Value.LineNumber + 1) { int commentLineSpan = MeasureCommentLinesAfter(previousComma); if (argumentStartLine != previousComma.Value.LineNumber + commentLineSpan + 1) { this.AddViolation(element, argumentStartLine, Rules.ParameterMustFollowComma); } } } } commaOnSameLineAsPreviousParameterViolation = false; // Find the comma after the token list. if (i < arguments.Count - 1) { for (Node <CsToken> tokenNode = tokens.Last.Next; tokenNode != null; tokenNode = tokenNode.Next) { if (tokenNode.Value.CsTokenType == CsTokenType.Comma) { previousComma = tokenNode; // The comma must be on the same line as the previous parameter. if (previousComma.Value.LineNumber != location.EndPoint.LineNumber) { int commentLineSpan = MeasureCommentLinesBetween(tokens.Last, previousComma, false); if (previousComma.Value.LineNumber != location.EndPoint.LineNumber + commentLineSpan) { this.AddViolation(element, tokenNode.Value.LineNumber, Rules.CommaMustBeOnSameLineAsPreviousParameter); commaOnSameLineAsPreviousParameterViolation = true; } } break; } } } } }
/// <summary> /// Checks the positioning of method parameters which are split across multiple lines. /// </summary> /// <param name="element">The element.</param> /// <param name="parameterList">The argument list.</param> /// <param name="arguments">The method arguments.</param> /// <param name="openingBracket">The opening bracket token.</param> private void CheckSplitMethodArgumentList(Element element, CodeUnit parameterList, IArgumentList arguments, OpenBracketToken openingBracket) { Param.AssertNotNull(element, "element"); Param.AssertNotNull(parameterList, "parameterList"); Param.AssertNotNull(arguments, "arguments"); Param.AssertNotNull(openingBracket, "openingBracket"); Token previousComma = null; bool commaOnSameLineAsPreviousParameterViolation = false; for (int i = 0; i < arguments.Count; ++i) { CodeLocation location = arguments.Location(i); int argumentStartLine = location.LineNumber; CodeUnit argument = arguments.Argument(i); // Some types of parameters or arguments are not allowed to span across multiple lines. if (location.LineSpan > 1 && !arguments.MaySpanMultipleLines(i)) { this.AddViolation(element, argumentStartLine, Rules.ParameterMustNotSpanMultipleLines); } if (i == 0) { // The first argument must start on the line after the opening bracket if (argumentStartLine != openingBracket.LineNumber + 1) { int commentLineSpan = MeasureCommentLinesAfter(openingBracket); if (argumentStartLine != openingBracket.LineNumber + commentLineSpan + 1) { this.AddViolation(element, argumentStartLine, Rules.SplitParametersMustStartOnLineAfterDeclaration, element.FriendlyTypeText); } } } else { // The argument must begin on the line after the previous comma. Debug.Assert(previousComma != null, "The previous comma should have been set."); if (!commaOnSameLineAsPreviousParameterViolation) { if (argumentStartLine != previousComma.LineNumber + 1) { int commentLineSpan = MeasureCommentLinesAfter(previousComma); if (argumentStartLine != previousComma.LineNumber + commentLineSpan + 1) { this.AddViolation(element, argumentStartLine, Rules.ParameterMustFollowComma); } } } } commaOnSameLineAsPreviousParameterViolation = false; // Find the comma after the token list. if (i < arguments.Count - 1) { Token lastTokenInArgument = argument.FindLastDescendentToken(); if (lastTokenInArgument != null) { for (Token token = lastTokenInArgument.FindNextDescendentTokenOf(parameterList); token != null; token = token.FindNextDescendentTokenOf(parameterList)) { if (token.TokenType == TokenType.Comma) { previousComma = token; // The comma must be on the same line as the previous argument. if (previousComma.LineNumber != location.EndPoint.LineNumber) { int commentLineSpan = MeasureCommentLinesBetween(argument.FindLastChildToken(), previousComma, false); if (previousComma.LineNumber != location.EndPoint.LineNumber + commentLineSpan) { this.AddViolation(element, token.LineNumber, Rules.CommaMustBeOnSameLineAsPreviousParameter); commaOnSameLineAsPreviousParameterViolation = true; } } break; } } } } } }
/// <summary> /// Checks the positioning of method parameters which are split across multiple lines. /// </summary> /// <param name="element"> /// The element. /// </param> /// <param name="arguments"> /// The method arguments. /// </param> /// <param name="openingBracketNode"> /// The opening bracket token. /// </param> /// <param name="friendlyTypeText"> /// The friendly type text to use in reporting violations. /// </param> private void CheckSplitMethodArgumentList(CsElement element, IArgumentList arguments, Node<CsToken> openingBracketNode, string friendlyTypeText) { Param.AssertNotNull(element, "element"); Param.AssertNotNull(arguments, "arguments"); Param.AssertNotNull(openingBracketNode, "openingBracketNode"); Node<CsToken> previousComma = null; bool commaOnSameLineAsPreviousParameterViolation = false; for (int i = 0; i < arguments.Count; ++i) { CodeLocation location = arguments.Location(i); int argumentStartLine = location.LineNumber; CsTokenList tokens = arguments.Tokens(i); // Some types of parameters or arguments are not allowed to span across multiple lines. if (location.LineSpan > 1 && !arguments.MaySpanMultipleLines(i)) { this.AddViolation(element, argumentStartLine, Rules.ParameterMustNotSpanMultipleLines); } if (i == 0) { // The first argument must start on the line after the opening bracket if (argumentStartLine != openingBracketNode.Value.LineNumber + 1) { int commentLineSpan = MeasureCommentLinesAfter(openingBracketNode); if (argumentStartLine != openingBracketNode.Value.LineNumber + commentLineSpan + 1) { this.AddViolation(element, argumentStartLine, Rules.SplitParametersMustStartOnLineAfterDeclaration, friendlyTypeText); } } } else { // The parameter must begin on the line after the previous comma. Debug.Assert(previousComma != null, "The previous comma should have been set."); if (!commaOnSameLineAsPreviousParameterViolation) { if (argumentStartLine != previousComma.Value.LineNumber + 1) { int commentLineSpan = MeasureCommentLinesAfter(previousComma); if (argumentStartLine != previousComma.Value.LineNumber + commentLineSpan + 1) { this.AddViolation(element, argumentStartLine, Rules.ParameterMustFollowComma); } } } } commaOnSameLineAsPreviousParameterViolation = false; // Find the comma after the token list. if (i < arguments.Count - 1) { for (Node<CsToken> tokenNode = tokens.Last.Next; tokenNode != null; tokenNode = tokenNode.Next) { if (tokenNode.Value.CsTokenType == CsTokenType.Comma) { previousComma = tokenNode; // The comma must be on the same line as the previous parameter. if (previousComma.Value.LineNumber != location.EndPoint.LineNumber) { int commentLineSpan = MeasureCommentLinesBetween(tokens.Last, previousComma, false); if (previousComma.Value.LineNumber != location.EndPoint.LineNumber + commentLineSpan) { this.AddViolation(element, tokenNode.Value.LineNumber, Rules.CommaMustBeOnSameLineAsPreviousParameter); commaOnSameLineAsPreviousParameterViolation = true; } } break; } } } } }