forked from qt-creator/qt-creator
ClangFormat: Remov unused functions
Change-Id: I294e190cdd76467cb79b58bc818a240cdead8bbc Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -307,12 +307,6 @@ QString configForFile(Utils::FilePath fileName)
|
||||
return configForFile(fileName, true);
|
||||
}
|
||||
|
||||
Utils::FilePath assumedPathForConfig(const QString &configFile)
|
||||
{
|
||||
Utils::FilePath fileName = Utils::FilePath::fromString(configFile);
|
||||
return fileName.parentDir().pathAppended("test.cpp");
|
||||
}
|
||||
|
||||
static clang::format::FormatStyle constructStyle(const QByteArray &baseStyle = QByteArray())
|
||||
{
|
||||
if (!baseStyle.isEmpty()) {
|
||||
@@ -359,56 +353,6 @@ void createStyleFileIfNeeded(bool isGlobal)
|
||||
}
|
||||
}
|
||||
|
||||
static QByteArray configBaseStyleName(const QString &configFile)
|
||||
{
|
||||
if (configFile.isEmpty())
|
||||
return QByteArray();
|
||||
|
||||
QFile config(configFile);
|
||||
if (!config.open(QIODevice::ReadOnly))
|
||||
return QByteArray();
|
||||
|
||||
const QByteArray content = config.readAll();
|
||||
const char basedOnStyle[] = "BasedOnStyle:";
|
||||
int basedOnStyleIndex = content.indexOf(basedOnStyle);
|
||||
if (basedOnStyleIndex < 0)
|
||||
return QByteArray();
|
||||
|
||||
basedOnStyleIndex += sizeof(basedOnStyle) - 1;
|
||||
const int endOfLineIndex = content.indexOf('\n', basedOnStyleIndex);
|
||||
return content
|
||||
.mid(basedOnStyleIndex, endOfLineIndex < 0 ? -1 : endOfLineIndex - basedOnStyleIndex)
|
||||
.trimmed();
|
||||
}
|
||||
|
||||
static clang::format::FormatStyle styleForFile(Utils::FilePath fileName, bool checkForSettings)
|
||||
{
|
||||
QString configFile = configForFile(fileName, checkForSettings);
|
||||
if (configFile.isEmpty()) {
|
||||
// If no configuration is found create a global one (if it does not yet exist) and use it.
|
||||
createStyleFileIfNeeded(true);
|
||||
configFile = globalPath().pathAppended(Constants::SETTINGS_FILE_NAME).toString();
|
||||
}
|
||||
|
||||
fileName = assumedPathForConfig(configFile);
|
||||
Expected<FormatStyle> style = format::getStyle("file",
|
||||
fileName.toString().toStdString(),
|
||||
"none");
|
||||
if (style)
|
||||
return *style;
|
||||
|
||||
handleAllErrors(style.takeError(), [](const ErrorInfoBase &) {
|
||||
// do nothing
|
||||
});
|
||||
|
||||
return constructStyle(configBaseStyleName(configFile));
|
||||
}
|
||||
|
||||
clang::format::FormatStyle styleForFile(Utils::FilePath fileName)
|
||||
{
|
||||
return styleForFile(fileName, true);
|
||||
}
|
||||
|
||||
void addQtcStatementMacros(clang::format::FormatStyle &style)
|
||||
{
|
||||
static const std::vector<std::string> macros = {"Q_OBJECT",
|
||||
@@ -458,26 +402,4 @@ std::string readFile(const QString &path)
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
std::string currentProjectConfigText()
|
||||
{
|
||||
const QString configPath = projectPath().pathAppended(Constants::SETTINGS_FILE_NAME).toString();
|
||||
return readFile(configPath);
|
||||
}
|
||||
|
||||
std::string currentGlobalConfigText()
|
||||
{
|
||||
const QString configPath = globalPath().pathAppended(Constants::SETTINGS_FILE_NAME).toString();
|
||||
return readFile(configPath);
|
||||
}
|
||||
|
||||
clang::format::FormatStyle currentProjectStyle()
|
||||
{
|
||||
return styleForFile(projectPath().pathAppended(Constants::SAMPLE_FILE_NAME), false);
|
||||
}
|
||||
|
||||
clang::format::FormatStyle currentGlobalStyle()
|
||||
{
|
||||
return styleForFile(globalPath().pathAppended(Constants::SAMPLE_FILE_NAME), false);
|
||||
}
|
||||
} // namespace ClangFormat
|
||||
|
@@ -23,11 +23,6 @@ void createStyleFileIfNeeded(bool isGlobal);
|
||||
|
||||
QString currentProjectUniqueId();
|
||||
|
||||
std::string currentProjectConfigText();
|
||||
std::string currentGlobalConfigText();
|
||||
|
||||
clang::format::FormatStyle currentProjectStyle();
|
||||
clang::format::FormatStyle currentGlobalStyle();
|
||||
std::string readFile(const QString &path);
|
||||
|
||||
bool getProjectUseGlobalSettings(const ProjectExplorer::Project *project);
|
||||
@@ -41,7 +36,6 @@ ClangFormatSettings::Mode getCurrentIndentationOrFormattingSettings(const Utils:
|
||||
|
||||
// Is the style from the matching .clang-format file or global one if it's not found.
|
||||
QString configForFile(Utils::FilePath fileName);
|
||||
clang::format::FormatStyle styleForFile(Utils::FilePath fileName);
|
||||
void saveStyleToFile(clang::format::FormatStyle style, Utils::FilePath filePath);
|
||||
|
||||
void addQtcStatementMacros(clang::format::FormatStyle &style);
|
||||
|
Reference in New Issue
Block a user