aboutsummaryrefslogtreecommitdiffstats
path: root/tools/shared
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-09-25 16:14:53 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-09-28 13:26:52 +0200
commit4cd06638c198c7ed48680c63e9df943e3680e89e (patch)
tree1c4213b905d02646dbbd0c4ec006791b30aeac20 /tools/shared
parent9e2f4e112776149be550dbea6003a192cd931538 (diff)
qmllint: Make imports local
Imports are not transitive. qmllint gets this wrong so far. Fixing it reveals two tests where we use types we haven't imported. Import the relevant modules. Change-Id: I45f3229468d54137f97d6b699f3a98a1349bc412 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/shared')
-rw-r--r--tools/shared/scopetree.cpp27
-rw-r--r--tools/shared/scopetree.h4
2 files changed, 31 insertions, 0 deletions
diff --git a/tools/shared/scopetree.cpp b/tools/shared/scopetree.cpp
index 4d02c67491..2ae2dfe054 100644
--- a/tools/shared/scopetree.cpp
+++ b/tools/shared/scopetree.cpp
@@ -144,6 +144,33 @@ bool ScopeTree::isIdInjectedFromSignal(const QString &id) const
return findCurrentQMLScope(parentScope())->m_injectedSignalIdentifiers.contains(id);
}
+void ScopeTree::resolveTypes(const QHash<QString, ScopeTree::Ptr> &contextualTypes)
+{
+ auto findType = [&](const QString &name) {
+ auto type = contextualTypes.constFind(name);
+ if (type != contextualTypes.constEnd())
+ return *type;
+
+ return ScopeTree::Ptr();
+ };
+
+ m_baseType = findType(m_baseTypeName);
+
+ for (auto it = m_properties.begin(), end = m_properties.end(); it != end; ++it)
+ it->setType(findType(it->typeName()));
+
+ for (auto it = m_methods.begin(), end = m_methods.end(); it != end; ++it) {
+ it->setReturnType(findType(it->returnTypeName()));
+ const auto paramNames = it->parameterTypeNames();
+ QList<ScopeTree::ConstPtr> paramTypes;
+
+ for (const QString &paramName: paramNames)
+ paramTypes.append(findType(paramName));
+
+ it->setParameterTypes(paramTypes);
+ }
+}
+
ScopeTree::ConstPtr ScopeTree::findCurrentQMLScope(const ScopeTree::ConstPtr &scope)
{
auto qmlScope = scope;
diff --git a/tools/shared/scopetree.h b/tools/shared/scopetree.h
index 9c16f6b05f..ecb9646db2 100644
--- a/tools/shared/scopetree.h
+++ b/tools/shared/scopetree.h
@@ -155,6 +155,7 @@ public:
// relevant base class (in the hierarchy starting from QObject) of a C++ type.
void setBaseTypeName(const QString &baseTypeName) { m_baseTypeName = baseTypeName; }
QString baseTypeName() const { return m_baseTypeName; }
+ ScopeTree::ConstPtr baseType() const { return m_baseType; }
void addProperty(const MetaProperty &prop) { m_properties.insert(prop.propertyName(), prop); }
QHash<QString, MetaProperty> properties() const { return m_properties; }
@@ -207,6 +208,8 @@ public:
return m_injectedSignalIdentifiers;
}
+ void resolveTypes(const QHash<QString, ScopeTree::Ptr> &contextualTypes);
+
private:
ScopeTree(ScopeType type, const ScopeTree::Ptr &parentScope = ScopeTree::Ptr());
@@ -226,6 +229,7 @@ private:
QString m_fileName;
QString m_internalName;
QString m_baseTypeName;
+ ScopeTree::WeakPtr m_baseType;
ScopeType m_scopeType = ScopeType::QMLScope;
QList<Export> m_exports;