Expression fragment = fragments[0].receiver;
int startingPositionInCascade = 1;
if (!fragment.isImplicitThis()) {
fragment.traverse(this, scope);
} else {
MessageSend currentMessageSend = fragments[1];
final int numberOfParens = (currentMessageSend.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
if (numberOfParens > 0) {
manageOpeningParenthesizedExpression(currentMessageSend, numberOfParens);
}
ASTNode[] arguments = currentMessageSend.arguments;
TypeReference[] typeArguments = currentMessageSend.typeArguments;
if (typeArguments != null) {
this.scribe.printNextToken(TerminalTokens.TokenNameLESS, this.preferences.insert_space_before_opening_angle_bracket_in_type_arguments);
if (this.preferences.insert_space_after_opening_angle_bracket_in_type_arguments) {
this.scribe.space();
}
int length = typeArguments.length;
for (int i = 0; i < length - 1; i++) {
typeArguments[i].traverse(this, scope);
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_type_arguments);
if (this.preferences.insert_space_after_comma_in_type_arguments) {
this.scribe.space();
}
}
typeArguments[length - 1].traverse(this, scope);
if (isClosingGenericToken()) {
this.scribe.printNextToken(CLOSING_GENERICS_EXPECTEDTOKENS, this.preferences.insert_space_before_closing_angle_bracket_in_type_arguments);
}
if (this.preferences.insert_space_after_closing_angle_bracket_in_type_arguments) {
this.scribe.space();
}
}
this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier); // selector
this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, this.preferences.insert_space_before_opening_paren_in_method_invocation);
if (arguments != null) {
if (this.preferences.insert_space_after_opening_paren_in_method_invocation) {
this.scribe.space();
}
int argumentLength = arguments.length;
Alignment argumentsAlignment = this.scribe.createAlignment(
Alignment.MESSAGE_ARGUMENTS,
this.preferences.alignment_for_arguments_in_method_invocation,
Alignment.R_OUTERMOST,
argumentLength,
this.scribe.scanner.currentPosition);
this.scribe.enterAlignment(argumentsAlignment);
boolean okForArguments = false;
do {
try {
for (int j = 0; j < argumentLength; j++) {
if (j > 0) {
this.scribe.printNextToken(TerminalTokens.TokenNameCOMMA, this.preferences.insert_space_before_comma_in_method_invocation_arguments);
this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
}
this.scribe.alignFragment(argumentsAlignment, j);
if (j > 0 && this.preferences.insert_space_after_comma_in_method_invocation_arguments) {
this.scribe.space();
}
arguments[j].traverse(this, scope);
}
okForArguments = true;
} catch (AlignmentException e) {
this.scribe.redoAlignment(e);
}
} while (!okForArguments);
this.scribe.exitAlignment(argumentsAlignment, true);
this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_method_invocation);
} else {
this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_between_empty_parens_in_method_invocation);
}
if (numberOfParens > 0) {
manageClosingParenthesizedExpression(currentMessageSend, numberOfParens);
}
startingPositionInCascade = 2;
}
int tieBreakRule = this.preferences.wrap_outer_expressions_when_nested && size-startingPositionInCascade > 2
? Alignment.R_OUTERMOST
: Alignment.R_INNERMOST;
Alignment cascadingMessageSendAlignment =
this.scribe.createAlignment(
Alignment.CASCADING_MESSAGE_SEND,
this.preferences.alignment_for_selector_in_method_invocation,
tieBreakRule,
size,
this.scribe.scanner.currentPosition);
this.scribe.enterAlignment(cascadingMessageSendAlignment);
boolean ok = false;
boolean setStartingColumn = true;
switch (this.preferences.alignment_for_arguments_in_method_invocation & Alignment.SPLIT_MASK) {
case Alignment.M_COMPACT_FIRST_BREAK_SPLIT:
case Alignment.M_NEXT_SHIFTED_SPLIT:
case Alignment.M_ONE_PER_LINE_SPLIT:
setStartingColumn = false;
break;
}
do {
if (setStartingColumn) {
cascadingMessageSendAlignment.startingColumn = this.scribe.column;
}
try {
this.scribe.alignFragment(cascadingMessageSendAlignment, 0);
this.scribe.printNextToken(TerminalTokens.TokenNameDOT);
for (int i = startingPositionInCascade; i < size; i++) {
MessageSend currentMessageSend = fragments[i];
final int numberOfParens = (currentMessageSend.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
if (numberOfParens > 0) {
manageOpeningParenthesizedExpression(currentMessageSend, numberOfParens);
}
TypeReference[] typeArguments = currentMessageSend.typeArguments;