From 3e07024e10012856892291294a861aaaeb33d5f0 Mon Sep 17 00:00:00 2001 From: Kai Koehne <kai.koehne@nokia.com> Date: Tue, 12 Apr 2011 09:14:31 +0200 Subject: [PATCH] QmlJS: Don't warn user about imports if static info is available Don't underline the import if a qmldump fails, but the typeinfo is available via a .qmltypes file. That should allow users to 'fix' qmldump issues by shipping a .qmltypes file. Reviewed-by: Erik Verbruggen --- src/libs/qmljs/qmljsinterpreter.cpp | 12 ++++++++++++ src/libs/qmljs/qmljsinterpreter.h | 2 ++ src/libs/qmljs/qmljslink.cpp | 12 ++++++++++-- src/libs/qmljs/qmljsmodelmanagerinterface.h | 2 ++ src/plugins/qmljstools/qmljsmodelmanager.cpp | 5 +++++ src/plugins/qmljstools/qmljsmodelmanager.h | 1 + 6 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/libs/qmljs/qmljsinterpreter.cpp b/src/libs/qmljs/qmljsinterpreter.cpp index b3f11d2b20b..65e3b3cd10f 100644 --- a/src/libs/qmljs/qmljsinterpreter.cpp +++ b/src/libs/qmljs/qmljsinterpreter.cpp @@ -1970,6 +1970,7 @@ const Value *Function::invoke(const Activation *activation) const //////////////////////////////////////////////////////////////////////////////// QHash<QString, FakeMetaObject::ConstPtr> CppQmlTypesLoader::builtinObjects; +QHash<QString, QList<LanguageUtils::ComponentVersion> > CppQmlTypesLoader::builtinPackages; QStringList CppQmlTypesLoader::loadQmlTypes(const QFileInfoList &qmlTypeFiles) { @@ -1997,6 +1998,17 @@ QStringList CppQmlTypesLoader::loadQmlTypes(const QFileInfoList &qmlTypeFiles) builtinObjects.unite(newObjects); } + QHash<QString, LanguageUtils::FakeMetaObject::ConstPtr>::const_iterator iter + = builtinObjects.constBegin(); + for (; iter != builtinObjects.constEnd(); iter++) { + foreach (const FakeMetaObject::Export &exp, iter.value().data()->exports()) { + QList<LanguageUtils::ComponentVersion> versions = builtinPackages.value(exp.package); + if (!versions.contains(exp.version)) { + versions.append(exp.version); + builtinPackages.insert(exp.package, versions); + } + } + } return errorMsgs; } diff --git a/src/libs/qmljs/qmljsinterpreter.h b/src/libs/qmljs/qmljsinterpreter.h index c45b4ae8d04..4e787e3688c 100644 --- a/src/libs/qmljs/qmljsinterpreter.h +++ b/src/libs/qmljs/qmljsinterpreter.h @@ -600,7 +600,9 @@ class QMLJS_EXPORT CppQmlTypesLoader public: /** \return an empty list when successful, error messages otherwise. */ static QStringList loadQmlTypes(const QFileInfoList &xmlFiles); + static QHash<QString, LanguageUtils::FakeMetaObject::ConstPtr> builtinObjects; + static QHash<QString, QList<LanguageUtils::ComponentVersion> > builtinPackages; // parses the xml string and fills the newObjects map static QString parseQmlTypeDescriptions(const QByteArray &xml, diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp index a079b517531..cc5adbfb247 100644 --- a/src/libs/qmljs/qmljslink.cpp +++ b/src/libs/qmljs/qmljslink.cpp @@ -347,8 +347,16 @@ bool Link::importLibrary(Document::Ptr doc, Interpreter::ObjectValue *import, tr("Library contains C++ plugins, type dump is in progress.")); } } else if (libraryInfo.dumpStatus() == LibraryInfo::DumpError) { - if (errorLoc.isValid()) { - error(doc, errorLoc, libraryInfo.dumpError()); + ModelManagerInterface *modelManager = ModelManagerInterface::instance(); + + // Only underline import if package/version isn't described in .qmltypes anyway + const QmlJS::ModelManagerInterface::BuiltinPackagesHash builtinPackages + = modelManager->builtinPackages(); + const QString packageName = importInfo.name().replace(QDir::separator(), QLatin1Char('.')); + if (!builtinPackages.value(packageName).contains(importInfo.version())) { + if (errorLoc.isValid()) { + error(doc, errorLoc, libraryInfo.dumpError()); + } } } else { QList<QmlObjectValue *> loadedObjects = diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.h b/src/libs/qmljs/qmljsmodelmanagerinterface.h index 1fa30b4196a..680422eff64 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.h +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.h @@ -110,6 +110,7 @@ public: }; typedef QHash<QString, QList<LanguageUtils::FakeMetaObject::ConstPtr> > CppQmlTypeHash; + typedef QHash<QString, QList<LanguageUtils::ComponentVersion> > BuiltinPackagesHash; public: ModelManagerInterface(QObject *parent = 0); @@ -135,6 +136,7 @@ public: const QString &importUri, const QString &importVersion) = 0; virtual CppQmlTypeHash cppQmlTypes() const = 0; + virtual BuiltinPackagesHash builtinPackages() const = 0; signals: void documentUpdated(QmlJS::Document::Ptr doc); diff --git a/src/plugins/qmljstools/qmljsmodelmanager.cpp b/src/plugins/qmljstools/qmljsmodelmanager.cpp index d6a829b9878..8142322c403 100644 --- a/src/plugins/qmljstools/qmljsmodelmanager.cpp +++ b/src/plugins/qmljstools/qmljsmodelmanager.cpp @@ -640,3 +640,8 @@ ModelManagerInterface::CppQmlTypeHash ModelManager::cppQmlTypes() const QMutexLocker locker(&m_cppTypesMutex); return m_cppTypes; } + +ModelManagerInterface::BuiltinPackagesHash ModelManager::builtinPackages() const +{ + return Interpreter::CppQmlTypesLoader::builtinPackages; +} diff --git a/src/plugins/qmljstools/qmljsmodelmanager.h b/src/plugins/qmljstools/qmljsmodelmanager.h index 9adbb1ad03a..84b9f5d7f6a 100644 --- a/src/plugins/qmljstools/qmljsmodelmanager.h +++ b/src/plugins/qmljstools/qmljsmodelmanager.h @@ -87,6 +87,7 @@ public: const QString &importUri, const QString &importVersion); virtual CppQmlTypeHash cppQmlTypes() const; + virtual BuiltinPackagesHash builtinPackages() const; Q_SIGNALS: void projectPathChanged(const QString &projectPath); -- GitLab