forked from qt-creator/qt-creator
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:
@@ -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,
|
||||
|
@@ -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
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user