From 2b8ec2eacbf96340ce95a2648450fde07bf3b5c3 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 5 Oct 2020 08:51:05 +0200 Subject: 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 --- tools/qmllint/findwarnings.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'tools/qmllint') diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp index 17d3588123..d601b3e910 100644 --- a/tools/qmllint/findwarnings.cpp +++ b/tools/qmllint/findwarnings.cpp @@ -137,7 +137,7 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiProgram *) // using an empty QQmlJSScope m_rootScopeImports.insert(QFileInfo { m_filePath }.baseName(), {}); - const auto imported = m_importer.importFileOrDirectory(QFileInfo(m_filePath).path()); + const auto imported = m_importer.importDirectory(QFileInfo(m_filePath).canonicalPath()); m_rootScopeImports.insert(imported); const QStringList warnings = m_importer.takeWarnings(); @@ -539,10 +539,15 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiImport *import) auto filename = import->fileName.toString(); if (!filename.isEmpty()) { const QFileInfo file(filename); - const auto imported = m_importer.importFileOrDirectory( - file.isRelative() ? QFileInfo(m_filePath).dir().filePath(filename) : filename, - prefix); - m_rootScopeImports.insert(imported); + const QFileInfo path(file.isRelative() ? QFileInfo(m_filePath).dir().filePath(filename) + : filename); + if (path.isDir()) { + m_rootScopeImports.insert(m_importer.importDirectory(path.canonicalFilePath(), prefix)); + } else if (path.isFile()) { + const auto scope = m_importer.importFile(path.canonicalFilePath()); + m_rootScopeImports.insert(prefix.isEmpty() ? scope->internalName() : prefix, scope); + } + } QString path {}; -- cgit v1.2.3