forked from qt-creator/qt-creator
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 <christian.stenger@qt.io>
This commit is contained in:
@@ -279,7 +279,7 @@ void ArtisticStyle::formatFile()
|
|||||||
if (cfgFileName.isEmpty())
|
if (cfgFileName.isEmpty())
|
||||||
showError(BeautifierTool::msgCannotGetConfigurationFile(asDisplayName()));
|
showError(BeautifierTool::msgCannotGetConfigurationFile(asDisplayName()));
|
||||||
else
|
else
|
||||||
formatCurrentFile(command(cfgFileName.toFSPathString()));
|
formatCurrentFile(textCommand(cfgFileName.toFSPathString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath ArtisticStyle::configurationFile() const
|
FilePath ArtisticStyle::configurationFile() const
|
||||||
@@ -318,10 +318,10 @@ FilePath ArtisticStyle::configurationFile() const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Command ArtisticStyle::command() const
|
Command ArtisticStyle::textCommand() const
|
||||||
{
|
{
|
||||||
const FilePath cfgFile = configurationFile();
|
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
|
bool ArtisticStyle::isApplicable(const Core::IDocument *document) const
|
||||||
@@ -329,25 +329,25 @@ bool ArtisticStyle::isApplicable(const Core::IDocument *document) const
|
|||||||
return settings().isApplicable(document);
|
return settings().isApplicable(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command ArtisticStyle::command(const QString &cfgFile) const
|
Command ArtisticStyle::textCommand(const QString &cfgFile) const
|
||||||
{
|
{
|
||||||
Command command;
|
Command cmd;
|
||||||
command.setExecutable(settings().command());
|
cmd.setExecutable(settings().command());
|
||||||
command.addOption("-q");
|
cmd.addOption("-q");
|
||||||
command.addOption("--options=" + cfgFile);
|
cmd.addOption("--options=" + cfgFile);
|
||||||
|
|
||||||
const QVersionNumber version = settings().version();
|
const QVersionNumber version = settings().version();
|
||||||
if (version > QVersionNumber(2, 3)) {
|
if (version > QVersionNumber(2, 3)) {
|
||||||
command.setProcessing(Command::PipeProcessing);
|
cmd.setProcessing(Command::PipeProcessing);
|
||||||
if (version == QVersionNumber(2, 4))
|
if (version == QVersionNumber(2, 4))
|
||||||
command.setPipeAddsNewline(true);
|
cmd.setPipeAddsNewline(true);
|
||||||
command.setReturnsCRLF(Utils::HostOsInfo::isWindowsHost());
|
cmd.setReturnsCRLF(Utils::HostOsInfo::isWindowsHost());
|
||||||
command.addOption("-z2");
|
cmd.addOption("-z2");
|
||||||
} else {
|
} else {
|
||||||
command.addOption("%file");
|
cmd.addOption("%file");
|
||||||
}
|
}
|
||||||
|
|
||||||
return command;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Beautifier::Internal
|
} // Beautifier::Internal
|
||||||
|
@@ -18,13 +18,13 @@ public:
|
|||||||
|
|
||||||
QString id() const override;
|
QString id() const override;
|
||||||
void updateActions(Core::IEditor *editor) 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;
|
bool isApplicable(const Core::IDocument *document) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void formatFile();
|
void formatFile();
|
||||||
Utils::FilePath configurationFile() const;
|
Utils::FilePath configurationFile() const;
|
||||||
TextEditor::Command command(const QString &cfgFile) const;
|
TextEditor::Command textCommand(const QString &cfgFile) const;
|
||||||
|
|
||||||
QAction *m_formatFile = nullptr;
|
QAction *m_formatFile = nullptr;
|
||||||
};
|
};
|
||||||
|
@@ -139,7 +139,7 @@ void BeautifierPluginPrivate::autoFormatOnSave(Core::IDocument *document)
|
|||||||
if (tool != std::end(tools)) {
|
if (tool != std::end(tools)) {
|
||||||
if (!(*tool)->isApplicable(document))
|
if (!(*tool)->isApplicable(document))
|
||||||
return;
|
return;
|
||||||
const TextEditor::Command command = (*tool)->command();
|
const TextEditor::Command command = (*tool)->textCommand();
|
||||||
if (!command.isValid())
|
if (!command.isValid())
|
||||||
return;
|
return;
|
||||||
const QList<Core::IEditor *> editors = Core::DocumentModel::editorsForDocument(document);
|
const QList<Core::IEditor *> editors = Core::DocumentModel::editorsForDocument(document);
|
||||||
|
@@ -41,7 +41,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @note The received command may be invalid.
|
* @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;
|
virtual bool isApplicable(const Core::IDocument *document) const = 0;
|
||||||
|
|
||||||
|
@@ -374,7 +374,7 @@ void ClangFormat::updateActions(Core::IEditor *editor)
|
|||||||
|
|
||||||
void ClangFormat::formatFile()
|
void ClangFormat::formatFile()
|
||||||
{
|
{
|
||||||
formatCurrentFile(command());
|
formatCurrentFile(textCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangFormat::formatAtPosition(const int pos, const int length)
|
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();
|
const QTextCodec *codec = widget->textDocument()->codec();
|
||||||
if (!codec) {
|
if (!codec) {
|
||||||
formatCurrentFile(command(pos, length));
|
formatCurrentFile(textCommand(pos, length));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +393,7 @@ void ClangFormat::formatAtPosition(const int pos, const int length)
|
|||||||
const QStringView buffer(text);
|
const QStringView buffer(text);
|
||||||
const int encodedOffset = codec->fromUnicode(buffer.left(pos)).size();
|
const int encodedOffset = codec->fromUnicode(buffer.left(pos)).size();
|
||||||
const int encodedLength = codec->fromUnicode(buffer.mid(pos, length)).size();
|
const int encodedLength = codec->fromUnicode(buffer.mid(pos, length)).size();
|
||||||
formatCurrentFile(command(encodedOffset, encodedLength));
|
formatCurrentFile(textCommand(encodedOffset, encodedLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangFormat::formatAtCursor()
|
void ClangFormat::formatAtCursor()
|
||||||
@@ -436,7 +436,7 @@ void ClangFormat::formatLines()
|
|||||||
lineEnd = end.blockNumber() + 1;
|
lineEnd = end.blockNumber() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cmd = command();
|
auto cmd = textCommand();
|
||||||
cmd.addOption(QString("-lines=%1:%2").arg(QString::number(lineStart)).arg(QString::number(lineEnd)));
|
cmd.addOption(QString("-lines=%1:%2").arg(QString::number(lineStart)).arg(QString::number(lineEnd)));
|
||||||
formatCurrentFile(cmd);
|
formatCurrentFile(cmd);
|
||||||
}
|
}
|
||||||
@@ -476,30 +476,30 @@ void ClangFormat::disableFormattingSelectedText()
|
|||||||
formatAtPosition(selectionStartBlock.position(), reformatTextLength);
|
formatAtPosition(selectionStartBlock.position(), reformatTextLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command ClangFormat::command() const
|
Command ClangFormat::textCommand() const
|
||||||
{
|
{
|
||||||
Command command;
|
Command cmd;
|
||||||
command.setExecutable(settings().command());
|
cmd.setExecutable(settings().command());
|
||||||
command.setProcessing(Command::PipeProcessing);
|
cmd.setProcessing(Command::PipeProcessing);
|
||||||
|
|
||||||
if (settings().usePredefinedStyle()) {
|
if (settings().usePredefinedStyle()) {
|
||||||
const QString predefinedStyle = settings().predefinedStyle.stringValue();
|
const QString predefinedStyle = settings().predefinedStyle.stringValue();
|
||||||
command.addOption("-style=" + predefinedStyle);
|
cmd.addOption("-style=" + predefinedStyle);
|
||||||
if (predefinedStyle == "File") {
|
if (predefinedStyle == "File") {
|
||||||
const QString fallbackStyle = settings().fallbackStyle.stringValue();
|
const QString fallbackStyle = settings().fallbackStyle.stringValue();
|
||||||
if (fallbackStyle != "Default")
|
if (fallbackStyle != "Default")
|
||||||
command.addOption("-fallback-style=" + fallbackStyle);
|
cmd.addOption("-fallback-style=" + fallbackStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
command.addOption("-assume-filename=%file");
|
cmd.addOption("-assume-filename=%file");
|
||||||
} else {
|
} else {
|
||||||
command.addOption("-style=file");
|
cmd.addOption("-style=file");
|
||||||
const FilePath path = settings().styleFileName(settings().customStyle())
|
const FilePath path = settings().styleFileName(settings().customStyle())
|
||||||
.absolutePath().pathAppended("%filename");
|
.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
|
bool ClangFormat::isApplicable(const Core::IDocument *document) const
|
||||||
@@ -507,12 +507,12 @@ bool ClangFormat::isApplicable(const Core::IDocument *document) const
|
|||||||
return settings().isApplicable(document);
|
return settings().isApplicable(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command ClangFormat::command(int offset, int length) const
|
Command ClangFormat::textCommand(int offset, int length) const
|
||||||
{
|
{
|
||||||
Command c = command();
|
Command cmd = textCommand();
|
||||||
c.addOption("-offset=" + QString::number(offset));
|
cmd.addOption("-offset=" + QString::number(offset));
|
||||||
c.addOption("-length=" + QString::number(length));
|
cmd.addOption("-length=" + QString::number(length));
|
||||||
return c;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Beautifier::Internal
|
} // Beautifier::Internal
|
||||||
|
@@ -18,7 +18,7 @@ public:
|
|||||||
|
|
||||||
QString id() const override;
|
QString id() const override;
|
||||||
void updateActions(Core::IEditor *editor) 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;
|
bool isApplicable(const Core::IDocument *document) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -27,7 +27,7 @@ private:
|
|||||||
void formatAtCursor();
|
void formatAtCursor();
|
||||||
void formatLines();
|
void formatLines();
|
||||||
void disableFormattingSelectedText();
|
void disableFormattingSelectedText();
|
||||||
TextEditor::Command command(int offset, int length) const;
|
TextEditor::Command textCommand(int offset, int length) const;
|
||||||
|
|
||||||
QAction *m_formatFile = nullptr;
|
QAction *m_formatFile = nullptr;
|
||||||
QAction *m_formatLines = nullptr;
|
QAction *m_formatLines = nullptr;
|
||||||
|
@@ -284,7 +284,7 @@ void Uncrustify::formatFile()
|
|||||||
if (cfgFileName.isEmpty())
|
if (cfgFileName.isEmpty())
|
||||||
showError(msgCannotGetConfigurationFile(uDisplayName()));
|
showError(msgCannotGetConfigurationFile(uDisplayName()));
|
||||||
else
|
else
|
||||||
formatCurrentFile(command(cfgFileName));
|
formatCurrentFile(textCommand(cfgFileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Uncrustify::formatSelectedText()
|
void Uncrustify::formatSelectedText()
|
||||||
@@ -311,7 +311,7 @@ void Uncrustify::formatSelectedText()
|
|||||||
if (tc.positionInBlock() > 0)
|
if (tc.positionInBlock() > 0)
|
||||||
tc.movePosition(QTextCursor::EndOfLine);
|
tc.movePosition(QTextCursor::EndOfLine);
|
||||||
const int endPos = tc.position();
|
const int endPos = tc.position();
|
||||||
formatCurrentFile(command(cfgFileName, true), startPos, endPos);
|
formatCurrentFile(textCommand(cfgFileName, true), startPos, endPos);
|
||||||
} else if (settings().formatEntireFileFallback()) {
|
} else if (settings().formatEntireFileFallback()) {
|
||||||
formatFile();
|
formatFile();
|
||||||
}
|
}
|
||||||
@@ -349,10 +349,10 @@ FilePath Uncrustify::configurationFile() const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Command Uncrustify::command() const
|
Command Uncrustify::textCommand() const
|
||||||
{
|
{
|
||||||
const FilePath cfgFile = configurationFile();
|
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
|
bool Uncrustify::isApplicable(const Core::IDocument *document) const
|
||||||
@@ -360,25 +360,25 @@ bool Uncrustify::isApplicable(const Core::IDocument *document) const
|
|||||||
return settings().isApplicable(document);
|
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 cmd;
|
||||||
command.setExecutable(settings().command());
|
cmd.setExecutable(settings().command());
|
||||||
command.setProcessing(Command::PipeProcessing);
|
cmd.setProcessing(Command::PipeProcessing);
|
||||||
if (settings().version() >= QVersionNumber(0, 62)) {
|
if (settings().version() >= QVersionNumber(0, 62)) {
|
||||||
command.addOption("--assume");
|
cmd.addOption("--assume");
|
||||||
command.addOption("%file");
|
cmd.addOption("%file");
|
||||||
} else {
|
} else {
|
||||||
command.addOption("-l");
|
cmd.addOption("-l");
|
||||||
command.addOption("cpp");
|
cmd.addOption("cpp");
|
||||||
}
|
}
|
||||||
command.addOption("-L");
|
cmd.addOption("-L");
|
||||||
command.addOption("1-2");
|
cmd.addOption("1-2");
|
||||||
if (fragment)
|
if (fragment)
|
||||||
command.addOption("--frag");
|
cmd.addOption("--frag");
|
||||||
command.addOption("-c");
|
cmd.addOption("-c");
|
||||||
command.addOption(cfgFile.path());
|
cmd.addOption(cfgFile.path());
|
||||||
return command;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Beautifier::Internal
|
} // Beautifier::Internal
|
||||||
|
@@ -18,14 +18,14 @@ public:
|
|||||||
|
|
||||||
QString id() const override;
|
QString id() const override;
|
||||||
void updateActions(Core::IEditor *editor) 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;
|
bool isApplicable(const Core::IDocument *document) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void formatFile();
|
void formatFile();
|
||||||
void formatSelectedText();
|
void formatSelectedText();
|
||||||
Utils::FilePath configurationFile() const;
|
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_formatFile = nullptr;
|
||||||
QAction *m_formatRange = nullptr;
|
QAction *m_formatRange = nullptr;
|
||||||
|
Reference in New Issue
Block a user