forked from qt-creator/qt-creator
Beautifier: Unification of the tool's command generation
It's a simple refactoring change. The change, however, is a preparation for further commits and to make the command generation similar to the one used in ClangFormat. Change-Id: I28ecc816dd7b271ff6cda908079a60ab70f145fd Reviewed-by: Jochen Becher <jochen_becher@gmx.de> Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
committed by
David Schulz
parent
34b92b7574
commit
a871e053b6
@@ -101,7 +101,19 @@ QList<QObject *> ArtisticStyle::autoReleaseObjects()
|
|||||||
|
|
||||||
void ArtisticStyle::formatFile()
|
void ArtisticStyle::formatFile()
|
||||||
{
|
{
|
||||||
QString cfgFileName;
|
const QString cfgFileName = configurationFile();
|
||||||
|
if (cfgFileName.isEmpty()) {
|
||||||
|
BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
|
||||||
|
QLatin1String(Constants::ArtisticStyle::DISPLAY_NAME)));
|
||||||
|
} else {
|
||||||
|
m_beautifierPlugin->formatCurrentFile(command(cfgFileName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ArtisticStyle::configurationFile() const
|
||||||
|
{
|
||||||
|
if (m_settings->useCustomStyle())
|
||||||
|
return m_settings->styleFileName(m_settings->customStyle());
|
||||||
|
|
||||||
if (m_settings->useOtherFiles()) {
|
if (m_settings->useOtherFiles()) {
|
||||||
if (const ProjectExplorer::Project *project
|
if (const ProjectExplorer::Project *project
|
||||||
@@ -112,48 +124,41 @@ void ArtisticStyle::formatFile()
|
|||||||
if (!file.endsWith(QLatin1String(".astylerc")))
|
if (!file.endsWith(QLatin1String(".astylerc")))
|
||||||
continue;
|
continue;
|
||||||
const QFileInfo fi(file);
|
const QFileInfo fi(file);
|
||||||
if (fi.isReadable()) {
|
if (fi.isReadable())
|
||||||
cfgFileName = file;
|
return file;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfgFileName.isEmpty() && m_settings->useHomeFile()) {
|
if (m_settings->useHomeFile()) {
|
||||||
const QDir homeDirectory = QDir::home();
|
const QDir homeDirectory = QDir::home();
|
||||||
QString file = homeDirectory.filePath(QLatin1String(".astylerc"));
|
QString file = homeDirectory.filePath(QLatin1String(".astylerc"));
|
||||||
if (QFile::exists(file)) {
|
if (QFile::exists(file))
|
||||||
cfgFileName = file;
|
return file;
|
||||||
} else {
|
file = homeDirectory.filePath(QLatin1String("astylerc"));
|
||||||
file = homeDirectory.filePath(QLatin1String("astylerc"));
|
if (QFile::exists(file))
|
||||||
if (QFile::exists(file))
|
return file;
|
||||||
cfgFileName = file;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_settings->useCustomStyle())
|
return QString();
|
||||||
cfgFileName = m_settings->styleFileName(m_settings->customStyle());
|
}
|
||||||
|
|
||||||
if (cfgFileName.isEmpty()) {
|
Command ArtisticStyle::command(const QString &cfgFile) const
|
||||||
BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
|
{
|
||||||
QLatin1String(Constants::ArtisticStyle::DISPLAY_NAME)));
|
Command command;
|
||||||
|
command.setExecutable(m_settings->command());
|
||||||
|
command.addOption(QLatin1String("-q"));
|
||||||
|
command.addOption(QLatin1String("--options=") + cfgFile);
|
||||||
|
|
||||||
|
if (m_settings->version() > ArtisticStyleSettings::Version_2_03) {
|
||||||
|
command.setProcessing(Command::PipeProcessing);
|
||||||
|
command.setPipeAddsNewline(true);
|
||||||
|
command.setReturnsCRLF(Utils::HostOsInfo::isWindowsHost());
|
||||||
} else {
|
} else {
|
||||||
Command command;
|
command.addOption(QLatin1String("%file"));
|
||||||
command.setExecutable(m_settings->command());
|
|
||||||
command.addOption(QLatin1String("-q"));
|
|
||||||
command.addOption(QLatin1String("--options=") + cfgFileName);
|
|
||||||
|
|
||||||
if (m_settings->version() > ArtisticStyleSettings::Version_2_03) {
|
|
||||||
command.setProcessing(Command::PipeProcessing);
|
|
||||||
command.setPipeAddsNewline(true);
|
|
||||||
command.setReturnsCRLF(Utils::HostOsInfo::isWindowsHost());
|
|
||||||
} else {
|
|
||||||
command.addOption(QLatin1String("%file"));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_beautifierPlugin->formatCurrentFile(command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ArtisticStyle
|
} // namespace ArtisticStyle
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
#define BEAUTIFIER_ARTISTICSTYLE_H
|
#define BEAUTIFIER_ARTISTICSTYLE_H
|
||||||
|
|
||||||
#include "../beautifierabstracttool.h"
|
#include "../beautifierabstracttool.h"
|
||||||
|
#include "../command.h"
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QAction)
|
QT_FORWARD_DECLARE_CLASS(QAction)
|
||||||
|
|
||||||
@@ -63,6 +63,8 @@ private:
|
|||||||
BeautifierPlugin *m_beautifierPlugin;
|
BeautifierPlugin *m_beautifierPlugin;
|
||||||
QAction *m_formatFile;
|
QAction *m_formatFile;
|
||||||
ArtisticStyleSettings *m_settings;
|
ArtisticStyleSettings *m_settings;
|
||||||
|
QString configurationFile() const;
|
||||||
|
Command command(const QString &cfgFile) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ArtisticStyle
|
} // namespace ArtisticStyle
|
||||||
|
@@ -102,7 +102,19 @@ QList<QObject *> Uncrustify::autoReleaseObjects()
|
|||||||
|
|
||||||
void Uncrustify::formatFile()
|
void Uncrustify::formatFile()
|
||||||
{
|
{
|
||||||
QString cfgFileName;
|
const QString cfgFileName = configurationFile();
|
||||||
|
if (cfgFileName.isEmpty()) {
|
||||||
|
BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
|
||||||
|
QLatin1String(Constants::Uncrustify::DISPLAY_NAME)));
|
||||||
|
} else {
|
||||||
|
m_beautifierPlugin->formatCurrentFile(command(cfgFileName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Uncrustify::configurationFile() const
|
||||||
|
{
|
||||||
|
if (m_settings->useCustomStyle())
|
||||||
|
return m_settings->styleFileName(m_settings->customStyle());
|
||||||
|
|
||||||
if (m_settings->useOtherFiles()) {
|
if (m_settings->useOtherFiles()) {
|
||||||
if (const ProjectExplorer::Project *project
|
if (const ProjectExplorer::Project *project
|
||||||
@@ -113,38 +125,33 @@ void Uncrustify::formatFile()
|
|||||||
if (!file.endsWith(QLatin1String("cfg")))
|
if (!file.endsWith(QLatin1String("cfg")))
|
||||||
continue;
|
continue;
|
||||||
const QFileInfo fi(file);
|
const QFileInfo fi(file);
|
||||||
if (fi.isReadable() && fi.fileName() == QLatin1String("uncrustify.cfg")) {
|
if (fi.isReadable() && fi.fileName() == QLatin1String("uncrustify.cfg"))
|
||||||
cfgFileName = file;
|
return file;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfgFileName.isEmpty() && m_settings->useHomeFile()) {
|
if (m_settings->useHomeFile()) {
|
||||||
const QString file = QDir::home().filePath(QLatin1String("uncrustify.cfg"));
|
const QString file = QDir::home().filePath(QLatin1String("uncrustify.cfg"));
|
||||||
if (QFile::exists(file))
|
if (QFile::exists(file))
|
||||||
cfgFileName = file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_settings->useCustomStyle())
|
return QString();
|
||||||
cfgFileName = m_settings->styleFileName(m_settings->customStyle());
|
}
|
||||||
|
|
||||||
if (cfgFileName.isEmpty()) {
|
Command Uncrustify::command(const QString &cfgFile) const
|
||||||
BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
|
{
|
||||||
QLatin1String(Constants::Uncrustify::DISPLAY_NAME)));
|
Command command;
|
||||||
} else {
|
command.setExecutable(m_settings->command());
|
||||||
Command command;
|
command.setProcessing(Command::PipeProcessing);
|
||||||
command.setExecutable(m_settings->command());
|
command.addOption(QLatin1String("-l"));
|
||||||
command.setProcessing(Command::PipeProcessing);
|
command.addOption(QLatin1String("cpp"));
|
||||||
command.addOption(QLatin1String("-l"));
|
command.addOption(QLatin1String("-L"));
|
||||||
command.addOption(QLatin1String("cpp"));
|
command.addOption(QLatin1String("1-2"));
|
||||||
command.addOption(QLatin1String("-L"));
|
command.addOption(QLatin1String("-c"));
|
||||||
command.addOption(QLatin1String("1-2"));
|
command.addOption(cfgFile);
|
||||||
command.addOption(QLatin1String("-c"));
|
return command;
|
||||||
command.addOption(cfgFileName);
|
|
||||||
m_beautifierPlugin->formatCurrentFile(command);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Uncrustify
|
} // namespace Uncrustify
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
#define BEAUTIFIER_UNCRUSTIFY_H
|
#define BEAUTIFIER_UNCRUSTIFY_H
|
||||||
|
|
||||||
#include "../beautifierabstracttool.h"
|
#include "../beautifierabstracttool.h"
|
||||||
|
#include "../command.h"
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QAction)
|
QT_FORWARD_DECLARE_CLASS(QAction)
|
||||||
|
|
||||||
@@ -63,6 +63,8 @@ private:
|
|||||||
BeautifierPlugin *m_beautifierPlugin;
|
BeautifierPlugin *m_beautifierPlugin;
|
||||||
QAction *m_formatFile;
|
QAction *m_formatFile;
|
||||||
UncrustifySettings *m_settings;
|
UncrustifySettings *m_settings;
|
||||||
|
QString configurationFile() const;
|
||||||
|
Command command(const QString &cfgFile) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Uncrustify
|
} // namespace Uncrustify
|
||||||
|
Reference in New Issue
Block a user