From caff343769b7ad774806169d8b9218031861c97f Mon Sep 17 00:00:00 2001 From: Thomas Hartmann <Thomas.Hartmann@digia.com> Date: Tue, 26 Nov 2013 09:55:34 +0100 Subject: [PATCH] QmlJS: Fixing warnings Correcting ImportKey::compare(). The compare function was not stable and QMap did not work properly. Done with: Fawzi Change-Id: I11790215cba6944bf9f04be0c3844b35ea54ea70 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com> --- src/libs/qmljs/qmljsimportdependencies.cpp | 38 ++++++++++++++++++-- src/libs/qmljs/qmljsimportdependencies.h | 1 + src/plugins/qmljstools/qmljsmodelmanager.cpp | 2 +- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/libs/qmljs/qmljsimportdependencies.cpp b/src/libs/qmljs/qmljsimportdependencies.cpp index dffcf8ee4b7..9dc0e53f54b 100644 --- a/src/libs/qmljs/qmljsimportdependencies.cpp +++ b/src/libs/qmljs/qmljsimportdependencies.cpp @@ -314,7 +314,7 @@ int ImportKey::compare(const ImportKey &other) const QString v2 = other.splitPath.at(i); if (v1 < v2) return -1; - if (v2 > v1) + if (v1 > v2) return 1; } if (len1 < len2) @@ -626,7 +626,7 @@ void ImportDependencies::iterateOnCandidateImports( break; default: { - QStringList imp = m_importCache.value(key.flatKey()); + const QStringList imp = m_importCache.value(key.flatKey()); foreach (const QString &cImportName, imp) { CoreImport cImport = coreImport(cImportName); if (vContext.languageIsCompatible(cImport.language)) { @@ -928,4 +928,38 @@ QSet<ImportKey> ImportDependencies::subdirImports( return res; } +void ImportDependencies::checkConsistency() const +{ + QMapIterator<ImportKey, QStringList> j(m_importCache); + while (j.hasNext()) { + j.next(); + foreach (const QString &s, j.value()) { + bool found = false; + foreach (const Export &e, m_coreImports.value(s).possibleExports) + if (e.exportName == j.key()) + found = true; + Q_ASSERT(found); + } + } + QMapIterator<QString,CoreImport> i(m_coreImports); + while (i.hasNext()) { + i.next(); + foreach (const Export &e, i.value().possibleExports) { + if (!m_importCache.value(e.exportName).contains(i.key())) { + qDebug() << e.exportName.toString(); + qDebug() << i.key(); + + QMapIterator<ImportKey, QStringList> j(m_importCache); + while (j.hasNext()) { + j.next(); + qDebug() << j.key().toString() << j.value(); + } + qDebug() << m_importCache.contains(e.exportName); + qDebug() << m_importCache.value(e.exportName); + } + Q_ASSERT(m_importCache.value(e.exportName).contains(i.key())); + } + } +} + } // namespace QmlJS diff --git a/src/libs/qmljs/qmljsimportdependencies.h b/src/libs/qmljs/qmljsimportdependencies.h index fc84f0794f2..1e27ef0626a 100644 --- a/src/libs/qmljs/qmljsimportdependencies.h +++ b/src/libs/qmljs/qmljsimportdependencies.h @@ -223,6 +223,7 @@ public: QSet<ImportKey> libraryImports(const ViewerContext &viewContext) const; QSet<ImportKey> subdirImports(const ImportKey &baseKey, const ViewerContext &viewContext) const; + void checkConsistency() const; private: void removeImportCacheEntry(const ImportKey &importKey, const QString &importId); diff --git a/src/plugins/qmljstools/qmljsmodelmanager.cpp b/src/plugins/qmljstools/qmljsmodelmanager.cpp index 61470f40c20..cb6d6f95a21 100644 --- a/src/plugins/qmljstools/qmljsmodelmanager.cpp +++ b/src/plugins/qmljstools/qmljsmodelmanager.cpp @@ -950,13 +950,13 @@ void ModelManager::importScan(QFutureInterface<void> &future, int totalWork(progressRange), workDone(0); future.setProgressRange(0, progressRange); // update max length while iterating? const bool libOnly = true; // FIXME remove when tested more + const Snapshot snapshot = modelManager->snapshot(); while (!pathsToScan.isEmpty() && !future.isCanceled()) { ScanItem toScan = pathsToScan.last(); pathsToScan.pop_back(); int pathBudget = (maxScanDepth + 2 - toScan.depth); if (!scannedPaths.contains(toScan.path)) { QStringList importedFiles; - const Snapshot snapshot = modelManager->snapshot(); if (!findNewQmlLibraryInPath(toScan.path, snapshot, modelManager, &importedFiles, &scannedPaths, &newLibraries, true) && !libOnly && snapshot.documentsInDirectory(toScan.path).isEmpty()) -- GitLab