MCPcopy Create free account
hub / github.com/KDE/kdevelop / formatArrayBraces

Method formatArrayBraces

plugins/astyle/3rdparty/libastyle/ASFormatter.cpp:5109–5299  ·  view source on GitHub ↗

* format array braces as attached or broken * determine if the braces can have an inStatement indent * currentChar contains the brace * the braces will be appended to the current formattedLine or a new formattedLine as necessary * the calling function should have a continue statement after calling this method * * @param braceType the type of brace to be formatted, must be an ARRAY

Source from the content-addressed store, hash-verified

5107 * @param isOpeningArrayBrace indicates if this is the opening brace for the array block.
5108 */
5109void ASFormatter::formatArrayBraces(BraceType braceType, bool isOpeningArrayBrace)
5110{
5111 assert(isBraceType(braceType, ARRAY_TYPE));
5112 assert(currentChar == '{' || currentChar == '}');
5113
5114 if (currentChar == '{')
5115 {
5116 // is this the first opening brace in the array?
5117 if (isOpeningArrayBrace)
5118 {
5119 if (braceFormatMode == ATTACH_MODE
5120 || braceFormatMode == LINUX_MODE)
5121 {
5122 // break an enum if mozilla
5123 if (isBraceType(braceType, ENUM_TYPE)
5124 && formattingStyle == STYLE_MOZILLA)
5125 {
5126 isInLineBreak = true;
5127 appendCurrentChar(); // don't attach
5128 }
5129 // don't attach to a preprocessor directive or '\' line
5130 else if ((isImmediatelyPostPreprocessor
5131 || (formattedLine.length() > 0
5132 && formattedLine[formattedLine.length() - 1] == '\\'))
5133 && currentLineBeginsWithBrace)
5134 {
5135 isInLineBreak = true;
5136 appendCurrentChar(); // don't attach
5137 }
5138 else if (isCharImmediatelyPostComment)
5139 {
5140 // TODO: attach brace to line-end comment
5141 appendCurrentChar(); // don't attach
5142 }
5143 else if (isCharImmediatelyPostLineComment && !isBraceType(braceType, SINGLE_LINE_TYPE))
5144 {
5145 appendCharInsideComments();
5146 }
5147 else
5148 {
5149 // if a blank line precedes this don't attach
5150 if (isEmptyLine(formattedLine))
5151 appendCurrentChar(); // don't attach
5152 else
5153 {
5154 // if brace is broken or not an assignment
5155 if (currentLineBeginsWithBrace
5156 && !isBraceType(braceType, SINGLE_LINE_TYPE))
5157 {
5158 appendSpacePad();
5159 appendCurrentChar(false); // OK to attach
5160 // TODO: debug the following line
5161 testForTimeToSplitFormattedLine(); // line length will have changed
5162
5163 if (currentLineBeginsWithBrace
5164 && currentLineFirstBraceNum == (size_t) charNum)
5165 shouldBreakLineAtNextChar = true;
5166 }

Callers

nothing calls this directly

Calls 4

lengthMethod · 0.45
hasMoreLinesMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected