From 2f7f1aaec3b6e916da278b6f35819f25c1412c36 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 7 Feb 2019 17:22:39 +0100 Subject: [PATCH] Move qrc parser from QmlJS to Utils We'd like to make use of it in a more general context, and it's not directly related to QML. Change-Id: I025ec67829f85544667684cdb8c99d1ee4c18197 Reviewed-by: Eike Ziller --- src/libs/qmljs/qmljs-lib.pri | 2 -- src/libs/qmljs/qmljs.qbs | 1 - src/libs/qmljs/qmljsimportdependencies.cpp | 6 ++-- src/libs/qmljs/qmljslink.cpp | 5 +-- src/libs/qmljs/qmljsmodelmanagerinterface.cpp | 2 ++ src/libs/qmljs/qmljsmodelmanagerinterface.h | 6 ++-- .../qrcparser.cpp} | 34 +++++++++++-------- .../qmljsqrcparser.h => utils/qrcparser.h} | 8 ++--- src/libs/utils/utils-lib.pri | 4 ++- src/libs/utils/utils.qbs | 4 ++- .../designercore/model/texttomodelmerger.cpp | 4 +-- src/plugins/qmljseditor/qmljshoverhandler.cpp | 4 +-- tests/auto/qml/qrcparser/qrcparser.pro | 2 +- tests/auto/qml/qrcparser/qrcparser.qbs | 5 ++- tests/auto/qml/qrcparser/tst_qrcparser.cpp | 4 +-- 15 files changed, 49 insertions(+), 42 deletions(-) rename src/libs/{qmljs/qmljsqrcparser.cpp => utils/qrcparser.cpp} (98%) rename src/libs/{qmljs/qmljsqrcparser.h => utils/qrcparser.h} (96%) diff --git a/src/libs/qmljs/qmljs-lib.pri b/src/libs/qmljs/qmljs-lib.pri index 2aa95a9f7a3..47967446bfd 100644 --- a/src/libs/qmljs/qmljs-lib.pri +++ b/src/libs/qmljs/qmljs-lib.pri @@ -36,7 +36,6 @@ HEADERS += \ $$PWD/jsoncheck.h \ $$PWD/qmljssimplereader.h \ $$PWD/persistenttrie.h \ - $$PWD/qmljsqrcparser.h \ $$PWD/qmljsconstants.h \ $$PWD/qmljsimportdependencies.h \ $$PWD/qmljsviewercontext.h \ @@ -70,7 +69,6 @@ SOURCES += \ $$PWD/jsoncheck.cpp \ $$PWD/qmljssimplereader.cpp \ $$PWD/persistenttrie.cpp \ - $$PWD/qmljsqrcparser.cpp \ $$PWD/qmljsimportdependencies.cpp \ $$PWD/qmljsviewercontext.cpp \ $$PWD/qmljsdialect.cpp diff --git a/src/libs/qmljs/qmljs.qbs b/src/libs/qmljs/qmljs.qbs index ddfb4c200e7..a2580cab1e5 100644 --- a/src/libs/qmljs/qmljs.qbs +++ b/src/libs/qmljs/qmljs.qbs @@ -42,7 +42,6 @@ Project { "qmljsmodelmanagerinterface.cpp", "qmljsmodelmanagerinterface.h", "qmljsplugindumper.cpp", "qmljsplugindumper.h", "qmljspropertyreader.cpp", "qmljspropertyreader.h", - "qmljsqrcparser.cpp", "qmljsqrcparser.h", "qmljsreformatter.cpp", "qmljsreformatter.h", "qmljsrewriter.cpp", "qmljsrewriter.h", "qmljsscanner.cpp", "qmljsscanner.h", diff --git a/src/libs/qmljs/qmljsimportdependencies.cpp b/src/libs/qmljs/qmljsimportdependencies.cpp index adc9c9ff57a..afa8d58b3a7 100644 --- a/src/libs/qmljs/qmljsimportdependencies.cpp +++ b/src/libs/qmljs/qmljsimportdependencies.cpp @@ -25,9 +25,9 @@ #include "qmljsimportdependencies.h" #include "qmljsinterpreter.h" -#include "qmljsqrcparser.h" #include "qmljsviewercontext.h" +#include #include #include @@ -139,10 +139,10 @@ ImportKey::ImportKey(ImportType::Enum type, const QString &path, int majorVersio break; case ImportType::File: case ImportType::QrcFile: - splitPath = QrcParser::normalizedQrcFilePath(path).split(QLatin1Char('/')); + splitPath = Utils::QrcParser::normalizedQrcFilePath(path).split(QLatin1Char('/')); break; case ImportType::QrcDirectory: - splitPath = QrcParser::normalizedQrcDirectoryPath(path).split(QLatin1Char('/')); + splitPath = Utils::QrcParser::normalizedQrcDirectoryPath(path).split(QLatin1Char('/')); if (splitPath.length() > 1 && splitPath.last().isEmpty()) splitPath.removeLast(); break; diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp index 737ec6cc46d..1acdb68ed93 100644 --- a/src/libs/qmljs/qmljslink.cpp +++ b/src/libs/qmljs/qmljslink.cpp @@ -30,9 +30,10 @@ #include "qmljsbind.h" #include "qmljsutils.h" #include "qmljsmodelmanagerinterface.h" -#include "qmljsqrcparser.h" #include "qmljsconstants.h" +#include + #include using namespace LanguageUtils; @@ -557,7 +558,7 @@ void LinkPrivate::loadImplicitDirectoryImports(Imports *imports, Document::Ptr d foreach (const QString &path, ModelManagerInterface::instance()->qrcPathsForFile(doc->fileName())) { processImport(ImportInfo::qrcDirectoryImport( - QrcParser::qrcDirectoryPathForQrcFilePath(path))); + Utils::QrcParser::qrcDirectoryPathForQrcFilePath(path))); } } diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp index 82d4da3f4a6..8f079c9a8d5 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp @@ -52,6 +52,8 @@ #include +using namespace Utils; + namespace QmlJS { QMLJS_EXPORT Q_LOGGING_CATEGORY(qmljsLog, "qtc.qmljs.common", QtWarningMsg) diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.h b/src/libs/qmljs/qmljsmodelmanagerinterface.h index 5de25eead36..cd36cbca2fa 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.h +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.h @@ -28,11 +28,11 @@ #include "qmljs_global.h" #include "qmljsbundle.h" #include "qmljsdocument.h" -#include "qmljsqrcparser.h" #include "qmljsdialect.h" #include #include +#include #include #include @@ -255,7 +255,7 @@ private: void cleanupFutures(); void iterateQrcFiles(ProjectExplorer::Project *project, QrcResourceSelector resources, - std::function callback); + std::function callback); mutable QMutex m_mutex; QmlJS::Snapshot m_validSnapshot; @@ -272,7 +272,7 @@ private: QTimer *m_asyncResetTimer = nullptr; QHash > m_queuedCppDocuments; QFuture m_cppQmlTypesUpdater; - QrcCache m_qrcCache; + Utils::QrcCache m_qrcCache; QHash m_qrcContents; CppDataHash m_cppDataHash; diff --git a/src/libs/qmljs/qmljsqrcparser.cpp b/src/libs/utils/qrcparser.cpp similarity index 98% rename from src/libs/qmljs/qmljsqrcparser.cpp rename to src/libs/utils/qrcparser.cpp index 0a68ebe2fbf..d05ae972036 100644 --- a/src/libs/qmljs/qmljsqrcparser.cpp +++ b/src/libs/utils/qrcparser.cpp @@ -23,22 +23,26 @@ ** ****************************************************************************/ -#include "qmljsqrcparser.h" -#include "qmljsconstants.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "qrcparser.h" + #include -namespace QmlJS { +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +Q_LOGGING_CATEGORY(qrcParserLog, "qtc.qrcParser", QtWarningMsg) + +namespace Utils { namespace Internal { /*! @@ -496,7 +500,7 @@ QrcParser::Ptr QrcCachePrivate::addPath(const QString &path, const QString &cont } QrcParser::Ptr newParser = QrcParser::parseQrcFile(path, contents); if (!newParser->isValid()) - qCWarning(qmljsLog) << "adding invalid qrc " << path << " to the cache:" << newParser->errorMessages(); + qCWarning(qrcParserLog) << "adding invalid qrc " << path << " to the cache:" << newParser->errorMessages(); { QMutexLocker l(&m_mutex); QPair currentValue = m_cache.value(path, {QrcParser::Ptr(0), 0}); diff --git a/src/libs/qmljs/qmljsqrcparser.h b/src/libs/utils/qrcparser.h similarity index 96% rename from src/libs/qmljs/qmljsqrcparser.h rename to src/libs/utils/qrcparser.h index 6973fa6d394..b5a7be761ba 100644 --- a/src/libs/qmljs/qmljsqrcparser.h +++ b/src/libs/utils/qrcparser.h @@ -24,7 +24,7 @@ ****************************************************************************/ #pragma once -#include "qmljs_global.h" +#include "utils_global.h" #include #include @@ -33,14 +33,14 @@ QT_FORWARD_DECLARE_CLASS(QLocale) -namespace QmlJS { +namespace Utils { namespace Internal { class QrcParserPrivate; class QrcCachePrivate; } -class QMLJS_EXPORT QrcParser +class QTCREATOR_UTILS_EXPORT QrcParser { public: typedef QSharedPointer Ptr; @@ -69,7 +69,7 @@ private: Internal::QrcParserPrivate *d; }; -class QMLJS_EXPORT QrcCache +class QTCREATOR_UTILS_EXPORT QrcCache { public: QrcCache(); diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 7de3faefc97..38053e928bc 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -13,7 +13,7 @@ shared { } } -QT += widgets gui network qml +QT += widgets gui network qml xml CONFIG += exceptions # used by portlist.cpp, textfileformat.cpp, and ssh/* @@ -27,6 +27,7 @@ SOURCES += \ $$PWD/environment.cpp \ $$PWD/environmentmodel.cpp \ $$PWD/environmentdialog.cpp \ + $$PWD/qrcparser.cpp \ $$PWD/qtcprocess.cpp \ $$PWD/reloadpromptutils.cpp \ $$PWD/settingsaccessor.cpp \ @@ -135,6 +136,7 @@ HEADERS += \ $$PWD/environmentmodel.h \ $$PWD/environmentdialog.h \ $$PWD/pointeralgorithm.h \ + $$PWD/qrcparser.h \ $$PWD/qtcprocess.h \ $$PWD/utils_global.h \ $$PWD/reloadpromptutils.h \ diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index a646e21973c..bb07e2a927a 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -33,7 +33,7 @@ Project { cpp.frameworks: ["Foundation", "AppKit"] } - Depends { name: "Qt"; submodules: ["concurrent", "network", "qml", "widgets"] } + Depends { name: "Qt"; submodules: ["concurrent", "network", "qml", "widgets", "xml"] } Depends { name: "Qt.macextras"; condition: qbs.targetOS.contains("macos") } Depends { name: "app_version_header" } @@ -189,6 +189,8 @@ Project { "proxycredentialsdialog.cpp", "proxycredentialsdialog.h", "proxycredentialsdialog.ui", + "qrcparser.cpp", + "qrcparser.h", "qtcassert.cpp", "qtcassert.h", "qtcolorbutton.cpp", diff --git a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp index c2dfea0e73e..c5e9b284f16 100644 --- a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp @@ -48,10 +48,10 @@ #include #include #include -#include #include #include +#include #include #include @@ -456,7 +456,7 @@ public: if (!name.isEmpty() && name != QLatin1String(".")) typeName.prepend(name + QLatin1Char('.')); } else if (importInfo.isValid() && importInfo.type() == ImportType::QrcDirectory) { - QString path = QrcParser::normalizedQrcDirectoryPath(importInfo.path()); + QString path = Utils::QrcParser::normalizedQrcDirectoryPath(importInfo.path()); path = path.mid(1, path.size() - ((path.size() > 1) ? 2 : 1)); const QString name = path.replace(QLatin1Char('/'), QLatin1Char('.')); if (!name.isEmpty()) diff --git a/src/plugins/qmljseditor/qmljshoverhandler.cpp b/src/plugins/qmljseditor/qmljshoverhandler.cpp index 6479ba13ad1..9cea65e3ef3 100644 --- a/src/plugins/qmljseditor/qmljshoverhandler.cpp +++ b/src/plugins/qmljseditor/qmljshoverhandler.cpp @@ -43,9 +43,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -133,7 +133,7 @@ static inline QString getModuleName(const ScopeChain &scopeChain, const Document const QString name = relativeDir.replace(QLatin1Char('/'), QLatin1Char('.')); return name; } else if (importInfo.isValid() && importInfo.type() == ImportType::QrcDirectory) { - QString path = QrcParser::normalizedQrcDirectoryPath(importInfo.path()); + QString path = Utils::QrcParser::normalizedQrcDirectoryPath(importInfo.path()); path = path.mid(1, path.size() - ((path.size() > 1) ? 2 : 1)); const QString name = path.replace(QLatin1Char('/'), QLatin1Char('.')); return name; diff --git a/tests/auto/qml/qrcparser/qrcparser.pro b/tests/auto/qml/qrcparser/qrcparser.pro index 571c0a11a33..e78ecbdc930 100644 --- a/tests/auto/qml/qrcparser/qrcparser.pro +++ b/tests/auto/qml/qrcparser/qrcparser.pro @@ -1,5 +1,5 @@ #include(../shared/shared.pri) -QTC_PLUGIN_DEPENDS += qmljstools +QTC_PLUGIN_DEPENDS += utils include(../../qttest.pri) #DEFINES+=CPLUSPLUS_BUILD_STATIC_LIB include($$IDE_SOURCE_TREE/src/rpath.pri) diff --git a/tests/auto/qml/qrcparser/qrcparser.qbs b/tests/auto/qml/qrcparser/qrcparser.qbs index f08e32a0630..432dca6d8be 100644 --- a/tests/auto/qml/qrcparser/qrcparser.qbs +++ b/tests/auto/qml/qrcparser/qrcparser.qbs @@ -1,9 +1,8 @@ import qbs QtcAutotest { - name: "QML qrc parser autotest" - Depends { name: "QmlJS" } - Depends { name: "QmlJSTools" } + name: "qrc parser autotest" + Depends { name: "Utils" } files: "tst_qrcparser.cpp" cpp.defines: base.concat(['TESTSRCDIR="' + path + '"']) } diff --git a/tests/auto/qml/qrcparser/tst_qrcparser.cpp b/tests/auto/qml/qrcparser/tst_qrcparser.cpp index d8c3f03c36c..10f3dfd10ca 100644 --- a/tests/auto/qml/qrcparser/tst_qrcparser.cpp +++ b/tests/auto/qml/qrcparser/tst_qrcparser.cpp @@ -27,9 +27,9 @@ #include #include -#include +#include -using namespace QmlJS; +using namespace Utils; class tst_QrcParser: public QObject {