MCPcopy Create free account
hub / github.com/dirkvranckaert/AndroidDecompiler / formatOpeningBracket

Method formatOpeningBracket

astyle/src/ASFormatter.cpp:3908–4034  ·  view source on GitHub ↗

* format opening bracket as attached or broken * currentChar contains the bracket * the brackets 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 bracketType the type of bracket to be formatted. */

Source from the content-addressed store, hash-verified

3906 * @param bracketType the type of bracket to be formatted.
3907 */
3908void ASFormatter::formatOpeningBracket(BracketType bracketType)
3909{
3910 assert(!isBracketType(bracketType, ARRAY_TYPE));
3911 assert(currentChar == '{');
3912
3913 parenStack->push_back(0);
3914
3915 bool breakBracket = isCurrentBracketBroken();
3916
3917 if (breakBracket)
3918 {
3919 if (isBeforeAnyComment() && isOkToBreakBlock(bracketType))
3920 {
3921 // if comment is at line end leave the comment on this line
3922 if (isBeforeAnyLineEndComment(charNum) && !currentLineBeginsWithBracket)
3923 {
3924 currentChar = ' '; // remove bracket from current line
3925 if (parenStack->size() > 1)
3926 parenStack->pop_back();
3927 currentLine[charNum] = currentChar;
3928 appendOpeningBracket = true; // append bracket to following line
3929 }
3930 // else put comment after the bracket
3931 else if (!isBeforeMultipleLineEndComments(charNum))
3932 breakLine();
3933 }
3934 else if (!isBracketType(bracketType, SINGLE_LINE_TYPE))
3935 breakLine();
3936 else if (shouldBreakOneLineBlocks && peekNextChar() != '}')
3937 breakLine();
3938 else if (!isInLineBreak)
3939 appendSpacePad();
3940
3941 appendCurrentChar();
3942
3943 // should a following comment break from the bracket?
3944 // must break the line AFTER the bracket
3945 if (isBeforeComment()
3946 && formattedLine.length() > 0
3947 && formattedLine[0] == '{'
3948 && isOkToBreakBlock(bracketType)
3949 && (bracketFormatMode == BREAK_MODE
3950 || bracketFormatMode == LINUX_MODE
3951 || bracketFormatMode == STROUSTRUP_MODE))
3952 {
3953 shouldBreakLineAtNextChar = true;
3954 }
3955
3956 }
3957 else // attach bracket
3958 {
3959 // are there comments before the bracket?
3960 if (isCharImmediatelyPostComment || isCharImmediatelyPostLineComment)
3961 {
3962 if (isOkToBreakBlock(bracketType)
3963 && !(isCharImmediatelyPostComment && isCharImmediatelyPostLineComment) // don't attach if two comments on the line
3964 && !isImmediatelyPostPreprocessor
3965// && peekNextChar() != '}' // don't attach { } // removed release 2.03

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected