CppEditor: Fix "inline" placement also when moving definitions

Not just when creating them.
Amends 9c4ba3ff21.

Task-number: QTCREATORBUG-31678
Change-Id: If1dbb1d5e247543fa91d3c086622926f5daeca93
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2024-12-06 15:33:47 +01:00
parent dc53625359
commit 404832815a
3 changed files with 24 additions and 10 deletions

View File

@@ -35,10 +35,10 @@ namespace CppEditor {
namespace Internal {
namespace Tests {
QList<TestDocumentPtr> singleDocument(const QByteArray &original,
const QByteArray &expected)
QList<TestDocumentPtr> singleDocument(
const QByteArray &original, const QByteArray &expected, const QByteArray fileName)
{
return {CppTestDocument::create("file.cpp", original, expected)};
return {CppTestDocument::create(fileName, original, expected)};
}
BaseQuickFixTestCase::BaseQuickFixTestCase(const QList<TestDocumentPtr> &testDocuments,

View File

@@ -86,8 +86,8 @@ public:
int operationIndex = 0);
};
QList<TestDocumentPtr> singleDocument(const QByteArray &original,
const QByteArray &expected);
QList<TestDocumentPtr> singleDocument(
const QByteArray &original, const QByteArray &expected, const QByteArray fileName = "file.cpp");
} // namespace Tests
} // namespace Internal

View File

@@ -107,9 +107,23 @@ public:
Scope *scopeAtInsertPos = m_toFile->cppDocument()->scopeAt(l.line(), l.column());
// construct definition
const QString funcDec = inlinePrefix(m_toFile->filePath(), [this] { return m_type == MoveOutside; })
+ definitionSignature(m_operation, funcAST, m_fromFile, m_toFile,
scopeAtInsertPos);
const QString inlinePref = inlinePrefix(m_toFile->filePath(), [this] {
return m_type == MoveOutside;
});
QString funcDec = definitionSignature(m_operation, funcAST, m_fromFile, m_toFile,
scopeAtInsertPos);
QString input = funcDec;
int inlineIndex = 0;
const QRegularExpression templateRegex("template\\s*<[^>]*>");
while (input.startsWith("template")) {
const QRegularExpressionMatch match = templateRegex.match(input);
if (match.hasMatch()) {
inlineIndex += match.captured().size() + 1;
input = input.mid(match.captured().size() + 1);
}
}
funcDec.insert(inlineIndex, inlinePref);
QString funcDef = prefix + funcDec;
const int startPosition = m_fromFile->endOf(funcAST->declarator);
const int endPosition = m_fromFile->endOf(funcAST);
@@ -1182,11 +1196,11 @@ private slots:
"class Foo { void fu@nc(); };\n"
"\n"
"template<class T>\n"
"void Foo<T>::func() {}\n";
"inline void Foo<T>::func() {}\n";
;
MoveFuncDefOutside factory;
QuickFixOperationTest(singleDocument(original, expected), &factory);
QuickFixOperationTest(singleDocument(original, expected, "file.h"), &factory);
}
void testMemberFunctionTemplate()