QmlJS: Allow for QML modules with version subdirectories.

That means
import Foo 2.1
can resolve to
/path/Foo.2.1 or
/path/Foo.2 or
/path/Foo

Task-number: QTCREATORBUG-4607
Change-Id: Ie1efc5be2ca2ed3ccc130e8a662f94aed11bec1a
Reviewed-on: http://codereview.qt.nokia.com/194
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
Christian Kamm
2011-05-27 14:51:30 +02:00
parent 42e5e5f00a
commit 8742026380
6 changed files with 106 additions and 36 deletions

View File

@@ -42,8 +42,6 @@
#include <QtCore/QDir>
#include <QtCore/QDebug>
#include <limits>
using namespace LanguageUtils;
using namespace QmlJS;
using namespace QmlJS::Interpreter;
@@ -278,18 +276,36 @@ Import Link::importNonFile(Document::Ptr doc, const ImportInfo &importInfo)
bool importFound = false;
// check the filesystem
const QString &packagePath = importInfo.name();
// check the filesystem with full version
foreach (const QString &importPath, d->importPaths) {
QString libraryPath = importPath;
libraryPath += QDir::separator();
libraryPath += packagePath;
QString libraryPath = QString("%1/%2.%3").arg(importPath, packagePath, version.toString());
if (importLibrary(doc, libraryPath, &import, importPath)) {
importFound = true;
break;
}
}
if (!importFound) {
// check the filesystem with major version
foreach (const QString &importPath, d->importPaths) {
QString libraryPath = QString("%1/%2.%3").arg(importPath, packagePath,
QString::number(version.majorVersion()));
if (importLibrary(doc, libraryPath, &import, importPath)) {
importFound = true;
break;
}
}
}
if (!importFound) {
// check the filesystem with no version
foreach (const QString &importPath, d->importPaths) {
QString libraryPath = QString("%1/%2").arg(importPath, packagePath);
if (importLibrary(doc, libraryPath, &import, importPath)) {
importFound = true;
break;
}
}
}
// if there are cpp-based types for this package, use them too
if (engine()->cppQmlTypes().hasPackage(packageName)) {
@@ -417,8 +433,7 @@ void Link::loadQmldirComponents(Interpreter::ObjectValue *import, ComponentVersi
// if the version isn't valid, import the latest
if (!version.isValid()) {
const int maxVersion = std::numeric_limits<int>::max();
version = ComponentVersion(maxVersion, maxVersion);
version = ComponentVersion(ComponentVersion::MaxVersion, ComponentVersion::MaxVersion);
}