Attach colon to constructor header and break line before member initializers

This commit is contained in:
Peter Vingelmann 2016-09-14 03:46:07 +02:00
parent 1bad21fe6b
commit 91bff90bf2

View File

@ -1209,6 +1209,64 @@ string ASFormatter::nextLine()
}
} // (isPotentialHeader && !isInTemplate)
if (currentChar == ':'
&& previousChar != ':' // not part of '::'
&& peekNextChar() != ':') // not part of '::'
{
if (isInCase)
{
isInCase = false;
if (shouldBreakOneLineStatements)
passedColon = true;
}
else if (isCStyle() // for C/C++ only
&& isOkToBreakBlock(bracketTypeStack->back())
&& shouldBreakOneLineStatements
&& !foundQuestionMark // not in a ?: sequence
&& !foundPreDefinitionHeader // not in a definition block (e.g. class foo : public bar
&& previousCommandChar != ')' // not immediately after closing paren of a method header, e.g. ASFormatter::ASFormatter(...) : ASBeautifier(...)
&& !foundPreCommandHeader // not after a 'noexcept'
&& !squareBracketCount // not in objC method call
&& !isInObjCMethodDefinition // not objC '-' or '+' method
&& !isInObjCInterface // not objC @interface
&& !isInObjCSelector // not objC @selector
&& !isDigit(peekNextChar()) // not a bit field
&& !isInEnum // not an enum with a base type
&& !isInAsm // not in extended assembler
&& !isInAsmOneLine // not in extended assembler
&& !isInAsmBlock) // not in extended assembler
{
passedColon = true;
}
if (isCStyle()
&& shouldPadMethodColon
&& (squareBracketCount > 0 || isInObjCMethodDefinition || isInObjCSelector)
&& !foundQuestionMark) // not in a ?: sequence
padObjCMethodColon();
if (isInObjCInterface)
{
appendSpacePad();
if ((int) currentLine.length() > charNum + 1 && !isWhiteSpace(currentLine[charNum + 1]))
currentLine.insert(charNum + 1, " ");
}
if (isClassInitializer())
{
isInClassInitializer = true;
if (!isCharImmediatelyPostComment && !isCharImmediatelyPostLineComment)
{
// Attach colon to the constructor header and force a
// new line before the member initializer list
appendSpacePad();
appendCurrentChar(false);
shouldBreakLineAtNextChar = true;
continue;
}
}
}
if (isInLineBreak) // OK to break line here
{
breakLine();
@ -1255,53 +1313,6 @@ string ASFormatter::nextLine()
resetEndOfStatement();
}
if (currentChar == ':'
&& previousChar != ':' // not part of '::'
&& peekNextChar() != ':') // not part of '::'
{
if (isInCase)
{
isInCase = false;
if (shouldBreakOneLineStatements)
passedColon = true;
}
else if (isCStyle() // for C/C++ only
&& isOkToBreakBlock(bracketTypeStack->back())
&& shouldBreakOneLineStatements
&& !foundQuestionMark // not in a ?: sequence
&& !foundPreDefinitionHeader // not in a definition block (e.g. class foo : public bar
&& previousCommandChar != ')' // not immediately after closing paren of a method header, e.g. ASFormatter::ASFormatter(...) : ASBeautifier(...)
&& !foundPreCommandHeader // not after a 'noexcept'
&& !squareBracketCount // not in objC method call
&& !isInObjCMethodDefinition // not objC '-' or '+' method
&& !isInObjCInterface // not objC @interface
&& !isInObjCSelector // not objC @selector
&& !isDigit(peekNextChar()) // not a bit field
&& !isInEnum // not an enum with a base type
&& !isInAsm // not in extended assembler
&& !isInAsmOneLine // not in extended assembler
&& !isInAsmBlock) // not in extended assembler
{
passedColon = true;
}
if (isCStyle()
&& shouldPadMethodColon
&& (squareBracketCount > 0 || isInObjCMethodDefinition || isInObjCSelector)
&& !foundQuestionMark) // not in a ?: sequence
padObjCMethodColon();
if (isInObjCInterface)
{
appendSpacePad();
if ((int) currentLine.length() > charNum + 1 && !isWhiteSpace(currentLine[charNum + 1]))
currentLine.insert(charNum + 1, " ");
}
if (isClassInitializer())
isInClassInitializer = true;
}
if (currentChar == '?')
foundQuestionMark = true;