aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cppeditor
diff options
context:
space:
mode:
authorLorenz Haas <lykurg@gmail.com>2013-11-27 23:08:05 +0100
committerNikolai Kosjar <nikolai.kosjar@digia.com>2014-02-20 21:02:01 +0100
commit88309188c13a22c1dc96dbd009b032925905e25d (patch)
treeec91fca5c7be62473c76f49a67ad2ab6923b5c40 /src/plugins/cppeditor
parent1442c883387bab317f1a5d22179a2d2a18851a7d (diff)
CppEditor: Fix InsertDefFromDecl to find right implementation file
Task-number: QTCREATORBUG-10728 Change-Id: Ic321f7504b55e7bd7badb5262f4d7cc4552ab1fa Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src/plugins/cppeditor')
-rw-r--r--src/plugins/cppeditor/cppeditorplugin.h1
-rw-r--r--src/plugins/cppeditor/cppquickfix_test.cpp40
-rw-r--r--src/plugins/cppeditor/cppquickfixes.cpp23
3 files changed, 60 insertions, 4 deletions
diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h
index 3a510fa6708..95710e71456 100644
--- a/src/plugins/cppeditor/cppeditorplugin.h
+++ b/src/plugins/cppeditor/cppeditorplugin.h
@@ -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();
diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp
index 182d74f44e1..ce12b8e4f2a 100644
--- a/src/plugins/cppeditor/cppquickfix_test.cpp
+++ b/src/plugins/cppeditor/cppquickfix_test.cpp
@@ -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)
{
diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp
index 79c084c050a..7ea9e1d253c 100644
--- a/src/plugins/cppeditor/cppquickfixes.cpp
+++ b/src/plugins/cppeditor/cppquickfixes.cpp
@@ -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;
}
}