diff options
author | Marco Benelli <marco.benelli@qt.io> | 2017-09-28 16:24:13 +0200 |
---|---|---|
committer | Marco Benelli <marco.benelli@qt.io> | 2017-10-16 11:10:17 +0000 |
commit | c054dd2cffd1c42c1dc59d00c87a5008c3c229d1 (patch) | |
tree | 61b2227dc0c486c6ac64896888601e32c2d0c9bb /src/libs/qmljs/qmljsplugindumper.cpp | |
parent | 79bdd7e14f3b3cc584c4a5911bf11e6fc835ca28 (diff) |
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 <tim.jenssen@qt.io>
Diffstat (limited to 'src/libs/qmljs/qmljsplugindumper.cpp')
-rw-r--r-- | src/libs/qmljs/qmljsplugindumper.cpp | 40 |
1 files changed, 14 insertions, 26 deletions
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 <qmljs/qmljsinterpreter.h> #include <qmljs/qmljsviewercontext.h> @@ -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: - * - * - <name>.<major>.<minor>/plugins.qmltypes - * - <name>.<major>/plugins.qmltypes - * - <name>/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("^(?<name>[\\w|\\.]+)\\s+(?<major>\\d+)\\.(?<minor>\\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(); } |