* UI */
| 986 | * UI |
| 987 | */ |
| 988 | void DeclarationBuilder::importDirectory(const QString& directory, QmlJS::AST::UiImport* node) |
| 989 | { |
| 990 | DUChainWriteLocker lock; |
| 991 | QString currentFilePath = currentContext()->topContext()->url().str(); |
| 992 | QFileInfo dir(directory); |
| 993 | QFileInfoList entries; |
| 994 | |
| 995 | if (dir.isDir()) { |
| 996 | // Import all the files in the given directory |
| 997 | entries = QDir(directory).entryInfoList( |
| 998 | QStringList{ |
| 999 | (QLatin1String("*.") + currentFilePath.section(QLatin1Char('.'), -1, -1)), |
| 1000 | QStringLiteral("*.qmltypes"), |
| 1001 | QStringLiteral("*.so")}, |
| 1002 | QDir::Files |
| 1003 | ); |
| 1004 | } else if (dir.isFile()) { |
| 1005 | // Import the specific file given in the import statement |
| 1006 | entries.append(dir); |
| 1007 | } else if (!m_prebuilding) { |
| 1008 | m_session->addProblem(node, i18n("Module not found, some types or properties may not be recognized")); |
| 1009 | return; |
| 1010 | } |
| 1011 | |
| 1012 | // Translate the QFileInfos into QStrings (and replace .so files with |
| 1013 | // qmlplugindump dumps) |
| 1014 | lock.unlock(); |
| 1015 | const QStringList filePaths = QmlJS::Cache::instance().getFileNames(entries); |
| 1016 | lock.lock(); |
| 1017 | |
| 1018 | if (node && !node->importId.isEmpty()) { |
| 1019 | // Open a namespace that will contain the declarations |
| 1020 | Identifier identifier(node->importId.toString()); |
| 1021 | RangeInRevision range = m_session->locationToRange(node->importIdToken); |
| 1022 | |
| 1023 | auto* decl = openDeclaration<Declaration>(identifier, range); |
| 1024 | decl->setKind(Declaration::Namespace); |
| 1025 | decl->setInternalContext(openContext(node, range, DUContext::Class, QualifiedIdentifier(identifier))); |
| 1026 | } |
| 1027 | |
| 1028 | for (const QString& filePath : filePaths) { |
| 1029 | if (filePath == currentFilePath) { |
| 1030 | continue; |
| 1031 | } |
| 1032 | |
| 1033 | ReferencedTopDUContext context = m_session->contextOfFile(filePath); |
| 1034 | |
| 1035 | if (context) { |
| 1036 | currentContext()->addImportedParentContext(context.data()); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | if (node && !node->importId.isEmpty()) { |
| 1041 | // Close the namespace containing the declarations |
| 1042 | closeContext(); |
| 1043 | closeDeclaration(); |
| 1044 | } |
| 1045 | } |
nothing calls this directly
no test coverage detected