* format closing brace * currentChar contains the brace * the calling function should have a continue statement after calling this method * * @param braceType the type of the opening brace for this closing brace. */
| 5025 | * @param braceType the type of the opening brace for this closing brace. |
| 5026 | */ |
| 5027 | void ASFormatter::formatClosingBrace(BraceType braceType) |
| 5028 | { |
| 5029 | assert(!isBraceType(braceType, ARRAY_TYPE)); |
| 5030 | assert(currentChar == '}'); |
| 5031 | |
| 5032 | // parenStack must contain one entry |
| 5033 | if (parenStack->size() > 1) |
| 5034 | parenStack->pop_back(); |
| 5035 | |
| 5036 | // mark state of immediately after empty block |
| 5037 | // this state will be used for locating braces that appear immediately AFTER an empty block (e.g. '{} \n}'). |
| 5038 | if (previousCommandChar == '{') |
| 5039 | isImmediatelyPostEmptyBlock = true; |
| 5040 | |
| 5041 | if (attachClosingBraceMode) |
| 5042 | { |
| 5043 | // for now, namespaces and classes will be attached. Uncomment the lines below to break. |
| 5044 | if ((isEmptyLine(formattedLine) // if a blank line precedes this |
| 5045 | || isCharImmediatelyPostLineComment |
| 5046 | || isCharImmediatelyPostComment |
| 5047 | || (isImmediatelyPostPreprocessor && (int) currentLine.find_first_not_of(" \t") == charNum) |
| 5048 | // || (isBraceType(braceType, CLASS_TYPE) && isOkToBreakBlock(braceType) && previousNonWSChar != '{') |
| 5049 | // || (isBraceType(braceType, NAMESPACE_TYPE) && isOkToBreakBlock(braceType) && previousNonWSChar != '{') |
| 5050 | ) |
| 5051 | && (!isBraceType(braceType, SINGLE_LINE_TYPE) || isOkToBreakBlock(braceType))) |
| 5052 | { |
| 5053 | breakLine(); |
| 5054 | appendCurrentChar(); // don't attach |
| 5055 | } |
| 5056 | else |
| 5057 | { |
| 5058 | if (previousNonWSChar != '{' |
| 5059 | && (!isBraceType(braceType, SINGLE_LINE_TYPE) |
| 5060 | || isOkToBreakBlock(braceType))) |
| 5061 | appendSpacePad(); |
| 5062 | appendCurrentChar(false); // attach |
| 5063 | } |
| 5064 | } |
| 5065 | else if (!isBraceType(braceType, EMPTY_BLOCK_TYPE) |
| 5066 | && (isBraceType(braceType, BREAK_BLOCK_TYPE) |
| 5067 | || isOkToBreakBlock(braceType))) |
| 5068 | { |
| 5069 | breakLine(); |
| 5070 | appendCurrentChar(); |
| 5071 | } |
| 5072 | else |
| 5073 | { |
| 5074 | appendCurrentChar(); |
| 5075 | } |
| 5076 | |
| 5077 | // if a declaration follows a definition, space pad |
| 5078 | if (isLegalNameChar(peekNextChar())) |
| 5079 | appendSpaceAfter(); |
| 5080 | |
| 5081 | if (shouldBreakBlocks |
| 5082 | && currentHeader != nullptr |
| 5083 | && !isHeaderInMultiStatementLine |
| 5084 | && parenStack->back() == 0) |