forked from qt-creator/qt-creator
qmljs: (QString -> Utils::FilePath)++
convert more QString containing paths to Utils::FilePath Change-Id: I1219d7d147993e48cfa641dc9bea72ab38c90f51 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
committed by
Tim Jenssen
parent
0bb272d411
commit
fd89043de2
@@ -87,20 +87,19 @@ using namespace QmlJS::AST;
|
||||
threads finish and new information becomes available.
|
||||
*/
|
||||
|
||||
Document::Document(const QString &fileName, Dialect language)
|
||||
Document::Document(const Utils::FilePath &fileName, Dialect language)
|
||||
: _engine(nullptr)
|
||||
, _ast(nullptr)
|
||||
, _bind(nullptr)
|
||||
, _fileName(QDir::cleanPath(fileName))
|
||||
, _fileName(fileName.cleanPath())
|
||||
, _editorRevision(0)
|
||||
, _language(language)
|
||||
, _parsedCorrectly(false)
|
||||
{
|
||||
QFileInfo fileInfo(fileName);
|
||||
_path = QDir::cleanPath(fileInfo.absolutePath());
|
||||
_path = fileName.absoluteFilePath().parentDir().cleanPath();
|
||||
|
||||
if (language.isQmlLikeLanguage()) {
|
||||
_componentName = fileInfo.baseName();
|
||||
_componentName = fileName.baseName();
|
||||
|
||||
if (! _componentName.isEmpty()) {
|
||||
// ### TODO: check the component name.
|
||||
@@ -120,7 +119,7 @@ Document::~Document()
|
||||
delete _engine;
|
||||
}
|
||||
|
||||
Document::MutablePtr Document::create(const QString &fileName, Dialect language)
|
||||
Document::MutablePtr Document::create(const Utils::FilePath &fileName, Dialect language)
|
||||
{
|
||||
Document::MutablePtr doc(new Document(fileName, language));
|
||||
doc->_ptr = doc;
|
||||
@@ -149,7 +148,7 @@ void Document::setLanguage(Dialect l)
|
||||
|
||||
QString Document::importId() const
|
||||
{
|
||||
return _fileName;
|
||||
return _fileName.toString();
|
||||
}
|
||||
|
||||
QByteArray Document::fingerprint() const
|
||||
@@ -213,13 +212,13 @@ void Document::setEditorRevision(int revision)
|
||||
_editorRevision = revision;
|
||||
}
|
||||
|
||||
QString Document::fileName() const
|
||||
Utils::FilePath Document::fileName() const
|
||||
{
|
||||
return _fileName;
|
||||
|
||||
}
|
||||
|
||||
QString Document::path() const
|
||||
Utils::FilePath Document::path() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
@@ -244,7 +243,7 @@ class CollectDirectives : public Directives
|
||||
QList<SourceLocation> _locations;
|
||||
|
||||
public:
|
||||
CollectDirectives(const QString &documentPath)
|
||||
CollectDirectives(const Utils::FilePath &documentPath)
|
||||
: documentPath(documentPath)
|
||||
, isLibrary(false)
|
||||
|
||||
@@ -272,7 +271,7 @@ public:
|
||||
|
||||
virtual QList<SourceLocation> locations() { return _locations; }
|
||||
|
||||
const QString documentPath;
|
||||
const Utils::FilePath documentPath;
|
||||
bool isLibrary;
|
||||
QList<ImportInfo> imports;
|
||||
};
|
||||
@@ -471,29 +470,29 @@ Snapshot::~Snapshot()
|
||||
void Snapshot::insert(const Document::Ptr &document, bool allowInvalid)
|
||||
{
|
||||
if (document && (allowInvalid || document->qmlProgram() || document->jsProgram())) {
|
||||
const QString fileName = document->fileName();
|
||||
const QString path = document->path();
|
||||
const Utils::FilePath fileName = document->fileName();
|
||||
const Utils::FilePath path = document->path();
|
||||
remove(fileName);
|
||||
_documentsByPath[path].append(document);
|
||||
_documents.insert(fileName, document);
|
||||
CoreImport cImport;
|
||||
cImport.importId = document->importId();
|
||||
cImport.language = document->language();
|
||||
cImport.addPossibleExport(Export(ImportKey(ImportType::File, fileName),
|
||||
{}, true, QFileInfo(fileName).baseName()));
|
||||
cImport.addPossibleExport(
|
||||
Export(ImportKey(ImportType::File, fileName.toString()), {}, true, fileName.baseName()));
|
||||
cImport.fingerprint = document->fingerprint();
|
||||
_dependencies.addCoreImport(cImport);
|
||||
}
|
||||
}
|
||||
|
||||
void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
|
||||
void Snapshot::insertLibraryInfo(const Utils::FilePath &path, const LibraryInfo &info)
|
||||
{
|
||||
QTC_CHECK(!path.isEmpty());
|
||||
QTC_CHECK(info.fingerprint() == info.calculateFingerprint());
|
||||
_libraries.insert(QDir::cleanPath(path), info);
|
||||
_libraries.insert(path.cleanPath(), info);
|
||||
if (!info.wasFound()) return;
|
||||
CoreImport cImport;
|
||||
cImport.importId = path;
|
||||
cImport.importId = path.toString();
|
||||
cImport.language = Dialect::AnyLanguage;
|
||||
QSet<ImportKey> packages;
|
||||
foreach (const ModuleApiInfo &moduleInfo, info.moduleApis()) {
|
||||
@@ -509,7 +508,7 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
|
||||
}
|
||||
}
|
||||
|
||||
QStringList splitPath = path.split(QLatin1Char('/'));
|
||||
QStringList splitPath = path.path().split(QLatin1Char('/'));
|
||||
const QRegularExpression vNr(QLatin1String("^(.+)\\.([0-9]+)(?:\\.([0-9]+))?$"));
|
||||
const QRegularExpression safeName(QLatin1String("^[a-zA-Z_][[a-zA-Z0-9_]*$"));
|
||||
foreach (const ImportKey &importKey, packages) {
|
||||
@@ -526,12 +525,17 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
|
||||
break;
|
||||
ImportKey iKey(ImportType::Library, QStringList(myPath.mid(iPath)).join(QLatin1Char('.')),
|
||||
importKey.majorVersion, importKey.minorVersion);
|
||||
cImport.addPossibleExport(Export(iKey, (iPath == 1) ? QLatin1String("/") :
|
||||
QStringList(myPath.mid(0, iPath)).join(QLatin1Char('/')), true));
|
||||
Utils::FilePath newP(path);
|
||||
newP.setPath((iPath == 1)
|
||||
? QLatin1String("/")
|
||||
: QStringList(myPath.mid(0, iPath)).join(QLatin1Char('/')));
|
||||
cImport.addPossibleExport(Export(iKey, newP, true));
|
||||
}
|
||||
} else {
|
||||
QString requiredPath = QStringList(splitPath.mid(0, splitPath.size() - importKey.splitPath.size()))
|
||||
.join(QLatin1String("/"));
|
||||
Utils::FilePath requiredPath(path);
|
||||
requiredPath.setPath(
|
||||
QStringList(splitPath.mid(0, splitPath.size() - importKey.splitPath.size()))
|
||||
.join(QLatin1String("/")));
|
||||
cImport.addPossibleExport(Export(importKey, requiredPath, true));
|
||||
}
|
||||
}
|
||||
@@ -567,8 +571,11 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
|
||||
break;
|
||||
ImportKey iKey(ImportType::Library, QStringList(splitPath.mid(iPath)).join(QLatin1Char('.')),
|
||||
majorVersion, minorVersion);
|
||||
cImport.addPossibleExport(Export(iKey, (iPath == 1) ? QLatin1String("/") :
|
||||
QStringList(splitPath.mid(0, iPath)).join(QLatin1Char('/')), true));
|
||||
Utils::FilePath newP(path);
|
||||
newP.setPath((iPath == 1)
|
||||
? QLatin1String("/")
|
||||
: QStringList(splitPath.mid(0, iPath)).join(QLatin1Char('/')));
|
||||
cImport.addPossibleExport(Export(iKey, newP, true));
|
||||
}
|
||||
}
|
||||
foreach (const QmlDirParser::Component &component, info.components()) {
|
||||
@@ -580,11 +587,11 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
|
||||
_dependencies.addCoreImport(cImport);
|
||||
}
|
||||
|
||||
void Snapshot::remove(const QString &fileName)
|
||||
void Snapshot::remove(const Utils::FilePath &fileName)
|
||||
{
|
||||
Document::Ptr doc = _documents.value(fileName);
|
||||
if (!doc.isNull()) {
|
||||
const QString &path = doc->path();
|
||||
const Utils::FilePath &path = doc->path();
|
||||
|
||||
QList<Document::Ptr> docs = _documentsByPath.value(path);
|
||||
docs.removeAll(doc);
|
||||
@@ -604,9 +611,9 @@ QmlJS::ImportDependencies *Snapshot::importDependencies()
|
||||
return &_dependencies;
|
||||
}
|
||||
|
||||
Document::MutablePtr Snapshot::documentFromSource(
|
||||
const QString &code, const QString &fileName,
|
||||
Dialect language) const
|
||||
Document::MutablePtr Snapshot::documentFromSource(const QString &code,
|
||||
const Utils::FilePath &fileName,
|
||||
Dialect language) const
|
||||
{
|
||||
Document::MutablePtr newDoc = Document::create(fileName, language);
|
||||
|
||||
@@ -617,24 +624,19 @@ Document::MutablePtr Snapshot::documentFromSource(
|
||||
return newDoc;
|
||||
}
|
||||
|
||||
Document::Ptr Snapshot::document(const QString &fileName) const
|
||||
Document::Ptr Snapshot::document(const Utils::FilePath &fileName) const
|
||||
{
|
||||
return _documents.value(QDir::cleanPath(fileName));
|
||||
return _documents.value(fileName.cleanPath());
|
||||
}
|
||||
|
||||
QList<Document::Ptr> Snapshot::documentsInDirectory(const QString &path) const
|
||||
QList<Document::Ptr> Snapshot::documentsInDirectory(const Utils::FilePath &path) const
|
||||
{
|
||||
return _documentsByPath.value(QDir::cleanPath(path));
|
||||
}
|
||||
|
||||
LibraryInfo Snapshot::libraryInfo(const QString &path) const
|
||||
{
|
||||
return _libraries.value(QDir::cleanPath(path));
|
||||
return _documentsByPath.value(path.cleanPath());
|
||||
}
|
||||
|
||||
LibraryInfo Snapshot::libraryInfo(const Utils::FilePath &path) const
|
||||
{
|
||||
return _libraries.value(path.cleanPath().toString());
|
||||
return _libraries.value(path.cleanPath());
|
||||
}
|
||||
|
||||
void ModuleApiInfo::addToHash(QCryptographicHash &hash) const
|
||||
|
||||
Reference in New Issue
Block a user