aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-11-11 14:12:55 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-11-12 08:06:34 +0100
commit6a605df673380ffe4e7ee24417175f58ba7972a4 (patch)
tree182471e75532eefba19aede0a2690688db036ee5
parent262d7eb305e1dea8dac660bec3ccc50193258ea9 (diff)
QmlCompiler: Allow more convenient access to enums in QQmlJSScope
Change-Id: Ibac4dd7641a89b686bee63cf974b2257a35631a2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor.cpp2
-rw-r--r--src/qmlcompiler/qqmljsscope.cpp4
-rw-r--r--src/qmlcompiler/qqmljsscope_p.h11
-rw-r--r--src/qmlcompiler/qqmljstypedescriptionreader.cpp2
-rw-r--r--tools/qmllint/checkidentifiers.cpp4
5 files changed, 14 insertions, 9 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp
index d310e2ed9d..b81f7b59a7 100644
--- a/src/qmlcompiler/qqmljsimportvisitor.cpp
+++ b/src/qmlcompiler/qqmljsimportvisitor.cpp
@@ -283,7 +283,7 @@ bool QQmlJSImportVisitor::visit(QQmlJS::AST::UiEnumDeclaration *uied)
QQmlJSMetaEnum qmlEnum(uied->name.toString());
for (const auto *member = uied->members; member; member = member->next)
qmlEnum.addKey(member->member.toString());
- m_currentScope->addEnum(qmlEnum);
+ m_currentScope->addEnumeration(qmlEnum);
return true;
}
diff --git a/src/qmlcompiler/qqmljsscope.cpp b/src/qmlcompiler/qqmljsscope.cpp
index ed029208dc..388de620b0 100644
--- a/src/qmlcompiler/qqmljsscope.cpp
+++ b/src/qmlcompiler/qqmljsscope.cpp
@@ -98,12 +98,12 @@ QQmlJSMetaMethod QQmlJSScope::method(const QString &name) const
bool QQmlJSScope::isIdInCurrentQMlScopes(const QString &id) const
{
if (m_scopeType == QQmlJSScope::QMLScope)
- return m_properties.contains(id) || m_methods.contains(id) || m_enums.contains(id);
+ return m_properties.contains(id) || m_methods.contains(id) || m_enumerations.contains(id);
const auto qmlScope = findCurrentQMLScope(parentScope());
return qmlScope->m_properties.contains(id)
|| qmlScope->m_methods.contains(id)
- || qmlScope->m_enums.contains(id);
+ || qmlScope->m_enumerations.contains(id);
}
bool QQmlJSScope::isIdInCurrentJSScopes(const QString &id) const
diff --git a/src/qmlcompiler/qqmljsscope_p.h b/src/qmlcompiler/qqmljsscope_p.h
index 24e401fa0a..0513612e42 100644
--- a/src/qmlcompiler/qqmljsscope_p.h
+++ b/src/qmlcompiler/qqmljsscope_p.h
@@ -166,8 +166,13 @@ public:
bool hasMethod(const QString &name) const;
QQmlJSMetaMethod method(const QString &name) const;
- void addEnum(const QQmlJSMetaEnum &fakeEnum) { m_enums.insert(fakeEnum.name(), fakeEnum); }
- QHash<QString, QQmlJSMetaEnum> enums() const { return m_enums; }
+ void addEnumeration(const QQmlJSMetaEnum &enumeration)
+ {
+ m_enumerations.insert(enumeration.name(), enumeration);
+ }
+ QHash<QString, QQmlJSMetaEnum> enumerations() const { return m_enumerations; }
+ QQmlJSMetaEnum enumeration(const QString &name) const { return m_enumerations.value(name); }
+ bool hasEnumeration(const QString &name) const { return m_enumerations.contains(name); }
QString fileName() const { return m_fileName; }
void setFileName(const QString &file) { m_fileName = file; }
@@ -246,7 +251,7 @@ private:
QMultiHash<QString, QQmlJSMetaMethod> m_methods;
QHash<QString, QQmlJSMetaProperty> m_properties;
- QHash<QString, QQmlJSMetaEnum> m_enums;
+ QHash<QString, QQmlJSMetaEnum> m_enumerations;
QVector<QQmlJSScope::Ptr> m_childScopes;
QQmlJSScope::WeakPtr m_parentScope;
diff --git a/src/qmlcompiler/qqmljstypedescriptionreader.cpp b/src/qmlcompiler/qqmljstypedescriptionreader.cpp
index fd875dd715..0a5c97c3db 100644
--- a/src/qmlcompiler/qqmljstypedescriptionreader.cpp
+++ b/src/qmlcompiler/qqmljstypedescriptionreader.cpp
@@ -386,7 +386,7 @@ void QQmlJSTypeDescriptionReader::readEnum(UiObjectDefinition *ast, const QQmlJS
}
}
- scope->addEnum(metaEnum);
+ scope->addEnumeration(metaEnum);
}
void QQmlJSTypeDescriptionReader::readParameter(UiObjectDefinition *ast, QQmlJSMetaMethod *metaMethod)
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp
index 86ac84fcf1..6500595c83 100644
--- a/tools/qmllint/checkidentifiers.cpp
+++ b/tools/qmllint/checkidentifiers.cpp
@@ -197,7 +197,7 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<FieldMember> &members,
return true; // Access to property of JS function
auto checkEnums = [&](const QQmlJSScope::ConstPtr &scope) {
- const auto enums = scope->enums();
+ const auto enums = scope->enumerations();
for (const auto &enumerator : enums) {
if (enumerator.name() == access.m_name) {
detectedRestrictiveKind = QLatin1String("enum");
@@ -373,7 +373,7 @@ bool CheckIdentifiers::operator()(
const auto firstElement = root->childScopes()[0];
if (firstElement->hasProperty(memberAccessBase.m_name)
|| firstElement->hasMethod(memberAccessBase.m_name)
- || firstElement->enums().contains(memberAccessBase.m_name)) {
+ || firstElement->enumerations().contains(memberAccessBase.m_name)) {
m_colorOut->writePrefixedMessage(
memberAccessBase.m_name
+ QLatin1String(" is a member of the root element\n")