diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-22 11:27:54 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-22 13:11:49 +0200 |
commit | 328759cdeb7b45eba5569b54ded35e38152ee0d0 (patch) | |
tree | feac5f52693441217836ff42d379aa6b7c3869bb /src/qmlcompiler/qqmljsscope.cpp | |
parent | c0063f73e5472f770133602ea2a7c6fe77f5a1b3 (diff) |
QmlCompiler: Properly discern between inherited and own names
Previously, we would mix them up on importExportedNames(), which was
also misnamed. Now we keep them in their proper place in the scope
hierarchy, so that we can identify which scope a property came from.
Exceptions are the qmllint-specific treatment of parent properties and
Connections elements.
Change-Id: I7c012388b16c83439d6f2de2e83fac0da4940d30
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsscope.cpp')
-rw-r--r-- | src/qmlcompiler/qqmljsscope.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljsscope.cpp b/src/qmlcompiler/qqmljsscope.cpp index ba74280ae2..bea6c29932 100644 --- a/src/qmlcompiler/qqmljsscope.cpp +++ b/src/qmlcompiler/qqmljsscope.cpp @@ -66,9 +66,9 @@ void QQmlJSScope::insertJSIdentifier(const QString &name, const JavaScriptIdenti void QQmlJSScope::insertPropertyIdentifier(const QQmlJSMetaProperty &property) { - addProperty(property); + addOwnProperty(property); QQmlJSMetaMethod method(property.propertyName() + QLatin1String("Changed"), QLatin1String("void")); - addMethod(method); + addOwnMethod(method); } bool QQmlJSScope::isIdInCurrentScope(const QString &id) const @@ -76,6 +76,25 @@ bool QQmlJSScope::isIdInCurrentScope(const QString &id) const return isIdInCurrentQMlScopes(id) || isIdInCurrentJSScopes(id); } +bool QQmlJSScope::hasMethod(const QString &name) const +{ + for (const QQmlJSScope *scope = this; scope; scope = scope->baseType().data()) { + if (scope->m_methods.contains(name)) + return true; + } + return false; +} + +QQmlJSMetaMethod QQmlJSScope::method(const QString &name) const +{ + for (const QQmlJSScope *scope = this; scope; scope = scope->baseType().data()) { + const auto it = scope->m_methods.find(name); + if (it != scope->m_methods.end()) + return *it; + } + return {}; +} + bool QQmlJSScope::isIdInCurrentQMlScopes(const QString &id) const { if (m_scopeType == QQmlJSScope::QMLScope) @@ -163,6 +182,25 @@ void QQmlJSScope::addExport(const QString &name, const QString &package, m_exports.append(Export(package, name, version)); } +bool QQmlJSScope::hasProperty(const QString &name) const +{ + for (const QQmlJSScope *scope = this; scope; scope = scope->baseType().data()) { + if (scope->m_properties.contains(name)) + return true; + } + return false; +} + +QQmlJSMetaProperty QQmlJSScope::property(const QString &name) const +{ + for (const QQmlJSScope *scope = this; scope; scope = scope->baseType().data()) { + const auto it = scope->m_properties.find(name); + if (it != scope->m_properties.end()) + return *it; + } + return {}; +} + QQmlJSScope::Export::Export(QString package, QString type, const QTypeRevision &version) : m_package(std::move(package)), m_type(std::move(type)), |