aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-08-26 11:30:15 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2021-08-27 11:27:35 +0200
commit831e8f6183b183b9c1d38ef29f8e38f775389549 (patch)
tree5f883bcf18253a297e4f493165966ba22b5131bd
parentaaa0ef458ae09d48dd2eccb55fdcfeebfcbb1e3b (diff)
qmltyperegistrar: Record deferred names in qmltypes
We will need this in order to provide better static analysis of deferred properties. Fixes: QTBUG-96020 Change-Id: I43d8e68f1fd8e5df11195b63c3de948c50888ab4 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/imports/tooling/Component.qml1
-rw-r--r--src/qmltyperegistrar/qmltypesclassdescription.cpp2
-rw-r--r--src/qmltyperegistrar/qmltypesclassdescription.h1
-rw-r--r--src/qmltyperegistrar/qmltypescreator.cpp8
-rw-r--r--tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp6
-rw-r--r--tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h15
6 files changed, 33 insertions, 0 deletions
diff --git a/src/imports/tooling/Component.qml b/src/imports/tooling/Component.qml
index 63e701a0b2..835e5f04ea 100644
--- a/src/imports/tooling/Component.qml
+++ b/src/imports/tooling/Component.qml
@@ -48,6 +48,7 @@ QtObject {
property var exports: []
property var exportMetaObjectRevisions: []
property var interfaces: []
+ property var deferredNames: []
property string attachedType
property string valueType
property string extension
diff --git a/src/qmltyperegistrar/qmltypesclassdescription.cpp b/src/qmltyperegistrar/qmltypesclassdescription.cpp
index bf6c0ca5ed..bcd965013f 100644
--- a/src/qmltyperegistrar/qmltypesclassdescription.cpp
+++ b/src/qmltyperegistrar/qmltypesclassdescription.cpp
@@ -185,6 +185,8 @@ void QmlTypesClassDescription::collect(
} else if (name == QLatin1String("QML.HasCustomParser")) {
if (value == QLatin1String("true"))
hasCustomParser = true;
+ } else if (name == QLatin1String("QML.DeferredPropertyNames")) {
+ deferredNames = value.split(u',');
}
}
diff --git a/src/qmltyperegistrar/qmltypesclassdescription.h b/src/qmltyperegistrar/qmltypesclassdescription.h
index 1e043fb925..dd3c858bbe 100644
--- a/src/qmltyperegistrar/qmltypesclassdescription.h
+++ b/src/qmltyperegistrar/qmltypesclassdescription.h
@@ -56,6 +56,7 @@ struct QmlTypesClassDescription
bool isRootClass = false;
bool hasCustomParser = false;
QStringList implementsInterfaces;
+ QStringList deferredNames;
enum CollectMode {
TopLevel,
diff --git a/src/qmltyperegistrar/qmltypescreator.cpp b/src/qmltyperegistrar/qmltypescreator.cpp
index e0d6ecff35..64906a8589 100644
--- a/src/qmltyperegistrar/qmltypescreator.cpp
+++ b/src/qmltyperegistrar/qmltypescreator.cpp
@@ -119,6 +119,14 @@ void QmlTypesCreator::writeClassProperties(const QmlTypesClassDescription &colle
if (collector.hasCustomParser)
m_qml.writeScriptBinding(QLatin1String("hasCustomParser"), QLatin1String("true"));
+ if (!collector.deferredNames.isEmpty()) {
+ QStringList deferredNames;
+ for (const QString &name : collector.deferredNames)
+ deferredNames << enquote(name);
+
+ m_qml.writeArrayBinding(QLatin1String("deferredNames"), deferredNames);
+ }
+
m_qml.writeArrayBinding(QLatin1String("exportMetaObjectRevisions"), metaObjects);
if (!collector.attachedType.isEmpty())
diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
index 873f1c9ad7..33644b0788 100644
--- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
+++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
@@ -315,4 +315,10 @@ void tst_qmltyperegistrar::namespaceExtendedNamespace()
QCOMPARE(o->property("f").toInt(), int(BaseNamespace::F));
}
+void tst_qmltyperegistrar::deferredNames()
+{
+ QVERIFY(qmltypesData.contains("deferredNames: [\"\"]"));
+ QVERIFY(qmltypesData.contains("deferredNames: [\"A\", \"B\", \"C\"]"));
+}
+
QTEST_MAIN(tst_qmltyperegistrar)
diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h
index d0f3f4d27b..feb8fd2a03 100644
--- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h
+++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h
@@ -402,6 +402,20 @@ public:
Q_ENUM(EEE)
};
+struct DeferredPropertyNamesEmpty : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ Q_CLASSINFO("QML.DeferredPropertyNames", "")
+};
+
+struct DeferredPropertyNames : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ Q_CLASSINFO("QML.DeferredPropertyNames", "A,B,C")
+};
+
namespace ForeignNamespace
{
Q_NAMESPACE
@@ -440,6 +454,7 @@ private slots:
void parentProperty();
void namespacesAndValueTypes();
void namespaceExtendedNamespace();
+ void deferredNames();
private:
QByteArray qmltypesData;