Commit 8a917b30 authored by Leandro Melo's avatar Leandro Melo
Browse files

C++: Fix add definitions on empty files



Task-number: QTCREATORBUG-7838

Change-Id: I8e9d452cf4c8ab5dd9f2a7f39d3802baf84609e1
Reviewed-by: default avatarDavid Schulz <david.schulz@nokia.com>
parent 7f98c517
......@@ -593,21 +593,31 @@ QList<InsertionLocation> InsertionPointLocator::methodDefinition(
FindMethodDefinitionInsertPoint finder(doc->translationUnit());
finder(declaration, &line, &column);
// Make sure we have a line before and after the new definition.
const QLatin1String prefix("\n\n");
// Force empty lines before and after the new definition.
QString prefix;
QString suffix;
int firstNonSpace = targetFile->position(line, column);
QChar c = targetFile->charAt(firstNonSpace);
while (c == QLatin1Char(' ') || c == QLatin1Char('\t')) {
++firstNonSpace;
c = targetFile->charAt(firstNonSpace);
}
if (targetFile->charAt(firstNonSpace) != QChar::ParagraphSeparator) {
suffix.append(QLatin1String("\n\n"));
if (!line) {
// Totally empty file.
line = 1;
column = 1;
prefix = suffix = QLatin1Char('\n');
} else {
++firstNonSpace;
if (targetFile->charAt(firstNonSpace) != QChar::ParagraphSeparator)
suffix.append(QLatin1Char('\n'));
QTC_ASSERT(column, return result);
prefix = QLatin1String("\n\n");
int firstNonSpace = targetFile->position(line, column);
QChar c = targetFile->charAt(firstNonSpace);
while (c == QLatin1Char(' ') || c == QLatin1Char('\t')) {
++firstNonSpace;
c = targetFile->charAt(firstNonSpace);
}
if (targetFile->charAt(firstNonSpace) != QChar::ParagraphSeparator) {
suffix.append(QLatin1String("\n\n"));
} else {
++firstNonSpace;
if (targetFile->charAt(firstNonSpace) != QChar::ParagraphSeparator)
suffix.append(QLatin1Char('\n'));
}
}
result += InsertionLocation(target, prefix, suffix, line, column);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment