forked from qt-creator/qt-creator
QmlJS: Collect import version numbers in Bind.
This commit is contained in:
@@ -53,17 +53,17 @@ Bind::~Bind()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Bind::fileImports() const
|
QList<Bind::ImportInfo> Bind::fileImports() const
|
||||||
{
|
{
|
||||||
return _fileImports;
|
return _fileImports;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Bind::directoryImports() const
|
QList<Bind::ImportInfo> Bind::directoryImports() const
|
||||||
{
|
{
|
||||||
return _directoryImports;
|
return _directoryImports;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Bind::libraryImports() const
|
QList<Bind::ImportInfo> Bind::libraryImports() const
|
||||||
{
|
{
|
||||||
return _libraryImports;
|
return _libraryImports;
|
||||||
}
|
}
|
||||||
@@ -185,14 +185,30 @@ bool Bind::visit(AST::Program *)
|
|||||||
|
|
||||||
bool Bind::visit(UiImport *ast)
|
bool Bind::visit(UiImport *ast)
|
||||||
{
|
{
|
||||||
|
ImportInfo info;
|
||||||
|
|
||||||
|
info.majorVersion = QmlObjectValue::NoVersion;
|
||||||
|
info.minorVersion = QmlObjectValue::NoVersion;
|
||||||
|
|
||||||
|
if (ast->versionToken.isValid()) {
|
||||||
|
const QString versionString = _doc->source().mid(ast->versionToken.offset, ast->versionToken.length);
|
||||||
|
const int dotIdx = versionString.indexOf(QLatin1Char('.'));
|
||||||
|
if (dotIdx != -1) {
|
||||||
|
info.majorVersion = versionString.left(dotIdx).toInt();
|
||||||
|
info.minorVersion = versionString.mid(dotIdx + 1).toInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ast->importUri) {
|
if (ast->importUri) {
|
||||||
_libraryImports += toString(ast->importUri, QLatin1Char('/'));
|
info.name = toString(ast->importUri, QLatin1Char('/'));
|
||||||
|
_libraryImports += info;
|
||||||
} else if (ast->fileName) {
|
} else if (ast->fileName) {
|
||||||
const QFileInfo importFileInfo(_doc->path() + QLatin1Char('/') + ast->fileName->asString());
|
const QFileInfo importFileInfo(_doc->path() + QLatin1Char('/') + ast->fileName->asString());
|
||||||
|
info.name = importFileInfo.absoluteFilePath();
|
||||||
if (importFileInfo.isFile())
|
if (importFileInfo.isFile())
|
||||||
_fileImports += importFileInfo.absoluteFilePath();
|
_fileImports += info;
|
||||||
else if (importFileInfo.isDir())
|
else if (importFileInfo.isDir())
|
||||||
_directoryImports += importFileInfo.absoluteFilePath();
|
_directoryImports += info;
|
||||||
//else
|
//else
|
||||||
// error: file or directory does not exist
|
// error: file or directory does not exist
|
||||||
}
|
}
|
||||||
|
@@ -50,9 +50,15 @@ public:
|
|||||||
Bind(Document *doc);
|
Bind(Document *doc);
|
||||||
virtual ~Bind();
|
virtual ~Bind();
|
||||||
|
|
||||||
QStringList fileImports() const;
|
struct ImportInfo {
|
||||||
QStringList directoryImports() const;
|
QString name;
|
||||||
QStringList libraryImports() const;
|
int majorVersion;
|
||||||
|
int minorVersion;
|
||||||
|
};
|
||||||
|
|
||||||
|
QList<ImportInfo> fileImports() const;
|
||||||
|
QList<ImportInfo> directoryImports() const;
|
||||||
|
QList<ImportInfo> libraryImports() const;
|
||||||
|
|
||||||
Interpreter::ObjectValue *currentObjectValue() const;
|
Interpreter::ObjectValue *currentObjectValue() const;
|
||||||
Interpreter::ObjectValue *idEnvironment() const;
|
Interpreter::ObjectValue *idEnvironment() const;
|
||||||
@@ -105,9 +111,9 @@ private:
|
|||||||
QHash<AST::FunctionDeclaration *, Interpreter::ObjectValue *> _functionScopes;
|
QHash<AST::FunctionDeclaration *, Interpreter::ObjectValue *> _functionScopes;
|
||||||
QStringList _includedScripts;
|
QStringList _includedScripts;
|
||||||
|
|
||||||
QStringList _fileImports;
|
QList<ImportInfo> _fileImports;
|
||||||
QStringList _directoryImports;
|
QList<ImportInfo> _directoryImports;
|
||||||
QStringList _libraryImports;
|
QList<ImportInfo> _libraryImports;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace Qml
|
} // end of namespace Qml
|
||||||
|
@@ -65,8 +65,8 @@ void Link::initializeScopeChain()
|
|||||||
} else {
|
} else {
|
||||||
// add scope chains for all components that import this file
|
// add scope chains for all components that import this file
|
||||||
foreach (Document::Ptr otherDoc, _snapshot) {
|
foreach (Document::Ptr otherDoc, _snapshot) {
|
||||||
foreach (const QString &fileImport, otherDoc->bind()->fileImports()) {
|
foreach (const Bind::ImportInfo &fileImport, otherDoc->bind()->fileImports()) {
|
||||||
if (_doc->fileName() == fileImport) {
|
if (_doc->fileName() == fileImport.name) {
|
||||||
ScopeChain::QmlComponentChain *component = new ScopeChain::QmlComponentChain;
|
ScopeChain::QmlComponentChain *component = new ScopeChain::QmlComponentChain;
|
||||||
componentScopes.insert(otherDoc.data(), component);
|
componentScopes.insert(otherDoc.data(), component);
|
||||||
scopeChain.qmlComponentScope.instantiatingComponents += component;
|
scopeChain.qmlComponentScope.instantiatingComponents += component;
|
||||||
|
@@ -236,15 +236,15 @@ static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapsho
|
|||||||
QStringList *importedFiles, QSet<QString> *scannedPaths)
|
QStringList *importedFiles, QSet<QString> *scannedPaths)
|
||||||
{
|
{
|
||||||
// scan files and directories that are explicitly imported
|
// scan files and directories that are explicitly imported
|
||||||
foreach (const QString &fileImport, doc->bind()->fileImports()) {
|
foreach (const Bind::ImportInfo &fileImport, doc->bind()->fileImports()) {
|
||||||
if (! snapshot.document(fileImport))
|
if (! snapshot.document(fileImport.name))
|
||||||
*importedFiles += fileImport;
|
*importedFiles += fileImport.name;
|
||||||
}
|
}
|
||||||
foreach (const QString &directoryImport, doc->bind()->directoryImports()) {
|
foreach (const Bind::ImportInfo &directoryImport, doc->bind()->directoryImports()) {
|
||||||
if (snapshot.documentsInDirectory(directoryImport).isEmpty()) {
|
if (snapshot.documentsInDirectory(directoryImport.name).isEmpty()) {
|
||||||
if (! scannedPaths->contains(directoryImport)) {
|
if (! scannedPaths->contains(directoryImport.name)) {
|
||||||
*importedFiles += qmlFilesInDirectory(directoryImport);
|
*importedFiles += qmlFilesInDirectory(directoryImport.name);
|
||||||
scannedPaths->insert(directoryImport);
|
scannedPaths->insert(directoryImport.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,10 +256,10 @@ static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snap
|
|||||||
{
|
{
|
||||||
// scan library imports
|
// scan library imports
|
||||||
const QStringList importPaths = modelManager->importPaths();
|
const QStringList importPaths = modelManager->importPaths();
|
||||||
foreach (const QString &libraryImport, doc->bind()->libraryImports()) {
|
foreach (const Bind::ImportInfo &libraryImport, doc->bind()->libraryImports()) {
|
||||||
foreach (const QString &importPath, importPaths) {
|
foreach (const QString &importPath, importPaths) {
|
||||||
QDir dir(importPath);
|
QDir dir(importPath);
|
||||||
dir.cd(libraryImport);
|
dir.cd(libraryImport.name);
|
||||||
const QString targetPath = dir.absolutePath();
|
const QString targetPath = dir.absolutePath();
|
||||||
|
|
||||||
// if we know there is a library, done
|
// if we know there is a library, done
|
||||||
|
Reference in New Issue
Block a user