CppEditor: Fix added newlines for GenerateGetterSetter quick fix

As a nice side effect superfluous new lines - introduced by quick fixes
that are using InsertionPointLocator::methodDefinition - vanished.

Task-number: QTCREATORBUG-13872
Change-Id: Ib3df2b2acbc22449f16f4444092a57ae93d53d35
Reviewed-by: Jochen Becher <jochen_becher@gmx.de>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Lorenz Haas
2015-02-01 11:32:45 +01:00
committed by Nikolai Kosjar
parent 03212d6e49
commit 7879aa5fae
3 changed files with 29 additions and 30 deletions

View File

@@ -3046,26 +3046,30 @@ public:
const QString implementationGetterTypeAndNameString = oo.prettyType(
getterType, QString::fromLatin1("%1::%2").arg(classString, m_getterName));
const QString implementationGetter = QString::fromLatin1(
"\n%1()%2\n"
"%1()%2\n"
"{\n"
"return %3;\n"
"}\n")
"}")
.arg(implementationGetterTypeAndNameString)
.arg(isStatic ? QString() : QLatin1String(" const"))
.arg(m_variableString);
const QString implementationSetter = QString::fromLatin1(
"\nvoid %1::%2(%3)\n"
"void %1::%2(%3)\n"
"{\n"
"%4 = %5;\n"
"}\n")
"}")
.arg(classString).arg(m_setterName)
.arg(paramString).arg(m_variableString)
.arg(paramName);
QString implementation;
if (generateGetter())
implementation += implementationGetter;
if (generateSetter())
if (generateSetter() && !fullySpecifiedType.isConst()) {
if (!implementation.isEmpty())
implementation += QLatin1String("\n\n");
implementation += implementationSetter;
}
// Create and apply changes
ChangeSet currChanges;
@@ -3076,6 +3080,7 @@ public:
if (sameFile) {
InsertionLocation loc = insertLocationForMethodDefinition(m_symbol, false, refactoring,
currentFile->fileName());
implementation = loc.prefix() + implementation + loc.suffix();
currChanges.insert(currentFile->position(loc.line(), loc.column()), implementation);
} else {
CppRefactoringChanges implRef(snapshot());
@@ -3083,6 +3088,7 @@ public:
ChangeSet implChanges;
InsertionLocation loc = insertLocationForMethodDefinition(m_symbol, false,
implRef, implFileName);
implementation = loc.prefix() + implementation + loc.suffix();
const int implInsertPos = implFile->position(loc.line(), loc.column());
implChanges.insert(implInsertPos, implementation);
implFile->setChangeSet(implChanges);