aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/language
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@theqtcompany.com>2015-08-04 12:59:20 +0200
committerChristian Kandeler <christian.kandeler@theqtcompany.com>2015-08-04 12:55:58 +0000
commit6cc4b9d6af6ed169cdb05a3925e50d353ab8c8a9 (patch)
tree90bb89a0c5e12e601ae339e10ef39c532dfbed44 /src/lib/corelib/language
parent4d74073d1a16fdd8479a85f3ba0d297fb4a7c318 (diff)
Allow importing JS collections also via the file name syntax.
The form "import MyCollection" was supported, the form "import 'mycollection' was not. That does not make any sense. Change-Id: Id57b6749300bfa21cd1afcbc58d234e5c67a963d Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'src/lib/corelib/language')
-rw-r--r--src/lib/corelib/language/itemreaderastvisitor.cpp36
-rw-r--r--src/lib/corelib/language/itemreaderastvisitor.h6
-rw-r--r--src/lib/corelib/language/testdata/import-collection/collection/file1.js1
-rw-r--r--src/lib/corelib/language/testdata/import-collection/collection/file2.js1
-rw-r--r--src/lib/corelib/language/testdata/import-collection/imports/Collection/file1.js2
-rw-r--r--src/lib/corelib/language/testdata/import-collection/imports/Collection/file2.js2
-rw-r--r--src/lib/corelib/language/testdata/import-collection/product.qbs5
-rw-r--r--src/lib/corelib/language/tst_language.cpp3
8 files changed, 37 insertions, 19 deletions
diff --git a/src/lib/corelib/language/itemreaderastvisitor.cpp b/src/lib/corelib/language/itemreaderastvisitor.cpp
index 712008d96..0fc4696c8 100644
--- a/src/lib/corelib/language/itemreaderastvisitor.cpp
+++ b/src/lib/corelib/language/itemreaderastvisitor.cpp
@@ -129,6 +129,23 @@ void ItemReaderASTVisitor::collectPrototypes(const QString &path, const QString
m_visitorState.cacheDirectoryEntries(path, fileNames);
}
+
+void ItemReaderASTVisitor::collectPrototypesAndJsCollections(const QString &path,
+ const QString &as, const CodeLocation &location, JsImportsHash &jsImports)
+{
+ collectPrototypes(path, as);
+ QDirIterator dirIter(path, QStringList(QLatin1String("*.js")));
+ while (dirIter.hasNext()) {
+ dirIter.next();
+ JsImport &jsImport = jsImports[as];
+ if (jsImport.scopeName.isNull()) {
+ jsImport.scopeName = as;
+ jsImport.location = location;
+ }
+ jsImport.filePaths.append(dirIter.filePath());
+ }
+}
+
bool ItemReaderASTVisitor::visit(AST::UiImportList *uiImportList)
{
foreach (const QString &searchPath, m_searchPaths)
@@ -140,7 +157,7 @@ bool ItemReaderASTVisitor::visit(AST::UiImportList *uiImportList)
collectPrototypes(path, QString());
QSet<QString> importAsNames;
- QHash<QString, JsImport> jsImports;
+ JsImportsHash jsImports;
for (const AST::UiImportList *it = uiImportList; it; it = it->next) {
const AST::UiImport *const import = it->import;
@@ -218,7 +235,8 @@ bool ItemReaderASTVisitor::visit(AST::UiImportList *uiImportList)
import->fileNameToken.startColumn));
filePath = fi.canonicalFilePath();
if (fi.isDir()) {
- collectPrototypes(filePath, as);
+ collectPrototypesAndJsCollections(filePath, as,
+ toCodeLocation(import->fileNameToken), jsImports);
} else {
if (filePath.endsWith(QLatin1String(".js"), Qt::CaseInsensitive)) {
JsImport &jsImport = jsImports[as];
@@ -246,18 +264,8 @@ bool ItemReaderASTVisitor::visit(AST::UiImportList *uiImportList)
if (fi.isDir()) {
// ### versioning, qbsdir file, etc.
const QString &resultPath = fi.absoluteFilePath();
- collectPrototypes(resultPath, as);
-
- QDirIterator dirIter(resultPath, QStringList(QLatin1String("*.js")));
- while (dirIter.hasNext()) {
- dirIter.next();
- JsImport &jsImport = jsImports[as];
- if (jsImport.scopeName.isNull()) {
- jsImport.scopeName = as;
- jsImport.location = toCodeLocation(import->firstSourceLocation());
- }
- jsImport.filePaths.append(dirIter.filePath());
- }
+ collectPrototypesAndJsCollections(resultPath, as,
+ toCodeLocation(import->importIdToken), jsImports);
found = true;
break;
}
diff --git a/src/lib/corelib/language/itemreaderastvisitor.h b/src/lib/corelib/language/itemreaderastvisitor.h
index cf85b852f..68c18c749 100644
--- a/src/lib/corelib/language/itemreaderastvisitor.h
+++ b/src/lib/corelib/language/itemreaderastvisitor.h
@@ -45,6 +45,7 @@ namespace Internal {
class Item;
class ItemPool;
class ItemReaderVisitorState;
+class JsImport;
class Version;
class ItemReaderASTVisitor : public QbsQmlJS::AST::Visitor
@@ -81,6 +82,11 @@ private:
static void replaceConditionScopes(const JSSourceValuePtr &value, Item *newScope);
void handlePropertiesBlock(Item *item, const Item *block);
void collectPrototypes(const QString &path, const QString &as);
+
+ using JsImportsHash = QHash<QString, JsImport>;
+ void collectPrototypesAndJsCollections(const QString &path, const QString &as,
+ const CodeLocation &location, JsImportsHash &jsImports);
+
bool addPrototype(const QString &fileName, const QString &filePath, const QString &as,
bool needsCheck);
diff --git a/src/lib/corelib/language/testdata/import-collection/collection/file1.js b/src/lib/corelib/language/testdata/import-collection/collection/file1.js
new file mode 100644
index 000000000..09c5cc75a
--- /dev/null
+++ b/src/lib/corelib/language/testdata/import-collection/collection/file1.js
@@ -0,0 +1 @@
+function f1() { return "C2f1"; }
diff --git a/src/lib/corelib/language/testdata/import-collection/collection/file2.js b/src/lib/corelib/language/testdata/import-collection/collection/file2.js
new file mode 100644
index 000000000..ecc0f7c63
--- /dev/null
+++ b/src/lib/corelib/language/testdata/import-collection/collection/file2.js
@@ -0,0 +1 @@
+function f2() { return "C2f2"; }
diff --git a/src/lib/corelib/language/testdata/import-collection/imports/Collection/file1.js b/src/lib/corelib/language/testdata/import-collection/imports/Collection/file1.js
index 9f4785b2e..d305c5284 100644
--- a/src/lib/corelib/language/testdata/import-collection/imports/Collection/file1.js
+++ b/src/lib/corelib/language/testdata/import-collection/imports/Collection/file1.js
@@ -1 +1 @@
-function f1() { return "f1"; }
+function f1() { return "C1f1"; }
diff --git a/src/lib/corelib/language/testdata/import-collection/imports/Collection/file2.js b/src/lib/corelib/language/testdata/import-collection/imports/Collection/file2.js
index 887fd6fdb..b35168227 100644
--- a/src/lib/corelib/language/testdata/import-collection/imports/Collection/file2.js
+++ b/src/lib/corelib/language/testdata/import-collection/imports/Collection/file2.js
@@ -1 +1 @@
-function f2() { return "f2"; }
+function f2() { return "C1f2"; }
diff --git a/src/lib/corelib/language/testdata/import-collection/product.qbs b/src/lib/corelib/language/testdata/import-collection/product.qbs
index af240ddca..0682fcfab 100644
--- a/src/lib/corelib/language/testdata/import-collection/product.qbs
+++ b/src/lib/corelib/language/testdata/import-collection/product.qbs
@@ -1,6 +1,7 @@
-import Collection
+import Collection as Collection1
+import "collection" as Collection2
Product {
name: "da product"
- targetName: Collection.f1() + Collection.f2()
+ targetName: Collection1.f1() + Collection1.f2() + Collection2.f1() + Collection2.f2()
}
diff --git a/src/lib/corelib/language/tst_language.cpp b/src/lib/corelib/language/tst_language.cpp
index b13404ad4..c227f1b83 100644
--- a/src/lib/corelib/language/tst_language.cpp
+++ b/src/lib/corelib/language/tst_language.cpp
@@ -814,7 +814,8 @@ void TestLanguage::importCollection()
QVERIFY(project);
QHash<QString, ResolvedProductPtr> products = productsFromProject(project);
const ResolvedProductConstPtr product = products.value("da product");
- QCOMPARE(product->productProperties.value("targetName").toString(), QLatin1String("f1f2"));
+ QCOMPARE(product->productProperties.value("targetName").toString(),
+ QLatin1String("C1f1C1f2C2f1C2f2"));
}
catch (const ErrorInfo &e) {
exceptionCaught = true;