diff --git a/src/libs/qmljs/qmljsbind.cpp b/src/libs/qmljs/qmljsbind.cpp index dba6cbe0aca870569283ee05769dd0e01cfef123..40333e9fb3d3bd0b5d8ac77576aa42826100cd24 100644 --- a/src/libs/qmljs/qmljsbind.cpp +++ b/src/libs/qmljs/qmljsbind.cpp @@ -54,14 +54,14 @@ Bind::~Bind() { } -QStringList Bind::includedScripts() const +QStringList Bind::fileImports() const { - return _includedScripts; + return _fileImports; } -QStringList Bind::fileImports() const +QStringList Bind::directoryImports() const { - return _fileImports; + return _directoryImports; } QStringList Bind::libraryImports() const @@ -142,47 +142,11 @@ ExpressionNode *Bind::expression(UiScriptBinding *ast) const return 0; } -void Bind::processScript(AST::UiQualifiedId *qualifiedId, AST::UiObjectInitializer *initializer) -{ - Q_UNUSED(qualifiedId); - - if (! initializer) - return; - - for (UiObjectMemberList *it = initializer->members; it; it = it->next) { - if (UiScriptBinding *binding = cast<UiScriptBinding *>(it->member)) { - const QString bindingName = toString(binding->qualifiedId); - if (bindingName == QLatin1String("source")) { - if (StringLiteral *literal = cast<StringLiteral *>(expression(binding))) { - QFileInfo fileInfo(QDir(_doc->path()), literal->value->asString()); - const QString scriptPath = fileInfo.absoluteFilePath(); - _includedScripts.append(scriptPath); - } - } - } else if (UiSourceElement *binding = cast<UiSourceElement *>(it->member)) { - if (FunctionDeclaration *decl = cast<FunctionDeclaration *>(binding->sourceElement)) { - accept(decl); // process the function declaration - } else { - // ### unexpected source element - } - } else { - // ### unexpected binding. - } - } -} - ObjectValue *Bind::bindObject(UiQualifiedId *qualifiedTypeNameId, UiObjectInitializer *initializer) { ObjectValue *parentObjectValue = 0; const QString typeName = toString(qualifiedTypeNameId); - if (typeName == QLatin1String("Script")) { - // Script blocks all contribute to the same scope - parentObjectValue = switchObjectValue(_functionEnvironment); - processScript(qualifiedTypeNameId, initializer); - switchObjectValue(parentObjectValue); - } - // normal component instance ASTObjectValue *objectValue = new ASTObjectValue(qualifiedTypeNameId, initializer, _doc, &_engine); QmlPrototypeReference *prototypeReference = @@ -225,7 +189,13 @@ bool Bind::visit(UiImport *ast) if (ast->importUri) { _libraryImports += toString(ast->importUri, QLatin1Char('/')); } else if (ast->fileName) { - _fileImports += ast->fileName->asString(); + const QFileInfo importFileInfo(_doc->path() + QLatin1Char('/') + ast->fileName->asString()); + if (importFileInfo.isFile()) + _fileImports += importFileInfo.absoluteFilePath(); + else if (importFileInfo.isDir()) + _directoryImports += importFileInfo.absoluteFilePath(); + //else + // error: file or directory does not exist } return false; diff --git a/src/libs/qmljs/qmljsbind.h b/src/libs/qmljs/qmljsbind.h index a74d8c92ccd4df2deaad644ed543fa799458f130..bb1a77f5269fadf550b7173f143b500006b19799 100644 --- a/src/libs/qmljs/qmljsbind.h +++ b/src/libs/qmljs/qmljsbind.h @@ -50,8 +50,8 @@ public: Bind(Document *doc); virtual ~Bind(); - QStringList includedScripts() const; QStringList fileImports() const; + QStringList directoryImports() const; QStringList libraryImports() const; Interpreter::ObjectValue *currentObjectValue() const; @@ -91,7 +91,6 @@ protected: Interpreter::ObjectValue *bindObject(AST::UiQualifiedId *qualifiedTypeNameId, AST::UiObjectInitializer *initializer); AST::ExpressionNode *expression(AST::UiScriptBinding *ast) const; - void processScript(AST::UiQualifiedId *qualifiedId, AST::UiObjectInitializer *initializer); private: Document *_doc; @@ -107,6 +106,7 @@ private: QStringList _includedScripts; QStringList _fileImports; + QStringList _directoryImports; QStringList _libraryImports; }; diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp index 2961063aab8a067b7351574067eb14ec1752b63e..6efea8b6f024343211b24be51be186838751429b 100644 --- a/src/libs/qmljs/qmljslink.cpp +++ b/src/libs/qmljs/qmljslink.cpp @@ -64,14 +64,15 @@ void Link::initializeScopeChain() if (const ObjectValue *typeEnvironment = _context->typeEnvironment(_doc.data())) scopeChain.qmlTypes = typeEnvironment; } else { - // add scope chains for all components that source this document - // ### TODO: This needs updates for the new way of importing scripts + // add scope chains for all components that import this file foreach (Document::Ptr otherDoc, _snapshot) { - if (otherDoc->bind()->includedScripts().contains(_doc->fileName())) { - ScopeChain::QmlComponentChain *component = new ScopeChain::QmlComponentChain; - componentScopes.insert(otherDoc.data(), component); - scopeChain.qmlComponentScope.instantiatingComponents += component; - makeComponentChain(otherDoc, component, &componentScopes); + foreach (const QString &fileImport, otherDoc->bind()->fileImports()) { + if (_doc->fileName() == fileImport) { + ScopeChain::QmlComponentChain *component = new ScopeChain::QmlComponentChain; + componentScopes.insert(otherDoc.data(), component); + scopeChain.qmlComponentScope.instantiatingComponents += component; + makeComponentChain(otherDoc, component, &componentScopes); + } } } @@ -114,16 +115,6 @@ void Link::makeComponentChain( if (bind->rootObjectValue()) target->rootObject = bind->rootObjectValue(); - const QStringList &includedScripts = bind->includedScripts(); - for (int index = includedScripts.size() - 1; index != -1; --index) { - const QString &scriptFile = includedScripts.at(index); - - if (Document::Ptr scriptDoc = _snapshot.document(scriptFile)) { - if (scriptDoc->jsProgram()) - target->functionScopes += scriptDoc->bind()->rootObjectValue(); - } - } - target->functionScopes += bind->functionEnvironment(); target->ids = bind->idEnvironment(); } diff --git a/src/plugins/qmljseditor/qmljsmodelmanager.cpp b/src/plugins/qmljseditor/qmljsmodelmanager.cpp index d949424c5c9bc0a515f17caf4ad641ee67864c7d..a253c99530b4b4dc93d871c62a75966fe0cdf772 100644 --- a/src/plugins/qmljseditor/qmljsmodelmanager.cpp +++ b/src/plugins/qmljseditor/qmljsmodelmanager.cpp @@ -227,17 +227,14 @@ static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapsho { // scan files and directories that are explicitly imported foreach (const QString &fileImport, doc->bind()->fileImports()) { - const QFileInfo importFileInfo(doc->path() + QLatin1Char('/') + fileImport); - const QString &importFilePath = importFileInfo.absoluteFilePath(); - if (importFileInfo.isFile()) { - if (! snapshot.document(importFilePath)) - *importedFiles += importFilePath; - } else if (importFileInfo.isDir()) { - if (snapshot.documentsInDirectory(importFilePath).isEmpty()) { - if (! scannedPaths->contains(importFilePath)) { - *importedFiles += qmlFilesInDirectory(importFilePath); - scannedPaths->insert(importFilePath); - } + if (! snapshot.document(fileImport)) + *importedFiles += fileImport; + } + foreach (const QString &directoryImport, doc->bind()->directoryImports()) { + if (snapshot.documentsInDirectory(directoryImport).isEmpty()) { + if (! scannedPaths->contains(directoryImport)) { + *importedFiles += qmlFilesInDirectory(directoryImport); + scannedPaths->insert(directoryImport); } } }