| 63 | } |
| 64 | |
| 65 | QString QmlJS::Cache::modulePath(const KDevelop::IndexedString& baseFile, const QString& uri, const QString& version) |
| 66 | { |
| 67 | QMutexLocker lock(&m_mutex); |
| 68 | QString cacheKey = uri + version; |
| 69 | QString path = m_modulePaths.value(cacheKey, QString()); |
| 70 | |
| 71 | if (!path.isEmpty()) { |
| 72 | return path; |
| 73 | } |
| 74 | |
| 75 | // Find the path for which <path>/u/r/i exists |
| 76 | QString fragment = QString(uri).replace(QLatin1Char('.'), QDir::separator()); |
| 77 | bool isVersion1 = version.startsWith(QLatin1String("1.")); |
| 78 | bool isQtQuick = (uri == QLatin1String("QtQuick")); |
| 79 | |
| 80 | const QStringList modulesWithoutVersionSuffix{ |
| 81 | QStringLiteral("QtQml"), |
| 82 | QStringLiteral("QtMultimedia"), |
| 83 | QStringLiteral("QtQuick.LocalStorage"), |
| 84 | QStringLiteral("QtQuick.XmlListModel"), |
| 85 | }; |
| 86 | |
| 87 | if (!isVersion1 && !fragment.isEmpty() && !fragment.endsWith(QLatin1Char('/')) && !version.isEmpty() |
| 88 | && !modulesWithoutVersionSuffix.contains(uri)) { |
| 89 | // Modules having a version greater or equal to 2 are stored in a directory |
| 90 | // name like QtQuick.2 |
| 91 | fragment += QLatin1Char('.') + version.section(QLatin1Char('.'), 0, 0); |
| 92 | } |
| 93 | |
| 94 | const auto paths = libraryPaths_internal(baseFile); |
| 95 | for (auto& p : paths) { |
| 96 | QString pathString = p.cd(fragment).path(); |
| 97 | |
| 98 | // HACK: QtQuick 1.0 is put in $LIB/qt5/imports/builtins.qmltypes. The "QtQuick" |
| 99 | // identifier appears nowhere. |
| 100 | if (isQtQuick && isVersion1) { |
| 101 | if (QFile::exists(p.cd(QStringLiteral("builtins.qmltypes")).path())) { |
| 102 | path = p.path(); |
| 103 | break; |
| 104 | } |
| 105 | } else if (QFile::exists(pathString + QLatin1String("/plugins.qmltypes"))) { |
| 106 | path = pathString; |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | m_modulePaths.insert(cacheKey, path); |
| 112 | return path; |
| 113 | } |
| 114 | |
| 115 | QStringList QmlJS::Cache::getFileNames(const QFileInfoList& fileInfos) |
| 116 | { |