diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-05 08:51:05 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-06 08:19:23 +0200 |
commit | 2b8ec2eacbf96340ce95a2648450fde07bf3b5c3 (patch) | |
tree | fcd14125a2af765a4e3cee2e5d9926fe0d9e6b5b /src/qmlcompiler | |
parent | d6091eb768a898377d191143ac8b43b1b666a2d7 (diff) |
QmlCompiler: Split importFileOrDirectory() in two
importing a file and importing a directory are really quite different
things and the code paths inside the function were completely separate.
We also don't have to create a map of ImportedTypes if we are only going
to return a single one.
Change-Id: Ifbb0caa70e9272dfde2d9f1cf5ed1b102e02f5cc
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r-- | src/qmlcompiler/qqmljsimporter.cpp | 20 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsimporter_p.h | 6 |
2 files changed, 12 insertions, 14 deletions
diff --git a/src/qmlcompiler/qqmljsimporter.cpp b/src/qmlcompiler/qqmljsimporter.cpp index 5caccd36cb..3a8507aa67 100644 --- a/src/qmlcompiler/qqmljsimporter.cpp +++ b/src/qmlcompiler/qqmljsimporter.cpp @@ -264,22 +264,18 @@ QQmlJSScope::Ptr QQmlJSImporter::localFile2ScopeTree(const QString &filePath) return result; } -QQmlJSImporter::ImportedTypes QQmlJSImporter::importFileOrDirectory( - const QString &fileOrDirectory, const QString &prefix) +QQmlJSScope::Ptr QQmlJSImporter::importFile(const QString &file) { - AvailableTypes result; - - QString name = fileOrDirectory; + return localFile2ScopeTree(file); +} - QFileInfo fileInfo(name); - if (fileInfo.isFile()) { - QQmlJSScope::Ptr scope(localFile2ScopeTree(fileInfo.canonicalFilePath())); - result.qmlNames.insert(prefix.isEmpty() ? scope->internalName() : prefix, scope); - return result.qmlNames; - } +QQmlJSImporter::ImportedTypes QQmlJSImporter::importDirectory( + const QString &directory, const QString &prefix) +{ + AvailableTypes result; QDirIterator it { - fileInfo.canonicalFilePath(), + directory, QStringList() << QLatin1String("*.qml"), QDir::NoFilter }; diff --git a/src/qmlcompiler/qqmljsimporter_p.h b/src/qmlcompiler/qqmljsimporter_p.h index 43bc0296b8..245964a339 100644 --- a/src/qmlcompiler/qqmljsimporter_p.h +++ b/src/qmlcompiler/qqmljsimporter_p.h @@ -53,8 +53,10 @@ public: ImportedTypes importBuiltins(); ImportedTypes importQmltypes(const QStringList &qmltypesFiles); - ImportedTypes importFileOrDirectory( - const QString &fileOrDirectory, const QString &prefix = QString()); + + QQmlJSScope::Ptr importFile(const QString &file); + ImportedTypes importDirectory(const QString &directory, const QString &prefix = QString()); + ImportedTypes importModule( const QString &module, const QString &prefix = QString(), QTypeRevision version = QTypeRevision()); |