forked from qt-creator/qt-creator
CppEditor: Consider comments when extracting a new function
That is, do not place the newly created function in between the function and its comment. Fixes: QTCREATORBUG-6934 Change-Id: I79f564a90c7e3c45188f5d694cbde47029651324 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -7843,7 +7843,8 @@ void QuickfixTest::testExtractFunction_data()
|
|||||||
QTest::addColumn<QByteArray>("expected");
|
QTest::addColumn<QByteArray>("expected");
|
||||||
|
|
||||||
QTest::newRow("basic")
|
QTest::newRow("basic")
|
||||||
<< _("void f()\n"
|
<< _("// Documentation for f\n"
|
||||||
|
"void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" @{start}g();@{end}\n"
|
" @{start}g();@{end}\n"
|
||||||
"}\n")
|
"}\n")
|
||||||
@@ -7852,6 +7853,7 @@ void QuickfixTest::testExtractFunction_data()
|
|||||||
" g();\n"
|
" g();\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"// Documentation for f\n"
|
||||||
"void f()\n"
|
"void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" extracted();\n"
|
" extracted();\n"
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include <cplusplus/ASTPath.h>
|
#include <cplusplus/ASTPath.h>
|
||||||
#include <cplusplus/CPlusPlusForwardDeclarations.h>
|
#include <cplusplus/CPlusPlusForwardDeclarations.h>
|
||||||
#include <cplusplus/CppRewriter.h>
|
#include <cplusplus/CppRewriter.h>
|
||||||
|
#include <cplusplus/declarationcomments.h>
|
||||||
#include <cplusplus/NamePrettyPrinter.h>
|
#include <cplusplus/NamePrettyPrinter.h>
|
||||||
#include <cplusplus/TypeOfExpression.h>
|
#include <cplusplus/TypeOfExpression.h>
|
||||||
#include <cplusplus/TypePrettyPrinter.h>
|
#include <cplusplus/TypePrettyPrinter.h>
|
||||||
@@ -5150,6 +5151,16 @@ public:
|
|||||||
// formatting) it's simpler to have two different change sets.
|
// formatting) it's simpler to have two different change sets.
|
||||||
ChangeSet change;
|
ChangeSet change;
|
||||||
int position = currentFile->startOf(m_refFuncDef);
|
int position = currentFile->startOf(m_refFuncDef);
|
||||||
|
|
||||||
|
// Do not insert right between the function and an associated comment.
|
||||||
|
const QList<Token> functionDoc = commentsForDeclaration(
|
||||||
|
m_refFuncDef->symbol, m_refFuncDef, *currentFile->document(),
|
||||||
|
currentFile->cppDocument());
|
||||||
|
if (!functionDoc.isEmpty()) {
|
||||||
|
position = currentFile->cppDocument()->translationUnit()->getTokenPositionInDocument(
|
||||||
|
functionDoc.first(), currentFile->document());
|
||||||
|
}
|
||||||
|
|
||||||
change.insert(position, funcDef);
|
change.insert(position, funcDef);
|
||||||
change.replace(m_extractionStart, m_extractionEnd, funcCall);
|
change.replace(m_extractionStart, m_extractionEnd, funcCall);
|
||||||
currentFile->setChangeSet(change);
|
currentFile->setChangeSet(change);
|
||||||
|
Reference in New Issue
Block a user