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

Method formatRunIn

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

* determine if a run-in can be attached. * if it can insert the indents in formattedLine and reset the current line break. */

Source from the content-addressed store, hash-verified

5303 * if it can insert the indents in formattedLine and reset the current line break.
5304 */
5305void ASFormatter::formatRunIn()
5306{
5307 assert(braceFormatMode == RUN_IN_MODE || braceFormatMode == NONE_MODE);
5308
5309 // keep one line blocks returns true without indenting the run-in
5310 if (formattingStyle != STYLE_PICO
5311 && !isOkToBreakBlock(braceTypeStack->back()))
5312 return; // true;
5313
5314 // make sure the line begins with a brace
5315 size_t lastText = formattedLine.find_last_not_of(" \t");
5316 if (lastText == string::npos || formattedLine[lastText] != '{')
5317 return; // false;
5318
5319 // make sure the brace is broken
5320 if (formattedLine.find_first_not_of(" \t{") != string::npos)
5321 return; // false;
5322
5323 if (isBraceType(braceTypeStack->back(), NAMESPACE_TYPE))
5324 return; // false;
5325
5326 bool extraIndent = false;
5327 bool extraHalfIndent = false;
5328 isInLineBreak = true;
5329
5330 // cannot attach a class modifier without indent-classes
5331 if (isCStyle()
5332 && isCharPotentialHeader(currentLine, charNum)
5333 && (isBraceType(braceTypeStack->back(), CLASS_TYPE)
5334 || (isBraceType(braceTypeStack->back(), STRUCT_TYPE)
5335 && isInIndentableStruct)))
5336 {
5337 if (findKeyword(currentLine, charNum, AS_PUBLIC)
5338 || findKeyword(currentLine, charNum, AS_PRIVATE)
5339 || findKeyword(currentLine, charNum, AS_PROTECTED))
5340 {
5341 if (getModifierIndent())
5342 extraHalfIndent = true;
5343 else if (!getClassIndent())
5344 return; // false;
5345 }
5346 else if (getClassIndent())
5347 extraIndent = true;
5348 }
5349
5350 // cannot attach a 'case' statement without indent-switches
5351 if (!getSwitchIndent()
5352 && isCharPotentialHeader(currentLine, charNum)
5353 && (findKeyword(currentLine, charNum, AS_CASE)
5354 || findKeyword(currentLine, charNum, AS_DEFAULT)))
5355 return; // false;
5356
5357 // extra indent for switch statements
5358 if (getSwitchIndent()
5359 && !preBraceHeaderStack->empty()
5360 && preBraceHeaderStack->back() == &AS_SWITCH
5361 && ((isLegalNameChar(currentChar)
5362 && !findKeyword(currentLine, charNum, AS_CASE))))

Callers

nothing calls this directly

Calls 5

emptyMethod · 0.80
backMethod · 0.45
lengthMethod · 0.45
appendMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected