From c054dd2cffd1c42c1dc59d00c87a5008c3c229d1 Mon Sep 17 00:00:00 2001 From: Marco Benelli Date: Thu, 28 Sep 2017 16:24:13 +0200 Subject: QmlJs: fix bug in resolving qml imports The introduction of Controls.2 changed the way in which imports are resolved. This patch fix some leftovers of the old resolution scheme. Such leftovers caused false positives in import declaration to happen when resetting the QML/JS code model. The code has also been simplified a little, by the removal of duplicate code and of unused methods. Change-Id: I90bdf7ed47fdfea7cbd8259acd7a9a968f27301b Reviewed-by: Tim Jenssen --- src/libs/qmljs/qmljsplugindumper.cpp | 40 +++++++++++++----------------------- 1 file changed, 14 insertions(+), 26 deletions(-) (limited to 'src/libs/qmljs/qmljsplugindumper.cpp') diff --git a/src/libs/qmljs/qmljsplugindumper.cpp b/src/libs/qmljs/qmljsplugindumper.cpp index c5ba42c13e..7ada84f28b 100644 --- a/src/libs/qmljs/qmljsplugindumper.cpp +++ b/src/libs/qmljs/qmljsplugindumper.cpp @@ -25,6 +25,7 @@ #include "qmljsplugindumper.h" #include "qmljsmodelmanagerinterface.h" +#include "qmljsutils.h" #include #include @@ -401,48 +402,35 @@ void PluginDumper::loadQmlTypeDescription(const QStringList &paths, /*! * \brief Build the path of an existing qmltypes file from a module name. * \param name - * \return the module's qmltypes file path + * \return the module's qmltypes file path or an empty string if not found * * Look for \a name qmltypes file in model manager's import paths. - * For each import path the following files are searched, in this order: - * - * - ../plugins.qmltypes - * - ./plugins.qmltypes - * - /plugins.qmltypes - * - * That means that a more qualified directory name has precedence over a - * less qualified one. Be aware that the import paths order has a stronger - * precedence, so a less qualified name could shadow a more qualified one if - * it resides in a different import path. * + * \sa QmlJs::modulePath * \sa LinkPrivate::importNonFile */ QString PluginDumper::buildQmltypesPath(const QString &name) const { QString qualifiedName; - QString majorVersion; - QString minorVersion; + QString version; QRegularExpression import("^(?[\\w|\\.]+)\\s+(?\\d+)\\.(?\\d+)$"); QRegularExpressionMatch m = import.match(name); if (m.hasMatch()) { qualifiedName = m.captured("name"); - majorVersion = m.captured("major"); - minorVersion = m.captured("minor"); + version = m.captured("major") + QLatin1Char('.') + m.captured("minor"); } - for (const PathAndLanguage &p: m_modelManager->importPaths()) { - QString moduleName = qualifiedName.replace(QLatin1Char('.'), QLatin1Char('/')); - QString moduleNameMajor = moduleName + QLatin1Char('.') + majorVersion; - QString moduleNameMajorMinor = moduleNameMajor + QLatin1Char('.') + minorVersion; + const QString path = modulePath(qualifiedName, version, m_modelManager->importPathsNames()); + + if (path.isEmpty()) + return QString(); + + const QString filename = path + QLatin1String("/plugins.qmltypes"); + + if (QFile::exists(filename)) + return filename; - for (const auto n: QStringList{moduleNameMajorMinor, moduleNameMajor, moduleName}) { - QString filename(p.path().toString() + QLatin1Char('/') + n - + QLatin1String("/plugins.qmltypes")); - if (QFile::exists(filename)) - return filename; - } - } return QString(); } -- cgit v1.2.3