Skip to content

Commit

Permalink
CppEditor: Move MoveClassToOwnFile quickfix into its own files
Browse files Browse the repository at this point in the history
Change-Id: I1d54263ac55c57e76120924627949b98816aafc3
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
  • Loading branch information
ckandeler committed May 15, 2024
1 parent 22e91fc commit b16f4cc
Show file tree
Hide file tree
Showing 12 changed files with 856 additions and 734 deletions.
2 changes: 2 additions & 0 deletions src/plugins/cppeditor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ add_qtc_plugin(CppEditor
quickfixes/cppquickfix.cpp quickfixes/cppquickfix.h
quickfixes/cppquickfixassistant.cpp quickfixes/cppquickfixassistant.h
quickfixes/cppquickfixes.cpp quickfixes/cppquickfixes.h
quickfixes/cppquickfixhelpers.h quickfixes/cppquickfixhelpers.cpp
quickfixes/cppquickfixprojectsettings.cpp quickfixes/cppquickfixprojectsettings.h
quickfixes/cppquickfixprojectsettingswidget.cpp quickfixes/cppquickfixprojectsettingswidget.h
quickfixes/cppquickfixsettings.cpp quickfixes/cppquickfixsettings.h
quickfixes/cppquickfixsettingspage.cpp quickfixes/cppquickfixsettingspage.h
quickfixes/cppquickfixsettingswidget.cpp quickfixes/cppquickfixsettingswidget.h
quickfixes/moveclasstoownfile.cpp quickfixes/moveclasstoownfile.h
resourcepreviewhoverhandler.cpp resourcepreviewhoverhandler.h
searchsymbols.cpp searchsymbols.h
semantichighlighter.cpp semantichighlighter.h
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/cppeditor/cppeditor.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ QtcPlugin {
"cppquickfixassistant.h",
"cppquickfixes.cpp",
"cppquickfixes.h",
"cppquickfixhelpers.cpp",
"cppquickfixhelpers.h",
"cppquickfixprojectsettings.cpp",
"cppquickfixprojectsettings.h",
"cppquickfixprojectsettingswidget.cpp",
Expand All @@ -237,6 +239,8 @@ QtcPlugin {
"cppquickfixsettingspage.h",
"cppquickfixsettingswidget.cpp",
"cppquickfixsettingswidget.h",
"moveclasstoownfile.cpp",
"moveclasstoownfile.h",
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../functionutils.h"
#include "../insertionpointlocator.h"
#include "cppquickfixassistant.h"
#include "cppquickfixhelpers.h"

#include <coreplugin/icore.h>
#include <texteditor/fontsettings.h>
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/cppeditor/quickfixes/cppquickfix.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ namespace CppEditor {
namespace Internal {
class CppQuickFixInterface;

// These are generated functions that should not be offered in quickfixes.
const QStringList magicQObjectFunctions();

class CppQuickFixOperation
: public TextEditor::QuickFixOperation,
public Internal::CppQuickFixInterface
Expand Down
96 changes: 0 additions & 96 deletions src/plugins/cppeditor/quickfixes/cppquickfix_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9952,100 +9952,4 @@ void QuickfixTest::testConvertToMetaMethodInvocation()
QuickFixOperationTest({CppTestDocument::create("file.cpp", input, expected)}, &factory);
}

void QuickfixTest::testMoveClassToOwnFile_data()
{
QTest::addColumn<QString>("projectName");
QTest::addColumn<QString>("fileName");
QTest::addColumn<QString>("className");
QTest::addColumn<bool>("applicable");

QTest::newRow("nested") << "nested" << "main.cpp" << "Inner" << false;
QTest::newRow("file name match 1") << "match1" << "TheClass.h" << "TheClass" << false;
QTest::newRow("file name match 2") << "match2" << "theclass.h" << "TheClass" << false;
QTest::newRow("file name match 3") << "match3" << "the_class.h" << "TheClass" << false;
QTest::newRow("single") << "single" << "theheader.h" << "TheClass" << false;
QTest::newRow("complex") << "complex" << "theheader.h" << "TheClass" << true;
QTest::newRow("header only") << "header-only" << "theheader.h" << "TheClass" << true;
QTest::newRow("decl in source file") << "decl-in-source" << "thesource.cpp" << "TheClass" << true;
QTest::newRow("template") << "template" << "theheader.h" << "TheClass" << true;
}

void QuickfixTest::testMoveClassToOwnFile()
{
QFETCH(QString, projectName);
QFETCH(QString, fileName);
QFETCH(QString, className);
QFETCH(bool, applicable);
using namespace CppEditor::Tests;

// Set up project.
Kit * const kit = Utils::findOr(KitManager::kits(), nullptr, [](const Kit *k) {
return k->isValid() && !k->hasWarning() && k->value("QtSupport.QtInformation").isValid();
});
if (!kit)
QSKIP("The test requires at least one valid kit with a valid Qt");
const auto projectDir = std::make_unique<TemporaryCopiedDir>(
":/cppeditor/testcases/move-class/" + projectName);
SourceFilesRefreshGuard refreshGuard;
ProjectOpenerAndCloser projectMgr;
QVERIFY(projectMgr.open(projectDir->absolutePath(projectName + ".pro"), true, kit));
QVERIFY(refreshGuard.wait());

// Open header file and locate class.
const auto headerFilePath = projectDir->absolutePath(fileName);
QVERIFY2(headerFilePath.exists(), qPrintable(headerFilePath.toUserOutput()));
const auto editor = qobject_cast<BaseTextEditor *>(EditorManager::openEditor(headerFilePath));
QVERIFY(editor);
const auto doc = qobject_cast<TextEditor::TextDocument *>(editor->document());
QVERIFY(doc);
QTextCursor classCursor = doc->document()->find("class " + className);
QVERIFY(!classCursor.isNull());
editor->setCursorPosition(classCursor.position());
const auto editorWidget = qobject_cast<CppEditorWidget *>(editor->editorWidget());
QVERIFY(editorWidget);
QVERIFY(TestCase::waitForRehighlightedSemanticDocument(editorWidget));

// Query factory.
MoveClassToOwnFile factory;
factory.setNonInteractive();
CppQuickFixInterface quickFixInterface(editorWidget, ExplicitlyInvoked);
QuickFixOperations operations;
factory.match(quickFixInterface, operations);
QCOMPARE(operations.isEmpty(), !applicable);
if (!applicable)
return;
operations.first()->perform();
QVERIFY(waitForSignalOrTimeout(doc, &IDocument::saved, 30000));
QTest::qWait(1000);

// Compare all files.
const FileFilter filter({"*_expected"}, QDir::Files);
const FilePaths expectedDocuments = projectDir->filePath().dirEntries(filter);
QVERIFY(!expectedDocuments.isEmpty());
for (const FilePath &expected : expectedDocuments) {
static const QString suffix = "_expected";
const FilePath actual = expected.parentDir()
.pathAppended(expected.fileName().chopped(suffix.length()));
QVERIFY(actual.exists());
const auto actualContents = actual.fileContents();
QVERIFY(actualContents);
const auto expectedContents = expected.fileContents();
const QByteArrayList actualLines = actualContents->split('\n');
const QByteArrayList expectedLines = expectedContents->split('\n');
if (actualLines.size() != expectedLines.size()) {
qDebug().noquote().nospace() << "---\n" << *expectedContents << "EOF";
qDebug().noquote().nospace() << "+++\n" << *actualContents << "EOF";
}
QCOMPARE(actualLines.size(), expectedLines.size());
for (int i = 0; i < actualLines.size(); ++i) {
const QByteArray actualLine = actualLines.at(i);
const QByteArray expectedLine = expectedLines.at(i);
if (actualLine != expectedLine)
qDebug() << "Unexpected content in line" << (i + 1) << "of file"
<< actual.fileName();
QCOMPARE(actualLine, expectedLine);
}
}
}

} // namespace CppEditor::Internal::Tests
3 changes: 0 additions & 3 deletions src/plugins/cppeditor/quickfixes/cppquickfix_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ private slots:

void testConvertToMetaMethodInvocation_data();
void testConvertToMetaMethodInvocation();

void testMoveClassToOwnFile_data();
void testMoveClassToOwnFile();
};

} // namespace Tests
Expand Down

0 comments on commit b16f4cc

Please sign in to comment.