From c828ba2f309f8c8db94eb4c440f5748d36fe91a1 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 25 Jul 2023 17:56:27 +0200 Subject: [PATCH] Beautifier: Rename some entities called 'command' A confusing amount of TextCommand or Utils::Command objects or -returning functions were called 'command'. Rename a few to make future reasoning simpler. Change-Id: I872b2e841cb40a4533e5ebcd37cb05489158cec7 Reviewed-by: Christian Stenger --- .../artisticstyle/artisticstyle.cpp | 28 +++++++------- .../beautifier/artisticstyle/artisticstyle.h | 4 +- src/plugins/beautifier/beautifierplugin.cpp | 2 +- src/plugins/beautifier/beautifiertool.h | 2 +- .../beautifier/clangformat/clangformat.cpp | 38 +++++++++---------- .../beautifier/clangformat/clangformat.h | 4 +- .../beautifier/uncrustify/uncrustify.cpp | 36 +++++++++--------- .../beautifier/uncrustify/uncrustify.h | 4 +- 8 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/plugins/beautifier/artisticstyle/artisticstyle.cpp b/src/plugins/beautifier/artisticstyle/artisticstyle.cpp index 68d546508d6..20a9f41e221 100644 --- a/src/plugins/beautifier/artisticstyle/artisticstyle.cpp +++ b/src/plugins/beautifier/artisticstyle/artisticstyle.cpp @@ -279,7 +279,7 @@ void ArtisticStyle::formatFile() if (cfgFileName.isEmpty()) showError(BeautifierTool::msgCannotGetConfigurationFile(asDisplayName())); else - formatCurrentFile(command(cfgFileName.toFSPathString())); + formatCurrentFile(textCommand(cfgFileName.toFSPathString())); } FilePath ArtisticStyle::configurationFile() const @@ -318,10 +318,10 @@ FilePath ArtisticStyle::configurationFile() const return {}; } -Command ArtisticStyle::command() const +Command ArtisticStyle::textCommand() const { const FilePath cfgFile = configurationFile(); - return cfgFile.isEmpty() ? Command() : command(cfgFile.toFSPathString()); + return cfgFile.isEmpty() ? Command() : textCommand(cfgFile.toFSPathString()); } bool ArtisticStyle::isApplicable(const Core::IDocument *document) const @@ -329,25 +329,25 @@ bool ArtisticStyle::isApplicable(const Core::IDocument *document) const return settings().isApplicable(document); } -Command ArtisticStyle::command(const QString &cfgFile) const +Command ArtisticStyle::textCommand(const QString &cfgFile) const { - Command command; - command.setExecutable(settings().command()); - command.addOption("-q"); - command.addOption("--options=" + cfgFile); + Command cmd; + cmd.setExecutable(settings().command()); + cmd.addOption("-q"); + cmd.addOption("--options=" + cfgFile); const QVersionNumber version = settings().version(); if (version > QVersionNumber(2, 3)) { - command.setProcessing(Command::PipeProcessing); + cmd.setProcessing(Command::PipeProcessing); if (version == QVersionNumber(2, 4)) - command.setPipeAddsNewline(true); - command.setReturnsCRLF(Utils::HostOsInfo::isWindowsHost()); - command.addOption("-z2"); + cmd.setPipeAddsNewline(true); + cmd.setReturnsCRLF(Utils::HostOsInfo::isWindowsHost()); + cmd.addOption("-z2"); } else { - command.addOption("%file"); + cmd.addOption("%file"); } - return command; + return cmd; } } // Beautifier::Internal diff --git a/src/plugins/beautifier/artisticstyle/artisticstyle.h b/src/plugins/beautifier/artisticstyle/artisticstyle.h index 45b94fbd463..2a20b7f1f2f 100644 --- a/src/plugins/beautifier/artisticstyle/artisticstyle.h +++ b/src/plugins/beautifier/artisticstyle/artisticstyle.h @@ -18,13 +18,13 @@ public: QString id() const override; void updateActions(Core::IEditor *editor) override; - TextEditor::Command command() const override; + TextEditor::Command textCommand() const override; bool isApplicable(const Core::IDocument *document) const override; private: void formatFile(); Utils::FilePath configurationFile() const; - TextEditor::Command command(const QString &cfgFile) const; + TextEditor::Command textCommand(const QString &cfgFile) const; QAction *m_formatFile = nullptr; }; diff --git a/src/plugins/beautifier/beautifierplugin.cpp b/src/plugins/beautifier/beautifierplugin.cpp index d4389b00c54..e7a4b7593fc 100644 --- a/src/plugins/beautifier/beautifierplugin.cpp +++ b/src/plugins/beautifier/beautifierplugin.cpp @@ -139,7 +139,7 @@ void BeautifierPluginPrivate::autoFormatOnSave(Core::IDocument *document) if (tool != std::end(tools)) { if (!(*tool)->isApplicable(document)) return; - const TextEditor::Command command = (*tool)->command(); + const TextEditor::Command command = (*tool)->textCommand(); if (!command.isValid()) return; const QList editors = Core::DocumentModel::editorsForDocument(document); diff --git a/src/plugins/beautifier/beautifiertool.h b/src/plugins/beautifier/beautifiertool.h index f8c99aef55b..b41197b49e5 100644 --- a/src/plugins/beautifier/beautifiertool.h +++ b/src/plugins/beautifier/beautifiertool.h @@ -41,7 +41,7 @@ public: * * @note The received command may be invalid. */ - virtual TextEditor::Command command() const = 0; + virtual TextEditor::Command textCommand() const = 0; virtual bool isApplicable(const Core::IDocument *document) const = 0; diff --git a/src/plugins/beautifier/clangformat/clangformat.cpp b/src/plugins/beautifier/clangformat/clangformat.cpp index 8277af19fb7..9ed2d4f4a40 100644 --- a/src/plugins/beautifier/clangformat/clangformat.cpp +++ b/src/plugins/beautifier/clangformat/clangformat.cpp @@ -374,7 +374,7 @@ void ClangFormat::updateActions(Core::IEditor *editor) void ClangFormat::formatFile() { - formatCurrentFile(command()); + formatCurrentFile(textCommand()); } void ClangFormat::formatAtPosition(const int pos, const int length) @@ -385,7 +385,7 @@ void ClangFormat::formatAtPosition(const int pos, const int length) const QTextCodec *codec = widget->textDocument()->codec(); if (!codec) { - formatCurrentFile(command(pos, length)); + formatCurrentFile(textCommand(pos, length)); return; } @@ -393,7 +393,7 @@ void ClangFormat::formatAtPosition(const int pos, const int length) const QStringView buffer(text); const int encodedOffset = codec->fromUnicode(buffer.left(pos)).size(); const int encodedLength = codec->fromUnicode(buffer.mid(pos, length)).size(); - formatCurrentFile(command(encodedOffset, encodedLength)); + formatCurrentFile(textCommand(encodedOffset, encodedLength)); } void ClangFormat::formatAtCursor() @@ -436,7 +436,7 @@ void ClangFormat::formatLines() lineEnd = end.blockNumber() + 1; } - auto cmd = command(); + auto cmd = textCommand(); cmd.addOption(QString("-lines=%1:%2").arg(QString::number(lineStart)).arg(QString::number(lineEnd))); formatCurrentFile(cmd); } @@ -476,30 +476,30 @@ void ClangFormat::disableFormattingSelectedText() formatAtPosition(selectionStartBlock.position(), reformatTextLength); } -Command ClangFormat::command() const +Command ClangFormat::textCommand() const { - Command command; - command.setExecutable(settings().command()); - command.setProcessing(Command::PipeProcessing); + Command cmd; + cmd.setExecutable(settings().command()); + cmd.setProcessing(Command::PipeProcessing); if (settings().usePredefinedStyle()) { const QString predefinedStyle = settings().predefinedStyle.stringValue(); - command.addOption("-style=" + predefinedStyle); + cmd.addOption("-style=" + predefinedStyle); if (predefinedStyle == "File") { const QString fallbackStyle = settings().fallbackStyle.stringValue(); if (fallbackStyle != "Default") - command.addOption("-fallback-style=" + fallbackStyle); + cmd.addOption("-fallback-style=" + fallbackStyle); } - command.addOption("-assume-filename=%file"); + cmd.addOption("-assume-filename=%file"); } else { - command.addOption("-style=file"); + cmd.addOption("-style=file"); const FilePath path = settings().styleFileName(settings().customStyle()) .absolutePath().pathAppended("%filename"); - command.addOption("-assume-filename=" + path.nativePath()); + cmd.addOption("-assume-filename=" + path.nativePath()); } - return command; + return cmd; } bool ClangFormat::isApplicable(const Core::IDocument *document) const @@ -507,12 +507,12 @@ bool ClangFormat::isApplicable(const Core::IDocument *document) const return settings().isApplicable(document); } -Command ClangFormat::command(int offset, int length) const +Command ClangFormat::textCommand(int offset, int length) const { - Command c = command(); - c.addOption("-offset=" + QString::number(offset)); - c.addOption("-length=" + QString::number(length)); - return c; + Command cmd = textCommand(); + cmd.addOption("-offset=" + QString::number(offset)); + cmd.addOption("-length=" + QString::number(length)); + return cmd; } } // Beautifier::Internal diff --git a/src/plugins/beautifier/clangformat/clangformat.h b/src/plugins/beautifier/clangformat/clangformat.h index 9b6b00df40b..82f6ac160b9 100644 --- a/src/plugins/beautifier/clangformat/clangformat.h +++ b/src/plugins/beautifier/clangformat/clangformat.h @@ -18,7 +18,7 @@ public: QString id() const override; void updateActions(Core::IEditor *editor) override; - TextEditor::Command command() const override; + TextEditor::Command textCommand() const override; bool isApplicable(const Core::IDocument *document) const override; private: @@ -27,7 +27,7 @@ private: void formatAtCursor(); void formatLines(); void disableFormattingSelectedText(); - TextEditor::Command command(int offset, int length) const; + TextEditor::Command textCommand(int offset, int length) const; QAction *m_formatFile = nullptr; QAction *m_formatLines = nullptr; diff --git a/src/plugins/beautifier/uncrustify/uncrustify.cpp b/src/plugins/beautifier/uncrustify/uncrustify.cpp index 819906266f8..fb69eac520c 100644 --- a/src/plugins/beautifier/uncrustify/uncrustify.cpp +++ b/src/plugins/beautifier/uncrustify/uncrustify.cpp @@ -284,7 +284,7 @@ void Uncrustify::formatFile() if (cfgFileName.isEmpty()) showError(msgCannotGetConfigurationFile(uDisplayName())); else - formatCurrentFile(command(cfgFileName)); + formatCurrentFile(textCommand(cfgFileName)); } void Uncrustify::formatSelectedText() @@ -311,7 +311,7 @@ void Uncrustify::formatSelectedText() if (tc.positionInBlock() > 0) tc.movePosition(QTextCursor::EndOfLine); const int endPos = tc.position(); - formatCurrentFile(command(cfgFileName, true), startPos, endPos); + formatCurrentFile(textCommand(cfgFileName, true), startPos, endPos); } else if (settings().formatEntireFileFallback()) { formatFile(); } @@ -349,10 +349,10 @@ FilePath Uncrustify::configurationFile() const return {}; } -Command Uncrustify::command() const +Command Uncrustify::textCommand() const { const FilePath cfgFile = configurationFile(); - return cfgFile.isEmpty() ? Command() : command(cfgFile, false); + return cfgFile.isEmpty() ? Command() : textCommand(cfgFile, false); } bool Uncrustify::isApplicable(const Core::IDocument *document) const @@ -360,25 +360,25 @@ bool Uncrustify::isApplicable(const Core::IDocument *document) const return settings().isApplicable(document); } -Command Uncrustify::command(const FilePath &cfgFile, bool fragment) const +Command Uncrustify::textCommand(const FilePath &cfgFile, bool fragment) const { - Command command; - command.setExecutable(settings().command()); - command.setProcessing(Command::PipeProcessing); + Command cmd; + cmd.setExecutable(settings().command()); + cmd.setProcessing(Command::PipeProcessing); if (settings().version() >= QVersionNumber(0, 62)) { - command.addOption("--assume"); - command.addOption("%file"); + cmd.addOption("--assume"); + cmd.addOption("%file"); } else { - command.addOption("-l"); - command.addOption("cpp"); + cmd.addOption("-l"); + cmd.addOption("cpp"); } - command.addOption("-L"); - command.addOption("1-2"); + cmd.addOption("-L"); + cmd.addOption("1-2"); if (fragment) - command.addOption("--frag"); - command.addOption("-c"); - command.addOption(cfgFile.path()); - return command; + cmd.addOption("--frag"); + cmd.addOption("-c"); + cmd.addOption(cfgFile.path()); + return cmd; } } // Beautifier::Internal diff --git a/src/plugins/beautifier/uncrustify/uncrustify.h b/src/plugins/beautifier/uncrustify/uncrustify.h index 71ee4730c14..090b06e0423 100644 --- a/src/plugins/beautifier/uncrustify/uncrustify.h +++ b/src/plugins/beautifier/uncrustify/uncrustify.h @@ -18,14 +18,14 @@ public: QString id() const override; void updateActions(Core::IEditor *editor) override; - TextEditor::Command command() const override; + TextEditor::Command textCommand() const override; bool isApplicable(const Core::IDocument *document) const override; private: void formatFile(); void formatSelectedText(); Utils::FilePath configurationFile() const; - TextEditor::Command command(const Utils::FilePath &cfgFile, bool fragment = false) const; + TextEditor::Command textCommand(const Utils::FilePath &cfgFile, bool fragment = false) const; QAction *m_formatFile = nullptr; QAction *m_formatRange = nullptr;