Commit 88309188 authored by Lorenz Haas's avatar Lorenz Haas Committed by Nikolai Kosjar

CppEditor: Fix InsertDefFromDecl to find right implementation file

Task-number: QTCREATORBUG-10728

Change-Id: Ic321f7504b55e7bd7badb5262f4d7cc4552ab1fa
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 1442c883
......@@ -142,6 +142,7 @@ private slots:
void test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile2();
void test_quickfix_InsertDefFromDecl_erroneousStatementAtEndOfFile();
void test_quickfix_InsertDefFromDecl_rvalueReference();
void test_quickfix_InsertDefFromDecl_findImplementationFile();
void test_quickfix_InsertDeclFromDef();
......
......@@ -1764,6 +1764,46 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_rvalueReference()
QuickFixTestCase(testFiles, &factory);
}
/// Find right implementation file. (QTCREATORBUG-10728)
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_findImplementationFile()
{
QList<QuickFixTestDocument::Ptr> testFiles;
QByteArray original;
QByteArray expected;
// Header File
original =
"class Foo {\n"
" void bar();\n"
" void ba@z();\n"
"};\n"
"\n"
"void Foo::bar()\n"
"{}\n";
expected = original + "\n";
testFiles << QuickFixTestDocument::create("file.h", original, expected);
// Source File
original =
"#include \"file.h\"\n"
;
expected =
"#include \"file.h\"\n"
"\n"
"\n"
"void Foo::baz()\n"
"{\n"
"\n"
"}\n"
"\n"
;
testFiles << QuickFixTestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
QuickFixTestCase(testFiles, &factory);
}
// Function for one of InsertDeclDef section cases
void insertToSectionDeclFromDef(const QByteArray &section, int sectionIndex)
{
......
......@@ -2693,14 +2693,29 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
// be used in perform() to get consistent insert positions.
foreach (const InsertionLocation &location,
locator.methodDefinition(decl, false, QString())) {
if (location.isValid()) {
if (!location.isValid())
continue;
const QString fileName = location.fileName();
if (ProjectFile::isHeader(ProjectFile::classify(fileName))) {
const QString source
= CppTools::correspondingHeaderOrSource(fileName);
if (!source.isEmpty()) {
op = new InsertDefOperation(interface, decl, declAST,
InsertionLocation(),
DefPosImplementationFile,
source);
}
} else {
op = new InsertDefOperation(interface, decl, declAST,
InsertionLocation(),
DefPosImplementationFile,
location.fileName());
result.append(CppQuickFixOperation::Ptr(op));
break;
fileName);
}
if (op)
result.append(CppQuickFixOperation::Ptr(op));
break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment