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 Internal {
|
||||||
namespace Tests {
|
namespace Tests {
|
||||||
|
|
||||||
QList<TestDocumentPtr> singleDocument(const QByteArray &original,
|
QList<TestDocumentPtr> singleDocument(
|
||||||
const QByteArray &expected)
|
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,
|
BaseQuickFixTestCase::BaseQuickFixTestCase(const QList<TestDocumentPtr> &testDocuments,
|
||||||
|
@@ -86,8 +86,8 @@ public:
|
|||||||
int operationIndex = 0);
|
int operationIndex = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
QList<TestDocumentPtr> singleDocument(const QByteArray &original,
|
QList<TestDocumentPtr> singleDocument(
|
||||||
const QByteArray &expected);
|
const QByteArray &original, const QByteArray &expected, const QByteArray fileName = "file.cpp");
|
||||||
|
|
||||||
} // namespace Tests
|
} // namespace Tests
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -107,9 +107,23 @@ public:
|
|||||||
Scope *scopeAtInsertPos = m_toFile->cppDocument()->scopeAt(l.line(), l.column());
|
Scope *scopeAtInsertPos = m_toFile->cppDocument()->scopeAt(l.line(), l.column());
|
||||||
|
|
||||||
// construct definition
|
// construct definition
|
||||||
const QString funcDec = inlinePrefix(m_toFile->filePath(), [this] { return m_type == MoveOutside; })
|
const QString inlinePref = inlinePrefix(m_toFile->filePath(), [this] {
|
||||||
+ definitionSignature(m_operation, funcAST, m_fromFile, m_toFile,
|
return m_type == MoveOutside;
|
||||||
|
});
|
||||||
|
QString funcDec = definitionSignature(m_operation, funcAST, m_fromFile, m_toFile,
|
||||||
scopeAtInsertPos);
|
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;
|
QString funcDef = prefix + funcDec;
|
||||||
const int startPosition = m_fromFile->endOf(funcAST->declarator);
|
const int startPosition = m_fromFile->endOf(funcAST->declarator);
|
||||||
const int endPosition = m_fromFile->endOf(funcAST);
|
const int endPosition = m_fromFile->endOf(funcAST);
|
||||||
@@ -1182,11 +1196,11 @@ private slots:
|
|||||||
"class Foo { void fu@nc(); };\n"
|
"class Foo { void fu@nc(); };\n"
|
||||||
"\n"
|
"\n"
|
||||||
"template<class T>\n"
|
"template<class T>\n"
|
||||||
"void Foo<T>::func() {}\n";
|
"inline void Foo<T>::func() {}\n";
|
||||||
;
|
;
|
||||||
|
|
||||||
MoveFuncDefOutside factory;
|
MoveFuncDefOutside factory;
|
||||||
QuickFixOperationTest(singleDocument(original, expected), &factory);
|
QuickFixOperationTest(singleDocument(original, expected, "file.h"), &factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
void testMemberFunctionTemplate()
|
void testMemberFunctionTemplate()
|
||||||
|
Reference in New Issue
Block a user