From e3c1e7ade3e4ea6e15e84274c5ff1c98ac199132 Mon Sep 17 00:00:00 2001 From: Tobias Hunger <tobias.hunger@qt.io> Date: Mon, 31 Oct 2016 11:42:30 +0100 Subject: [PATCH] CMake: Unify mapping of type strings to CMakeConfigItem::Type Change-Id: I29b905aac8965039369891e6aad7e356fa1dad8f Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> --- .../cmakeprojectmanager/cmakeconfigitem.cpp | 31 +++++++++++-------- .../cmakeprojectmanager/cmakeconfigitem.h | 1 + .../cmakeprojectmanager/tealeafreader.cpp | 18 ++--------- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp b/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp index fdf1fc0e458..eb10aee6b97 100644 --- a/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp @@ -134,6 +134,23 @@ QStringList CMakeConfigItem::cmakeSplitValue(const QString &in, bool keepEmpty) return newArgs; } +CMakeConfigItem::Type CMakeConfigItem::typeStringToType(const QByteArray &type) +{ + if (type == "BOOL") + return CMakeConfigItem::BOOL; + if (type == "STRING") + return CMakeConfigItem::STRING; + if (type == "FILEPATH") + return CMakeConfigItem::FILEPATH; + if (type == "PATH") + return CMakeConfigItem::PATH; + if (type == "STATIC") + return CMakeConfigItem::STATIC; + + QTC_CHECK(type == "INTERNAL"); + return CMakeConfigItem::INTERNAL; +} + QString CMakeConfigItem::expandedValue(const ProjectExplorer::Kit *k) const { return expandedValue(k->macroExpander()); @@ -195,20 +212,8 @@ CMakeConfigItem CMakeConfigItem::fromString(const QString &s) // Fill in item: CMakeConfigItem item; if (!key.isEmpty()) { - CMakeConfigItem::Type t = CMakeConfigItem::STRING; - if (type == QLatin1String("FILEPATH")) - t = CMakeConfigItem::FILEPATH; - else if (type == QLatin1String("PATH")) - t = CMakeConfigItem::PATH; - else if (type == QLatin1String("BOOL")) - t = CMakeConfigItem::BOOL; - else if (type == QLatin1String("INTERNAL")) - t = CMakeConfigItem::INTERNAL; - else if (type == QLatin1String("STATIC")) - t = CMakeConfigItem::STATIC; - item.key = key.toUtf8(); - item.type = t; + item.type = CMakeConfigItem::typeStringToType(type.toUtf8()); item.value = value.toUtf8(); } return item; diff --git a/src/plugins/cmakeprojectmanager/cmakeconfigitem.h b/src/plugins/cmakeprojectmanager/cmakeconfigitem.h index 24e5c54cd9d..e52a3ee535a 100644 --- a/src/plugins/cmakeprojectmanager/cmakeconfigitem.h +++ b/src/plugins/cmakeprojectmanager/cmakeconfigitem.h @@ -47,6 +47,7 @@ public: static QString expandedValueOf(const ProjectExplorer::Kit *k, const QByteArray &key, const QList<CMakeConfigItem> &input); static QStringList cmakeSplitValue(const QString &in, bool keepEmpty = false); + static Type typeStringToType(const QByteArray &typeString); bool isNull() const { return key.isEmpty(); } QString expandedValue(const ProjectExplorer::Kit *k) const; diff --git a/src/plugins/cmakeprojectmanager/tealeafreader.cpp b/src/plugins/cmakeprojectmanager/tealeafreader.cpp index 76ce5f8f027..b84544d177b 100644 --- a/src/plugins/cmakeprojectmanager/tealeafreader.cpp +++ b/src/plugins/cmakeprojectmanager/tealeafreader.cpp @@ -143,20 +143,6 @@ static QByteArrayList splitCMakeCacheLine(const QByteArray &line) { << line.mid(equalPos + 1); } -static CMakeConfigItem::Type fromByteArray(const QByteArray &type) { - if (type == "BOOL") - return CMakeConfigItem::BOOL; - if (type == "STRING") - return CMakeConfigItem::STRING; - if (type == "FILEPATH") - return CMakeConfigItem::FILEPATH; - if (type == "PATH") - return CMakeConfigItem::PATH; - QTC_CHECK(type == "INTERNAL" || type == "STATIC"); - - return CMakeConfigItem::INTERNAL; -} - // -------------------------------------------------------------------- // TeaLeafReader: // -------------------------------------------------------------------- @@ -305,10 +291,10 @@ CMakeConfig TeaLeafReader::parseConfiguration(const Utils::FileName &cacheFile, if (key.endsWith("-ADVANCED") && value == "1") { advancedSet.insert(key.left(key.count() - 9 /* "-ADVANCED" */)); - } else if (key.endsWith("-STRINGS") && fromByteArray(type) == CMakeConfigItem::INTERNAL) { + } else if (key.endsWith("-STRINGS") && CMakeConfigItem::typeStringToType(type) == CMakeConfigItem::INTERNAL) { valuesMap[key.left(key.count() - 8) /* "-STRINGS" */] = value; } else { - CMakeConfigItem::Type t = fromByteArray(type); + CMakeConfigItem::Type t = CMakeConfigItem::typeStringToType(type); result << CMakeConfigItem(key, t, documentation, value); } } -- GitLab