2021-06-29 11:19:21 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
**
|
|
|
|
** This file is part of the tools applications of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "qqmljsregistercontent_p.h"
|
|
|
|
#include "qqmljstyperesolver_p.h"
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
QString QQmlJSRegisterContent::descriptiveName() const
|
|
|
|
{
|
2022-04-06 09:52:25 +00:00
|
|
|
if (m_storedType.isNull())
|
|
|
|
return u"(invalid type)"_qs;
|
|
|
|
|
2021-06-29 11:19:21 +00:00
|
|
|
QString result = m_storedType->internalName() + u" of "_qs;
|
|
|
|
const auto scope = [this]() -> QString {
|
2022-04-06 09:52:25 +00:00
|
|
|
if (m_scope.isNull())
|
|
|
|
return u"(invalid type)::"_qs;
|
2021-06-29 11:19:21 +00:00
|
|
|
return (m_scope->internalName().isEmpty()
|
2022-02-24 09:37:01 +00:00
|
|
|
? (m_scope->filePath().isEmpty()
|
2021-06-29 11:19:21 +00:00
|
|
|
? u"??"_qs
|
2022-02-24 09:37:01 +00:00
|
|
|
: (u"(component in "_qs + m_scope->filePath() + u")"_qs))
|
2021-06-29 11:19:21 +00:00
|
|
|
: m_scope->internalName())
|
|
|
|
+ u"::"_qs;
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (m_content.index()) {
|
|
|
|
case Type:
|
|
|
|
return result + std::get<QQmlJSScope::ConstPtr>(m_content)->internalName();
|
|
|
|
case Property: {
|
|
|
|
const QQmlJSMetaProperty prop = std::get<QQmlJSMetaProperty>(m_content);
|
|
|
|
return result + scope() + prop.propertyName() + u" with type "_qs + prop.typeName();
|
|
|
|
}
|
|
|
|
case Method: {
|
|
|
|
const auto methods = std::get<QList<QQmlJSMetaMethod>>(m_content);
|
|
|
|
if (methods.isEmpty())
|
|
|
|
return result + scope() + u"(unknown method)"_qs;
|
|
|
|
else
|
|
|
|
return result + scope() + methods[0].methodName() + u"(...)"_qs;
|
|
|
|
}
|
|
|
|
case Enum: {
|
|
|
|
const auto e = std::get<std::pair<QQmlJSMetaEnum, QString>>(m_content);
|
|
|
|
if (e.second.isEmpty())
|
|
|
|
return result + scope() + e.first.name();
|
|
|
|
else
|
|
|
|
return result + scope() + e.first.name() + u"::"_qs + e.second;
|
|
|
|
}
|
2021-08-16 06:53:39 +00:00
|
|
|
case ImportNamespace: {
|
|
|
|
return u"import namespace %1"_qs.arg(std::get<uint>(m_content));
|
|
|
|
}
|
2022-02-04 20:46:07 +00:00
|
|
|
case Conversion: {
|
|
|
|
return u"conversion to %1"_qs.arg(
|
|
|
|
std::get<ConvertedTypes>(m_content).result->internalName());
|
|
|
|
}
|
2021-06-29 11:19:21 +00:00
|
|
|
}
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
return result + u"wat?"_qs;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QQmlJSRegisterContent::isList() const
|
|
|
|
{
|
|
|
|
switch (m_content.index()) {
|
|
|
|
case Type:
|
|
|
|
return std::get<QQmlJSScope::ConstPtr>(m_content)->accessSemantics()
|
|
|
|
== QQmlJSScope::AccessSemantics::Sequence;
|
|
|
|
case Property: {
|
|
|
|
const auto prop = std::get<QQmlJSMetaProperty>(m_content);
|
|
|
|
return prop.isList()
|
|
|
|
|| prop.type()->accessSemantics() == QQmlJSScope::AccessSemantics::Sequence;
|
|
|
|
}
|
2022-02-04 20:46:07 +00:00
|
|
|
case Conversion:
|
|
|
|
return std::get<ConvertedTypes>(m_content).result->accessSemantics()
|
|
|
|
== QQmlJSScope::AccessSemantics::Sequence;
|
2021-06-29 11:19:21 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QQmlJSRegisterContent::isWritable() const
|
|
|
|
{
|
|
|
|
switch (m_content.index()) {
|
|
|
|
case Property:
|
|
|
|
return std::get<QQmlJSMetaProperty>(m_content).isWritable();
|
|
|
|
|
|
|
|
// TODO: What can we actually write?
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QQmlJSRegisterContent QQmlJSRegisterContent::create(const QQmlJSScope::ConstPtr &storedType,
|
|
|
|
const QQmlJSScope::ConstPtr &type,
|
|
|
|
QQmlJSRegisterContent::ContentVariant variant,
|
|
|
|
const QQmlJSScope::ConstPtr &scope)
|
|
|
|
{
|
|
|
|
QQmlJSRegisterContent result(storedType, scope, variant);
|
|
|
|
result.m_content = type;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QQmlJSRegisterContent QQmlJSRegisterContent::create(const QQmlJSScope::ConstPtr &storedType,
|
|
|
|
const QQmlJSMetaProperty &property,
|
|
|
|
QQmlJSRegisterContent::ContentVariant variant,
|
|
|
|
const QQmlJSScope::ConstPtr &scope)
|
|
|
|
{
|
|
|
|
QQmlJSRegisterContent result(storedType, scope, variant);
|
|
|
|
result.m_content = property;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QQmlJSRegisterContent QQmlJSRegisterContent::create(const QQmlJSScope::ConstPtr &storedType,
|
|
|
|
const QQmlJSMetaEnum &enumeration,
|
|
|
|
const QString &enumMember,
|
|
|
|
QQmlJSRegisterContent::ContentVariant variant,
|
|
|
|
const QQmlJSScope::ConstPtr &scope)
|
|
|
|
{
|
|
|
|
QQmlJSRegisterContent result(storedType, scope, variant);
|
|
|
|
result.m_content = std::make_pair(enumeration, enumMember);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QQmlJSRegisterContent QQmlJSRegisterContent::create(const QQmlJSScope::ConstPtr &storedType,
|
|
|
|
const QList<QQmlJSMetaMethod> &methods,
|
|
|
|
QQmlJSRegisterContent::ContentVariant variant,
|
|
|
|
const QQmlJSScope::ConstPtr &scope)
|
|
|
|
{
|
|
|
|
QQmlJSRegisterContent result(storedType, scope, variant);
|
|
|
|
result.m_content = methods;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-08-16 06:53:39 +00:00
|
|
|
QQmlJSRegisterContent QQmlJSRegisterContent::create(const QQmlJSScope::ConstPtr &storedType,
|
|
|
|
uint importNamespaceStringId,
|
|
|
|
QQmlJSRegisterContent::ContentVariant variant,
|
|
|
|
const QQmlJSScope::ConstPtr &scope)
|
|
|
|
{
|
|
|
|
QQmlJSRegisterContent result(storedType, scope, variant);
|
|
|
|
result.m_content = importNamespaceStringId;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-02-04 20:46:07 +00:00
|
|
|
QQmlJSRegisterContent QQmlJSRegisterContent::create(const QQmlJSScope::ConstPtr &storedType,
|
|
|
|
const QList<QQmlJSScope::ConstPtr> origins,
|
|
|
|
const QQmlJSScope::ConstPtr &conversion,
|
|
|
|
ContentVariant variant,
|
|
|
|
const QQmlJSScope::ConstPtr &scope)
|
|
|
|
{
|
|
|
|
QQmlJSRegisterContent result(storedType, scope, variant);
|
|
|
|
result.m_content = ConvertedTypes { origins, conversion };
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-06-29 11:19:21 +00:00
|
|
|
QT_END_NAMESPACE
|